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 2023/12/01 04:33:41 UTC
(skywalking-cli) branch master updated: Support global dependency query command (#198)
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 d5f3597 Support global dependency query command (#198)
d5f3597 is described below
commit d5f3597733aa5217373986d776a3ee5ee8b3c468
Author: mrproliu <74...@qq.com>
AuthorDate: Fri Dec 1 12:33:36 2023 +0800
Support global dependency query command (#198)
---
CHANGES.md | 9 +++
assets/graphqls/dependency/GlobalTopology.graphql | 35 +++++++++
.../dependency/GlobalTopologyWithoutLayer.graphql | 35 +++++++++
internal/commands/dependency/dependency.go | 1 +
internal/commands/dependency/global.go | 86 ++++++++++++++++++++++
pkg/graphql/dependency/dependency.go | 23 ++++++
6 files changed, 189 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index 8520a3e..5285fb0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,15 @@ Changes by Version
==================
Release Notes.
+0.14.0
+------------------
+
+### Features
+
+* Add the sub-command `dependency global` for adapt the global dependency query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/198
+
+### Bug Fixes
+
0.13.0
------------------
diff --git a/assets/graphqls/dependency/GlobalTopology.graphql b/assets/graphqls/dependency/GlobalTopology.graphql
new file mode 100644
index 0000000..f09602e
--- /dev/null
+++ b/assets/graphqls/dependency/GlobalTopology.graphql
@@ -0,0 +1,35 @@
+# 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 ($layer: String, $duration: Duration!) {
+ result: getGlobalTopology(duration: $duration, layer: $layer) {
+ nodes {
+ id
+ name
+ type
+ isReal
+ }
+ calls {
+ id
+ source
+ detectPoints
+ target
+ sourceComponents
+ targetComponents
+ }
+ }
+}
diff --git a/assets/graphqls/dependency/GlobalTopologyWithoutLayer.graphql b/assets/graphqls/dependency/GlobalTopologyWithoutLayer.graphql
new file mode 100644
index 0000000..0a25ed6
--- /dev/null
+++ b/assets/graphqls/dependency/GlobalTopologyWithoutLayer.graphql
@@ -0,0 +1,35 @@
+# 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 ($duration: Duration!) {
+ result: getGlobalTopology(duration: $duration) {
+ nodes {
+ id
+ name
+ type
+ isReal
+ }
+ calls {
+ id
+ source
+ detectPoints
+ target
+ sourceComponents
+ targetComponents
+ }
+ }
+}
diff --git a/internal/commands/dependency/dependency.go b/internal/commands/dependency/dependency.go
index 4b373e1..c3b62f9 100644
--- a/internal/commands/dependency/dependency.go
+++ b/internal/commands/dependency/dependency.go
@@ -30,5 +30,6 @@ var Command = &cli.Command{
ServiceCommand,
InstanceCommand,
ProcessCommand,
+ GlobalCommand,
},
}
diff --git a/internal/commands/dependency/global.go b/internal/commands/dependency/global.go
new file mode 100644
index 0000000..c0ad798
--- /dev/null
+++ b/internal/commands/dependency/global.go
@@ -0,0 +1,86 @@
+// 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.
+
+package dependency
+
+import (
+ "fmt"
+
+ "github.com/urfave/cli/v2"
+
+ "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"
+ "github.com/apache/skywalking-cli/pkg/display/displayable"
+ "github.com/apache/skywalking-cli/pkg/graphql/dependency"
+ "github.com/apache/skywalking-cli/pkg/graphql/metadata"
+
+ api "skywalking.apache.org/repo/goapi/query"
+)
+
+var GlobalCommand = &cli.Command{
+ Name: "global",
+ Aliases: []string{"glb"},
+ Usage: "Query the global dependencies",
+ Flags: flags.Flags(
+ flags.DurationFlags,
+ []cli.Flag{
+ &cli.StringFlag{
+ Name: "layer",
+ Usage: "Name of the layer to query the dependency of this layer",
+ Required: false,
+ },
+ },
+ ),
+ Before: interceptor.BeforeChain(
+ interceptor.DurationInterceptor,
+ ),
+ Action: func(ctx *cli.Context) error {
+ layer := ctx.String("layer")
+ end := ctx.String("end")
+ start := ctx.String("start")
+ step := ctx.Generic("step")
+
+ duration := api.Duration{
+ Start: start,
+ End: end,
+ Step: step.(*model.StepEnumValue).Selected,
+ }
+
+ major, _, err := metadata.BackendVersion(ctx)
+ if err != nil {
+ return err
+ }
+
+ var topology api.Topology
+ if major >= 10 {
+ topology, err = dependency.GlobalTopology(ctx, layer, duration)
+ } else {
+ if layer != "" {
+ return fmt.Errorf("the layer parameter only available when OAP version >= 10.0.0")
+ }
+ topology, err = dependency.GlobalTopologyWithoutLayer(ctx, duration)
+ }
+
+ if err != nil {
+ return err
+ }
+
+ return display.Display(ctx, &displayable.Displayable{Data: topology})
+ },
+}
diff --git a/pkg/graphql/dependency/dependency.go b/pkg/graphql/dependency/dependency.go
index ea5fe1a..958835e 100644
--- a/pkg/graphql/dependency/dependency.go
+++ b/pkg/graphql/dependency/dependency.go
@@ -39,6 +39,29 @@ func EndpointDependency(ctx *cli.Context, endpointID string, duration api.Durati
return response["result"], err
}
+func GlobalTopology(ctx *cli.Context, layer string, duration api.Duration) (api.Topology, error) {
+ var response map[string]api.Topology
+
+ request := graphql.NewRequest(assets.Read("graphqls/dependency/GlobalTopology.graphql"))
+ request.Var("layer", layer)
+ request.Var("duration", duration)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}
+
+func GlobalTopologyWithoutLayer(ctx *cli.Context, duration api.Duration) (api.Topology, error) {
+ var response map[string]api.Topology
+
+ request := graphql.NewRequest(assets.Read("graphqls/dependency/GlobalTopologyWithoutLayer.graphql"))
+ request.Var("duration", duration)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}
+
func ServiceTopology(ctx *cli.Context, serviceID string, duration api.Duration) (api.Topology, error) {
var response map[string]api.Topology