Skip to content

Commit 86618d0

Browse files
authored
Add the duration related flags in the endpoint list (#201)
1 parent ee371a2 commit 86618d0

File tree

8 files changed

+60
-8
lines changed

8 files changed

+60
-8
lines changed

.github/workflows/CI.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
- name: Check for CLI source changes
6666
id: filter-cli
6767
# The GHA version is pinned by infra
68-
uses: tj-actions/changed-files@v35.9.2
68+
uses: tj-actions/changed-files@v43.0.0
6969
with:
7070
files_from_source_file: .github/file-filters.txt
7171
- name: List all modified files
@@ -145,7 +145,7 @@ jobs:
145145
go-version: 1.18
146146

147147
- name: Test commands
148-
uses: apache/skywalking-infra-e2e@2b3aa53dbba73909730b211d5b8065abc74b56ad
148+
uses: apache/skywalking-infra-e2e@cf589b4a0b9f8e6f436f78e9cfd94a1ee5494180
149149
env:
150150
OAP_TAG: ${{ matrix.oap }}
151151
with:

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release Notes.
1111
* Upgrade crypto lib to fix cve by @mrproliu in https://github.com/apache/skywalking-cli/pull/199
1212
* Add the **hierarchy** related commands `hierarchy service`, `hierarchy instance` and `hierarchy layer-levels` by @mrproliu in https://github.com/apache/skywalking-cli/pull/200
1313
* Add the `layers` field to `nodes` in the `dependency service` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/200
14+
* Add the duration related flags in the `endpoint list` command by @mrproliu in https://github.com/apache/skywalking-cli/pull/201
1415

1516
### Bug Fixes
1617

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
query ($keyword: String!, $serviceId: ID!, $limit: Int!, $duration: Duration) {
19+
result: findEndpoint(keyword: $keyword, serviceId: $serviceId, limit: $limit, duration: $duration) {
20+
id name
21+
}
22+
}

internal/commands/browser/page/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $ swctl browser page ls --service-id dGVzdC11aQ==.1`,
5858
serviceID := ctx.String("service-id")
5959
limit := ctx.Int("limit")
6060

61-
endpoints, err := metadata.SearchEndpoints(ctx, serviceID, "", limit)
61+
endpoints, err := metadata.SearchEndpoints(ctx, serviceID, "", limit, nil)
6262

6363
if err != nil {
6464
return err

internal/commands/endpoint/list.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ package endpoint
2020
import (
2121
"github.com/urfave/cli/v2"
2222

23+
api "skywalking.apache.org/repo/goapi/query"
24+
2325
"github.com/apache/skywalking-cli/internal/commands/interceptor"
2426
"github.com/apache/skywalking-cli/internal/flags"
27+
"github.com/apache/skywalking-cli/internal/model"
2528

2629
"github.com/apache/skywalking-cli/pkg/display/displayable"
2730

@@ -47,6 +50,7 @@ $ swctl endpoint ls --service-id YnVzaW5lc3Mtem9uZTo6cHJvamVjdEM=.1
4750
$ swctl endpoint ls --service-name business-zone::projectC --keyword projectC`,
4851
Flags: flags.Flags(
4952
flags.ServiceFlags,
53+
flags.DurationFlags,
5054

5155
[]cli.Flag{
5256
&cli.IntFlag{
@@ -71,8 +75,22 @@ $ swctl endpoint ls --service-name business-zone::projectC --keyword projectC`,
7175
limit := ctx.Int("limit")
7276
keyword := ctx.String("keyword")
7377

74-
endpoints, err := metadata.SearchEndpoints(ctx, serviceID, keyword, limit)
78+
var duration *api.Duration
79+
if interceptor.IsSetDurationFlags(ctx) {
80+
if err := interceptor.DurationInterceptor(ctx); err != nil {
81+
return err
82+
}
83+
end := ctx.String("end")
84+
start := ctx.String("start")
85+
step := ctx.Generic("step")
86+
duration = &api.Duration{
87+
Start: start,
88+
End: end,
89+
Step: step.(*model.StepEnumValue).Selected,
90+
}
91+
}
7592

93+
endpoints, err := metadata.SearchEndpoints(ctx, serviceID, keyword, limit, duration)
7694
if err != nil {
7795
return err
7896
}

internal/commands/interceptor/duration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func DurationInterceptor(ctx *cli.Context) error {
8080
return nil
8181
}
8282

83+
// IsSetDurationFlags checks if the duration flags are set
84+
func IsSetDurationFlags(ctx *cli.Context) bool {
85+
return ctx.IsSet("start") || ctx.IsSet("end") || ctx.IsSet("step")
86+
}
87+
8388
// ParseDuration parses the `start` and `end` to a triplet, (startTime, endTime, step),
8489
// based on the given `timezone`, however, if the given `timezone` is empty, UTC becomes the default timezone.
8590
// if --start and --end are both absent,

pkg/graphql/metadata/metadata.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,22 @@ func SearchBrowserService(cliCtx *cli.Context, serviceCode string) (service api.
112112
return service, err
113113
}
114114

115-
func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int) ([]api.Endpoint, error) {
115+
func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int, duration *api.Duration) ([]api.Endpoint, error) {
116116
var response map[string][]api.Endpoint
117117

118-
majorVersion, _, err := BackendVersion(cliCtx)
118+
majorVersion, minorVersion, err := BackendVersion(cliCtx)
119119
if err != nil {
120120
return nil, err
121121
}
122122
var request *graphql.Request
123-
if majorVersion >= 9 {
124-
request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpoints.graphql"))
123+
if majorVersion >= 10 && minorVersion >= 2 {
124+
request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpointsWithDuration.graphql"))
125+
request.Var("serviceId", serviceID)
126+
request.Var("keyword", keyword)
127+
request.Var("limit", limit)
128+
request.Var("duration", duration)
129+
} else if majorVersion >= 9 {
130+
request = graphql.NewRequest(assets.Read("graphqls/metadata/v2/FindEndpointsWithoutDuration.graphql"))
125131
request.Var("serviceId", serviceID)
126132
request.Var("keyword", keyword)
127133
request.Var("limit", limit)

0 commit comments

Comments
 (0)