diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 19bdecf0..423387a3 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 cdda2fdc..e978e0e5 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/FindEndpointsWithDuration.graphql b/assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql new file mode 100644 index 00000000..b9cd1691 --- /dev/null +++ b/assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql @@ -0,0 +1,22 @@ +# 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. + +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 b389c227..757f4003 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 b9b35559..2249b123 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 85ed5914..20c1ac5b 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 77e7695e..85823d03 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)