Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/post-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ echo "Reporting event..."
--message="$MESSAGE" \
--startTime="$STATE_START_TIME" \
--endTime=$(date +%s)000 \
--layer="$LAYER" \
$PARAMETERS
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
endpoint: "" # Optional. Endpoint of the service, if any
message: "Upgrade from {fromVersion} to {toVersion}" # Optional. The message of the event
parameters: "" # Optional. The parameters in the message, if any
layer: "GENERAL" # Required. Name of the layer to which the event belongs (case-insensitive)

# your package / deployment steps...
```
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ inputs:
description: The parameters in the message
required: false
default: ""
layer:
description: Name of the layer to which the event belongs (case-insensitive)
required: true

runs:
using: docker
Expand All @@ -58,5 +61,6 @@ runs:
ENDPOINT: ${{ inputs.endpoint }}
MESSAGE: ${{ inputs.message }}
PARAMETERS: ${{ inputs.parameters }}
LAYER: ${{ inputs.layer }}
entrypoint: /entrypoint.sh
post-entrypoint: /post-entrypoint.sh
1 change: 1 addition & 0 deletions cmd/swctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func init() {

func main() {
app := cli.NewApp()
app.Name = "swctl"
app.Usage = "The CLI (Command Line Interface) for Apache SkyWalking."
app.UsageText = `Commands in SkyWalking CLI are organized into two levels,
in the form of "swctl --option <level1> --option <level2> --option",
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ replace golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 => golang.org/x/c
require (
github.com/apache/skywalking-swck v0.2.0
github.com/gizak/termui/v3 v3.1.0
github.com/google/uuid v1.3.0
github.com/machinebox/graphql v0.2.2
github.com/mattn/go-runewidth v0.0.9
github.com/mitchellh/mapstructure v1.4.0 // indirect
Expand All @@ -20,5 +21,5 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.1
sigs.k8s.io/controller-runtime v0.7.0
skywalking.apache.org/repo/goapi v0.0.0-20220407130404-69485e13dbb3
skywalking.apache.org/repo/goapi v0.0.0-20220412071816-33e4ea2a99b4
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
Expand Down Expand Up @@ -941,5 +942,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
skywalking.apache.org/repo/goapi v0.0.0-20220407130404-69485e13dbb3 h1:DHRqCV17xjLT/HIyNWzLmhrizkne8JgaQDYclHg1tLg=
skywalking.apache.org/repo/goapi v0.0.0-20220407130404-69485e13dbb3/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=
skywalking.apache.org/repo/goapi v0.0.0-20220412071816-33e4ea2a99b4 h1:2JJA2JLUkdj5vimJH4+JYdeqqlr+F+g2eQYS6EqxUrA=
skywalking.apache.org/repo/goapi v0.0.0-20220412071816-33e4ea2a99b4/go.mod h1:uWwwvhcwe2MD/nJCg0c1EE/eL6KzaBosLHDfMFoEJ30=
9 changes: 9 additions & 0 deletions internal/commands/event/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package event

import (
"strings"

event "skywalking.apache.org/repo/goapi/collect/event/v3"
api "skywalking.apache.org/repo/goapi/query"

Expand Down Expand Up @@ -53,6 +55,11 @@ $ swctl event list
Usage: "event name",
Required: false,
},
&cli.StringFlag{
Name: "layer",
Usage: "Name of the layer to which the event belongs (case-insensitive), which can be queried via 'swctl layer list'",
Required: false,
},
&cli.GenericFlag{
Name: "type",
Usage: "the type of the event",
Expand Down Expand Up @@ -85,6 +92,7 @@ $ swctl event list
endpointName := ctx.String("endpoint-name")
name := ctx.String("name")
eventType := api.EventType(ctx.Generic("type").(*model.EventTypeEnumValue).String())
layer := strings.ToUpper(ctx.String("layer"))
pageNum := 1
needTotal := true

Expand All @@ -102,6 +110,7 @@ $ swctl event list
Name: &name,
Type: &eventType,
Time: &duration,
Layer: &layer,
Order: nil,
Paging: &paging,
}
Expand Down
54 changes: 44 additions & 10 deletions internal/commands/event/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,39 @@
package event

import (
"strings"

"github.com/google/uuid"
"github.com/urfave/cli/v2"
event "skywalking.apache.org/repo/goapi/collect/event/v3"

"github.com/apache/skywalking-cli/internal/commands/interceptor"
"github.com/apache/skywalking-cli/internal/flags"
"github.com/apache/skywalking-cli/internal/logger"
"github.com/apache/skywalking-cli/internal/model"
pkgevent "github.com/apache/skywalking-cli/pkg/commands/event"
"github.com/apache/skywalking-cli/pkg/display"
"github.com/apache/skywalking-cli/pkg/display/displayable"

"github.com/urfave/cli/v2"
"github.com/apache/skywalking-cli/pkg/grpc"
)

var reportCommand = &cli.Command{
Name: "report",
Aliases: []string{"r"},
Usage: "Report an event to OAP server via gRPC",
Name: "report",
Aliases: []string{"r"},
Usage: "Report an event to OAP server via gRPC",
Description: `When reporting an event, you typically execute the command twice,
one for starting of the event (--start-time is required) and the other one for ending of the event
(--uuid and --end-time are required).\n You can also report an event once with start time and end time.`,
ArgsUsage: "[parameters...]",
Flags: flags.Flags(
flags.InstanceFlags,
flags.EndpointFlags,

[]cli.Flag{
&cli.StringFlag{
Name: "uuid",
Usage: "Unique `ID` of the event.",
Name: "uuid",
Usage: "Unique `ID` of the event, if not specified, a random one will be generated.",
Value: uuid.New().String(),
DefaultText: "",
},
&cli.StringFlag{
Name: "name",
Expand All @@ -69,15 +77,41 @@ var reportCommand = &cli.Command{
Name: "end-time",
Usage: "The end time (in milliseconds) of the event, measured between the current time and midnight, January 1, 1970 UTC.",
},
&cli.StringFlag{
Name: "layer",
Usage: "Name of the layer to which the event belongs (case-insensitive), which can be queried via 'swctl layer list'",
Required: true,
},
},
),
Action: func(ctx *cli.Context) error {
reply, err := pkgevent.Report(ctx)
parameters, err := interceptor.ParseParameters(ctx.Args())
if err != nil {
return err
}

e := event.Event{
Uuid: ctx.String("uuid"),
Source: &event.Source{
Service: ctx.String("service-name"),
ServiceInstance: ctx.String("instance-name"),
Endpoint: ctx.String("endpoint-name"),
},
Name: ctx.String("name"),
Type: ctx.Generic("type").(*model.EventTypeEnumValue).Selected,
Message: ctx.String("message"),
Parameters: parameters,
StartTime: ctx.Int64("start-time"),
EndTime: ctx.Int64("end-time"),
Layer: strings.ToUpper(ctx.String("layer")),
}

reply, err := grpc.ReportEvent(ctx.String("grpc-addr"), &e)
if err != nil {
return err
}

logger.Log.Println("Report the event successfully, whose uuid is ", ctx.String("uuid"))
logger.Log.Printf("Report the event successfully, whose uuid is %s\n", ctx.String("uuid"))
return display.Display(ctx, &displayable.Displayable{Data: reply})
},
}
58 changes: 0 additions & 58 deletions pkg/commands/event/report.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"google.golang.org/grpc"
)

// ReportEvent creates a grpc client and report an event.
// ReportEvent creates a grpc client and reports an event to OAP.
func ReportEvent(addr string, e *event.Event) (*common.Commands, error) {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
Expand Down