From a5f28fcfb765f753d9c1dd6d536e807eee981e6d Mon Sep 17 00:00:00 2001 From: Hoshea Date: Thu, 14 Apr 2022 10:05:52 +0800 Subject: [PATCH 1/3] add layer to event --- .github/scripts/post-entrypoint.sh | 1 + README.md | 1 + action.yaml | 4 +++ cmd/swctl/main.go | 1 + go.mod | 3 +- go.sum | 6 ++-- internal/commands/event/list.go | 13 +++++-- internal/commands/event/report.go | 54 ++++++++++++++++++++++------ pkg/commands/event/report.go | 58 ------------------------------ pkg/grpc/grpc.go | 2 +- 10 files changed, 67 insertions(+), 76 deletions(-) delete mode 100644 pkg/commands/event/report.go diff --git a/.github/scripts/post-entrypoint.sh b/.github/scripts/post-entrypoint.sh index 3802e4de..cb0ad28b 100755 --- a/.github/scripts/post-entrypoint.sh +++ b/.github/scripts/post-entrypoint.sh @@ -31,4 +31,5 @@ echo "Reporting event..." --message="$MESSAGE" \ --startTime="$STATE_START_TIME" \ --endTime=$(date +%s)000 \ + --layer="$LAYER" \ $PARAMETERS diff --git a/README.md b/README.md index e8e81f27..49a9433b 100644 --- a/README.md +++ b/README.md @@ -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... ``` diff --git a/action.yaml b/action.yaml index b511b172..aaa28f2b 100644 --- a/action.yaml +++ b/action.yaml @@ -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 @@ -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 diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go index 58aa2d72..8ea20eb9 100644 --- a/cmd/swctl/main.go +++ b/cmd/swctl/main.go @@ -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 --option --option", diff --git a/go.mod b/go.mod index a6f8f79c..29db4b8e 100644 --- a/go.mod +++ b/go.mod @@ -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 // indirect github.com/machinebox/graphql v0.2.2 github.com/mattn/go-runewidth v0.0.9 github.com/mitchellh/mapstructure v1.4.0 // indirect @@ -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 ) diff --git a/go.sum b/go.sum index 824a6279..06db97c1 100644 --- a/go.sum +++ b/go.sum @@ -269,6 +269,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ 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= @@ -941,5 +943,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= diff --git a/internal/commands/event/list.go b/internal/commands/event/list.go index 1ec38bd4..2ffe7a61 100644 --- a/internal/commands/event/list.go +++ b/internal/commands/event/list.go @@ -53,6 +53,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", @@ -85,6 +90,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 @@ -99,9 +105,10 @@ $ swctl event list ServiceInstance: &serviceInstanceName, Endpoint: &endpointName, }, - Name: &name, - Type: &eventType, - Time: &duration, + Name: &name, + Type: &eventType, + Time: &duration, + // Layer: &layer, Order: nil, Paging: &paging, } diff --git a/internal/commands/event/report.go b/internal/commands/event/report.go index 6d009d7e..334b7863 100644 --- a/internal/commands/event/report.go +++ b/internal/commands/event/report.go @@ -18,31 +18,37 @@ 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", - ArgsUsage: "[parameters...]", + 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", @@ -69,15 +75,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}) }, } diff --git a/pkg/commands/event/report.go b/pkg/commands/event/report.go deleted file mode 100644 index 19ec6c69..00000000 --- a/pkg/commands/event/report.go +++ /dev/null @@ -1,58 +0,0 @@ -// Licensed to Apache Software Foundation (ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation (ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package event - -import ( - common "skywalking.apache.org/repo/goapi/collect/common/v3" - event "skywalking.apache.org/repo/goapi/collect/event/v3" - - "github.com/apache/skywalking-cli/internal/commands/interceptor" - "github.com/apache/skywalking-cli/internal/model" - "github.com/apache/skywalking-cli/pkg/grpc" - - "github.com/urfave/cli/v2" -) - -func Report(ctx *cli.Context) (*common.Commands, error) { - parameters, err := interceptor.ParseParameters(ctx.Args()) - if err != nil { - return nil, 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"), - } - - reply, err := grpc.ReportEvent(ctx.String("grpc-addr"), &e) - if err != nil { - return nil, err - } - - return reply, nil -} diff --git a/pkg/grpc/grpc.go b/pkg/grpc/grpc.go index b97ae6fa..47c0568f 100644 --- a/pkg/grpc/grpc.go +++ b/pkg/grpc/grpc.go @@ -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 { From 2897311b49072a364353564b3b46026ad2bbc193 Mon Sep 17 00:00:00 2001 From: Hoshea Date: Thu, 14 Apr 2022 10:42:59 +0800 Subject: [PATCH 2/3] add layer to event --- go.mod | 2 +- go.sum | 1 - internal/commands/event/report.go | 12 +++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 29db4b8e..900fee68 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +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 // indirect + 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 diff --git a/go.sum b/go.sum index 06db97c1..73ead90c 100644 --- a/go.sum +++ b/go.sum @@ -267,7 +267,6 @@ 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= diff --git a/internal/commands/event/report.go b/internal/commands/event/report.go index 334b7863..4c7b1938 100644 --- a/internal/commands/event/report.go +++ b/internal/commands/event/report.go @@ -34,11 +34,13 @@ import ( ) var reportCommand = &cli.Command{ - 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...]", + 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, From f1b1d1d9fa22c4f167a457403809f5546ce8395a Mon Sep 17 00:00:00 2001 From: Hoshea Date: Thu, 14 Apr 2022 14:07:11 +0800 Subject: [PATCH 3/3] add layer to event query --- internal/commands/event/list.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/commands/event/list.go b/internal/commands/event/list.go index 2ffe7a61..4d4eb865 100644 --- a/internal/commands/event/list.go +++ b/internal/commands/event/list.go @@ -18,6 +18,8 @@ package event import ( + "strings" + event "skywalking.apache.org/repo/goapi/collect/event/v3" api "skywalking.apache.org/repo/goapi/query" @@ -90,7 +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")) + layer := strings.ToUpper(ctx.String("layer")) pageNum := 1 needTotal := true @@ -105,10 +107,10 @@ $ swctl event list ServiceInstance: &serviceInstanceName, Endpoint: &endpointName, }, - Name: &name, - Type: &eventType, - Time: &duration, - // Layer: &layer, + Name: &name, + Type: &eventType, + Time: &duration, + Layer: &layer, Order: nil, Paging: &paging, }