You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2024/10/12 00:39:14 UTC

(skywalking-cli) branch master updated: Add the duration related flags in the `endpoint list` (#201)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 86618d0  Add the duration related flags in the `endpoint list` (#201)
86618d0 is described below

commit 86618d043ce25ebaec6570c4341c1f6c3cc8d64c
Author: mrproliu <74...@qq.com>
AuthorDate: Sat Oct 12 08:39:09 2024 +0800

    Add the duration related flags in the `endpoint list` (#201)
---
 .github/workflows/CI.yaml                            |  4 ++--
 CHANGES.md                                           |  1 +
 ...nts.graphql => FindEndpointsWithDuration.graphql} |  4 ++--
 ....graphql => FindEndpointsWithoutDuration.graphql} |  0
 internal/commands/browser/page/list.go               |  2 +-
 internal/commands/endpoint/list.go                   | 20 +++++++++++++++++++-
 internal/commands/interceptor/duration.go            |  5 +++++
 pkg/graphql/metadata/metadata.go                     | 14 ++++++++++----
 8 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml
index 19bdecf..423387a 100644
--- a/.github/workflows/CI.yaml
+++ b/.github/workflows/CI.yaml
@@ -65,7 +65,7 @@ jobs:
       - name: Check for CLI source changes
         id: filter-cli
         # The GHA version is pinned by infra
-        uses: tj-actions/changed-files@v35.9.2
+        uses: tj-actions/changed-files@v43.0.0
         with:
           files_from_source_file: .github/file-filters.txt
       - name: List all modified files
@@ -145,7 +145,7 @@ jobs:
           go-version: 1.18
 
       - name: Test commands
-        uses: apache/skywalking-infra-e2e@2b3aa53dbba73909730b211d5b8065abc74b56ad
+        uses: apache/skywalking-infra-e2e@cf589b4a0b9f8e6f436f78e9cfd94a1ee5494180
         env:
           OAP_TAG: ${{ matrix.oap }}
         with:
diff --git a/CHANGES.md b/CHANGES.md
index cdda2fd..e978e0e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -11,6 +11,7 @@ Release Notes.
 * Upgrade crypto lib to fix cve by @mrproliu in https://github.com/apache/skywalking-cli/pull/199
 * Add the **hierarchy** related commands `hierarchy service`, `hierarchy instance` and `hierarchy layer-levels` by @mrproliu in https://github.com/apache/skywalking-cli/pull/200
 * Add the `layers` field to `nodes` in the `dependency service` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/200
+* Add the duration related flags in the `endpoint list` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/201
 
 ### Bug Fixes
 
diff --git a/assets/graphqls/metadata/v2/FindEndpoints.graphql b/assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql
similarity index 87%
copy from assets/graphqls/metadata/v2/FindEndpoints.graphql
copy to assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql
index f53c225..b9cd169 100644
--- a/assets/graphqls/metadata/v2/FindEndpoints.graphql
+++ b/assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql
@@ -15,8 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-query ($keyword: String!, $serviceId: ID!, $limit: Int!) {
-    result: findEndpoint(keyword: $keyword, serviceId: $serviceId, limit: $limit) {
+query ($keyword: String!, $serviceId: ID!, $limit: Int!, $duration: Duration) {
+    result: findEndpoint(keyword: $keyword, serviceId: $serviceId, limit: $limit, duration: $duration) {
         id name
     }
 }
\ No newline at end of file
diff --git a/assets/graphqls/metadata/v2/FindEndpoints.graphql b/assets/graphqls/metadata/v2/FindEndpointsWithoutDuration.graphql
similarity index 100%
rename from assets/graphqls/metadata/v2/FindEndpoints.graphql
rename to assets/graphqls/metadata/v2/FindEndpointsWithoutDuration.graphql
diff --git a/internal/commands/browser/page/list.go b/internal/commands/browser/page/list.go
index b389c22..757f400 100644
--- a/internal/commands/browser/page/list.go
+++ b/internal/commands/browser/page/list.go
@@ -58,7 +58,7 @@ $ swctl browser page ls --service-id dGVzdC11aQ==.1`,
 		serviceID := ctx.String("service-id")
 		limit := ctx.Int("limit")
 
-		endpoints, err := metadata.SearchEndpoints(ctx, serviceID, "", limit)
+		endpoints, err := metadata.SearchEndpoints(ctx, serviceID, "", limit, nil)
 
 		if err != nil {
 			return err
diff --git a/internal/commands/endpoint/list.go b/internal/commands/endpoint/list.go
index b9b3555..2249b12 100644
--- a/internal/commands/endpoint/list.go
+++ b/internal/commands/endpoint/list.go
@@ -20,8 +20,11 @@ package endpoint
 import (
 	"github.com/urfave/cli/v2"
 
+	api "skywalking.apache.org/repo/goapi/query"
+
 	"github.com/apache/skywalking-cli/internal/commands/interceptor"
 	"github.com/apache/skywalking-cli/internal/flags"
+	"github.com/apache/skywalking-cli/internal/model"
 
 	"github.com/apache/skywalking-cli/pkg/display/displayable"
 
@@ -47,6 +50,7 @@ $ swctl endpoint ls --service-id YnVzaW5lc3Mtem9uZTo6cHJvamVjdEM=.1
 $ swctl endpoint ls --service-name business-zone::projectC --keyword projectC`,
 	Flags: flags.Flags(
 		flags.ServiceFlags,
+		flags.DurationFlags,
 
 		[]cli.Flag{
 			&cli.IntFlag{
@@ -71,8 +75,22 @@ $ swctl endpoint ls --service-name business-zone::projectC --keyword projectC`,
 		limit := ctx.Int("limit")
 		keyword := ctx.String("keyword")
 
-		endpoints, err := metadata.SearchEndpoints(ctx, serviceID, keyword, limit)
+		var duration *api.Duration
+		if interceptor.IsSetDurationFlags(ctx) {
+			if err := interceptor.DurationInterceptor(ctx); err != nil {
+				return err
+			}
+			end := ctx.String("end")
+			start := ctx.String("start")
+			step := ctx.Generic("step")
+			duration = &api.Duration{
+				Start: start,
+				End:   end,
+				Step:  step.(*model.StepEnumValue).Selected,
+			}
+		}
 
+		endpoints, err := metadata.SearchEndpoints(ctx, serviceID, keyword, limit, duration)
 		if err != nil {
 			return err
 		}
diff --git a/internal/commands/interceptor/duration.go b/internal/commands/interceptor/duration.go
index 85ed591..20c1ac5 100644
--- a/internal/commands/interceptor/duration.go
+++ b/internal/commands/interceptor/duration.go
@@ -80,6 +80,11 @@ func DurationInterceptor(ctx *cli.Context) error {
 	return nil
 }
 
+// IsSetDurationFlags checks if the duration flags are set
+func IsSetDurationFlags(ctx *cli.Context) bool {
+	return ctx.IsSet("start") || ctx.IsSet("end") || ctx.IsSet("step")
+}
+
 // ParseDuration parses the `start` and `end` to a triplet, (startTime, endTime, step),
 // based on the given `timezone`, however, if the given `timezone` is empty, UTC becomes the default timezone.
 // if --start and --end are both absent,
diff --git a/pkg/graphql/metadata/metadata.go b/pkg/graphql/metadata/metadata.go
index 77e7695..85823d0 100644
--- a/pkg/graphql/metadata/metadata.go
+++ b/pkg/graphql/metadata/metadata.go
@@ -112,16 +112,22 @@ func SearchBrowserService(cliCtx *cli.Context, serviceCode string) (service api.
 	return service, err
 }
 
-func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int) ([]api.Endpoint, error) {
+func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int, duration *api.Duration) ([]api.Endpoint, error) {
 	var response map[string][]api.Endpoint
 
-	majorVersion, _, err := BackendVersion(cliCtx)
+	majorVersion, minorVersion, err := BackendVersion(cliCtx)
 	if err != nil {
 		return nil, err
 	}
 	var request *graphql.Request
-	if majorVersion >= 9 {
-		request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpoints.graphql"))
+	if majorVersion >= 10 && minorVersion >= 2 {
+		request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpointsWithDuration.graphql"))
+		request.Var("serviceId", serviceID)
+		request.Var("keyword", keyword)
+		request.Var("limit", limit)
+		request.Var("duration", duration)
+	} else if majorVersion >= 9 {
+		request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpointsWithoutDuration.graphql"))
 		request.Var("serviceId", serviceID)
 		request.Var("keyword", keyword)
 		request.Var("limit", limit)