Skip to content

Commit

Permalink
Add the duration related flags in the endpoint list (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Oct 12, 2024
1 parent ee371a2 commit 86618d0
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions assets/graphqls/metadata/v2/FindEndpointsWithDuration.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion internal/commands/browser/page/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion internal/commands/endpoint/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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{
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions internal/commands/interceptor/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions pkg/graphql/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 86618d0

Please sign in to comment.