You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by li...@apache.org on 2024/10/11 08:54:48 UTC
(skywalking-cli) branch endpoint-duration created (now 13081c5)
This is an automated email from the ASF dual-hosted git repository.
liuhan pushed a change to branch endpoint-duration
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
at 13081c5 Add the duration related flags in the `endpoint list`
This branch includes the following new commits:
new 13081c5 Add the duration related flags in the `endpoint list`
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(skywalking-cli) 01/01: Add the duration related flags in the `endpoint list`
Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
liuhan pushed a commit to branch endpoint-duration
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
commit 13081c5e881327ca5d813e70c70a51d7e97a3892
Author: mrproliu <74...@qq.com>
AuthorDate: Fri Oct 11 16:54:37 2024 +0800
Add the duration related flags in the `endpoint list`
---
CHANGES.md | 1 +
assets/graphqls/metadata/v2/FindEndpoints.graphql | 4 ++--
internal/commands/browser/page/list.go | 2 +-
internal/commands/endpoint/list.go | 20 +++++++++++++++++++-
internal/commands/interceptor/duration.go | 5 +++++
pkg/graphql/metadata/metadata.go | 3 ++-
6 files changed, 30 insertions(+), 5 deletions(-)
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/FindEndpoints.graphql
index f53c225..b9cd169 100644
--- a/assets/graphqls/metadata/v2/FindEndpoints.graphql
+++ b/assets/graphqls/metadata/v2/FindEndpoints.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/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..b5544bb 100644
--- a/pkg/graphql/metadata/metadata.go
+++ b/pkg/graphql/metadata/metadata.go
@@ -112,7 +112,7 @@ 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)
@@ -125,6 +125,7 @@ func SearchEndpoints(cliCtx *cli.Context, serviceID, keyword string, limit int)
request.Var("serviceId", serviceID)
request.Var("keyword", keyword)
request.Var("limit", limit)
+ request.Var("duration", duration)
} else {
request = graphql.NewRequest(assets.Read("graphqls/metadata/v1/SearchEndpoints.graphql"))
request.Var("serviceId", serviceID)