You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ho...@apache.org on 2021/08/16 06:02:25 UTC
[skywalking-cli] branch master updated: Add a command dependency
and its first sub-command endpoint (#107)
This is an automated email from the ASF dual-hosted git repository.
hoshea 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 c58e726 Add a command dependency and its first sub-command endpoint (#107)
c58e726 is described below
commit c58e7261a1f496cbbb0449a2937522012c183105
Author: JarvisG495 <86...@users.noreply.github.com>
AuthorDate: Mon Aug 16 02:02:10 2021 -0400
Add a command dependency and its first sub-command endpoint (#107)
* Add a command dependency
swctl dependency [endpoint-id] [--start=start-time] [--end=end-time]
* Fix make lint error
* Refactor dependency command for further development
set endpoint as dependency's sub-command
* Update internal/commands/dependency/dependency.go
---
README.md | 19 ++++
assets/assets.gen.go | 105 ++++++++++++++++-----
.../graphqls/dependency/EndpointDependency.graphql | 35 +++++++
cmd/swctl/main.go | 2 +
internal/commands/dependency/dependency.go | 31 ++++++
internal/commands/dependency/endpoint.go | 74 +++++++++++++++
pkg/graphql/dependency/dependency.go | 40 ++++++++
7 files changed, 282 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 0456abd..7db37e3 100644
--- a/README.md
+++ b/README.md
@@ -528,6 +528,25 @@ You can imitate the content of [the default template file](examples/global.yml)
</details>
+### `dependency`
+
+#### `endpoint`
+
+<details>
+
+<summary>dependency endpoint [endpoint-id] [--start=start-time] [--end=end-time]</summary>
+
+`dependency endpoint` shows all the dependencies of given `[endpoint-id]` in the time range of `[start, end]`.
+
+| argument | description | default |
+| :--- | :--- | :--- |
+| `endpoint-id` | The service endpoint id whose dependencies are to displayed. | |
+| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
+| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
+
+</details>
+
+
# Use Cases
<details>
diff --git a/assets/assets.gen.go b/assets/assets.gen.go
index b68211c..ee5279e 100644
--- a/assets/assets.gen.go
+++ b/assets/assets.gen.go
@@ -19,6 +19,7 @@
// sources:
// cr/oap.yaml (942B)
// cr/ui.yaml (935B)
+// graphqls/dependency/EndpointDependency.graphql (1.207kB)
// graphqls/event/events.graphql (1.256kB)
// graphqls/healthcheck/healthcheck.graphql (870B)
// graphqls/logs/Logs.graphql (1.258kB)
@@ -168,6 +169,58 @@ func crUiYaml() (*asset, error) {
return a, nil
}
+var _graphqlsDependencyEndpointdependencyGraphql = []byte(`# 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 ($endpointId:ID!, $duration: Duration!) {
+ result: getEndpointDependencies(duration: $duration, endpointId: $endpointId) {
+ nodes {
+ id
+ name
+ serviceId
+ serviceName
+ type
+ isReal
+ }
+ calls {
+ id
+ source
+ target
+ detectPoints
+ }
+ }
+}
+`)
+
+func graphqlsDependencyEndpointdependencyGraphqlBytes() ([]byte, error) {
+ return _graphqlsDependencyEndpointdependencyGraphql, nil
+}
+
+func graphqlsDependencyEndpointdependencyGraphql() (*asset, error) {
+ bytes, err := graphqlsDependencyEndpointdependencyGraphqlBytes()
+ if err != nil {
+ return nil, err
+ }
+
+ info := bindataFileInfo{name: "graphqls/dependency/EndpointDependency.graphql", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)}
+ a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xed, 0x55, 0x1, 0xe5, 0x9f, 0x2d, 0xaf, 0xe1, 0xad, 0x20, 0xc5, 0xa2, 0xaa, 0x16, 0x1, 0xca, 0xe3, 0xbf, 0x54, 0x54, 0x4a, 0x9d, 0xa6, 0x69, 0x37, 0x8a, 0xa8, 0x1a, 0xe5, 0xed, 0x28, 0xf}}
+ return a, nil
+}
+
var _graphqlsEventEventsGraphql = []byte(`# 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
@@ -1321,30 +1374,31 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
- "cr/oap.yaml": crOapYaml,
- "cr/ui.yaml": crUiYaml,
- "graphqls/event/events.graphql": graphqlsEventEventsGraphql,
- "graphqls/healthcheck/healthcheck.graphql": graphqlsHealthcheckHealthcheckGraphql,
- "graphqls/logs/Logs.graphql": graphqlsLogsLogsGraphql,
- "graphqls/metadata/AllServices.graphql": graphqlsMetadataAllservicesGraphql,
- "graphqls/metadata/Instances.graphql": graphqlsMetadataInstancesGraphql,
- "graphqls/metadata/SearchEndpoints.graphql": graphqlsMetadataSearchendpointsGraphql,
- "graphqls/metadata/SearchService.graphql": graphqlsMetadataSearchserviceGraphql,
- "graphqls/metadata/ServerTimeInfo.graphql": graphqlsMetadataServertimeinfoGraphql,
- "graphqls/metrics/HeatMap.graphql": graphqlsMetricsHeatmapGraphql,
- "graphqls/metrics/LabeledMetricsValues.graphql": graphqlsMetricsLabeledmetricsvaluesGraphql,
- "graphqls/metrics/ListMetrics.graphql": graphqlsMetricsListmetricsGraphql,
- "graphqls/metrics/MetricsValue.graphql": graphqlsMetricsMetricsvalueGraphql,
- "graphqls/metrics/MetricsValues.graphql": graphqlsMetricsMetricsvaluesGraphql,
- "graphqls/metrics/SortMetrics.graphql": graphqlsMetricsSortmetricsGraphql,
- "graphqls/profile/CreateTask.graphql": graphqlsProfileCreatetaskGraphql,
- "graphqls/profile/GetProfileAnalyze.graphql": graphqlsProfileGetprofileanalyzeGraphql,
- "graphqls/profile/GetProfiledSegment.graphql": graphqlsProfileGetprofiledsegmentGraphql,
- "graphqls/profile/GetTaskList.graphql": graphqlsProfileGettasklistGraphql,
- "graphqls/profile/GetTaskSegmentList.graphql": graphqlsProfileGettasksegmentlistGraphql,
- "graphqls/trace/Trace.graphql": graphqlsTraceTraceGraphql,
- "graphqls/trace/Traces.graphql": graphqlsTraceTracesGraphql,
- "templates/dashboard/global.yml": templatesDashboardGlobalYml,
+ "cr/oap.yaml": crOapYaml,
+ "cr/ui.yaml": crUiYaml,
+ "graphqls/dependency/EndpointDependency.graphql": graphqlsDependencyEndpointdependencyGraphql,
+ "graphqls/event/events.graphql": graphqlsEventEventsGraphql,
+ "graphqls/healthcheck/healthcheck.graphql": graphqlsHealthcheckHealthcheckGraphql,
+ "graphqls/logs/Logs.graphql": graphqlsLogsLogsGraphql,
+ "graphqls/metadata/AllServices.graphql": graphqlsMetadataAllservicesGraphql,
+ "graphqls/metadata/Instances.graphql": graphqlsMetadataInstancesGraphql,
+ "graphqls/metadata/SearchEndpoints.graphql": graphqlsMetadataSearchendpointsGraphql,
+ "graphqls/metadata/SearchService.graphql": graphqlsMetadataSearchserviceGraphql,
+ "graphqls/metadata/ServerTimeInfo.graphql": graphqlsMetadataServertimeinfoGraphql,
+ "graphqls/metrics/HeatMap.graphql": graphqlsMetricsHeatmapGraphql,
+ "graphqls/metrics/LabeledMetricsValues.graphql": graphqlsMetricsLabeledmetricsvaluesGraphql,
+ "graphqls/metrics/ListMetrics.graphql": graphqlsMetricsListmetricsGraphql,
+ "graphqls/metrics/MetricsValue.graphql": graphqlsMetricsMetricsvalueGraphql,
+ "graphqls/metrics/MetricsValues.graphql": graphqlsMetricsMetricsvaluesGraphql,
+ "graphqls/metrics/SortMetrics.graphql": graphqlsMetricsSortmetricsGraphql,
+ "graphqls/profile/CreateTask.graphql": graphqlsProfileCreatetaskGraphql,
+ "graphqls/profile/GetProfileAnalyze.graphql": graphqlsProfileGetprofileanalyzeGraphql,
+ "graphqls/profile/GetProfiledSegment.graphql": graphqlsProfileGetprofiledsegmentGraphql,
+ "graphqls/profile/GetTaskList.graphql": graphqlsProfileGettasklistGraphql,
+ "graphqls/profile/GetTaskSegmentList.graphql": graphqlsProfileGettasksegmentlistGraphql,
+ "graphqls/trace/Trace.graphql": graphqlsTraceTraceGraphql,
+ "graphqls/trace/Traces.graphql": graphqlsTraceTracesGraphql,
+ "templates/dashboard/global.yml": templatesDashboardGlobalYml,
}
// AssetDebug is true if the assets were built with the debug flag enabled.
@@ -1396,6 +1450,9 @@ var _bintree = &bintree{nil, map[string]*bintree{
"ui.yaml": &bintree{crUiYaml, map[string]*bintree{}},
}},
"graphqls": &bintree{nil, map[string]*bintree{
+ "dependency": &bintree{nil, map[string]*bintree{
+ "EndpointDependency.graphql": &bintree{graphqlsDependencyEndpointdependencyGraphql, map[string]*bintree{}},
+ }},
"event": &bintree{nil, map[string]*bintree{
"events.graphql": &bintree{graphqlsEventEventsGraphql, map[string]*bintree{}},
}},
diff --git a/assets/graphqls/dependency/EndpointDependency.graphql b/assets/graphqls/dependency/EndpointDependency.graphql
new file mode 100644
index 0000000..3310b9a
--- /dev/null
+++ b/assets/graphqls/dependency/EndpointDependency.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 ($endpointId:ID!, $duration: Duration!) {
+ result: getEndpointDependencies(duration: $duration, endpointId: $endpointId) {
+ nodes {
+ id
+ name
+ serviceId
+ serviceName
+ type
+ isReal
+ }
+ calls {
+ id
+ source
+ target
+ detectPoints
+ }
+ }
+}
diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go
index bfbe23e..9d5b262 100644
--- a/cmd/swctl/main.go
+++ b/cmd/swctl/main.go
@@ -22,6 +22,7 @@ import (
"os"
"github.com/apache/skywalking-cli/internal/commands/dashboard"
+ "github.com/apache/skywalking-cli/internal/commands/dependency"
"github.com/apache/skywalking-cli/internal/commands/endpoint"
"github.com/apache/skywalking-cli/internal/commands/event"
"github.com/apache/skywalking-cli/internal/commands/healthcheck"
@@ -124,6 +125,7 @@ func main() {
event.Command,
logs.Command,
profile.Command,
+ dependency.Command,
}
app.Before = interceptor.BeforeChain([]cli.BeforeFunc{
diff --git a/internal/commands/dependency/dependency.go b/internal/commands/dependency/dependency.go
new file mode 100644
index 0000000..c060165
--- /dev/null
+++ b/internal/commands/dependency/dependency.go
@@ -0,0 +1,31 @@
+// 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 (
+ "github.com/urfave/cli"
+)
+
+var Command = cli.Command{
+ Name: "dependency",
+ ShortName: "dep",
+ Usage: "Dependency related subcommand",
+ Subcommands: cli.Commands{
+ EndpointCommand,
+ },
+}
diff --git a/internal/commands/dependency/endpoint.go b/internal/commands/dependency/endpoint.go
new file mode 100644
index 0000000..05bfd3a
--- /dev/null
+++ b/internal/commands/dependency/endpoint.go
@@ -0,0 +1,74 @@
+// 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"
+
+ "github.com/apache/skywalking-cli/internal/commands/interceptor"
+ "github.com/apache/skywalking-cli/internal/flags"
+ "github.com/apache/skywalking-cli/internal/logger"
+ "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"
+
+ api "skywalking.apache.org/repo/goapi/query"
+)
+
+var EndpointCommand = cli.Command{
+ Name: "endpoint",
+ ShortName: "ep",
+ Usage: "Query the dependencies of given endpoint",
+ ArgsUsage: "<endpointId>",
+ Flags: flags.Flags(
+ flags.DurationFlags,
+ ),
+ Before: interceptor.BeforeChain([]cli.BeforeFunc{
+ interceptor.TimezoneInterceptor,
+ interceptor.DurationInterceptor,
+ }),
+
+ Action: func(ctx *cli.Context) error {
+ if ctx.NArg() == 0 {
+ return fmt.Errorf("command endpoint requires endpointId as argument")
+ }
+
+ end := ctx.String("end")
+ start := ctx.String("start")
+ step := ctx.Generic("step")
+
+ duration := api.Duration{
+ Start: start,
+ End: end,
+ Step: step.(*model.StepEnumValue).Selected,
+ }
+
+ dependency, err := dependency.EndpointDependency(ctx, ctx.Args().First(), duration)
+
+ if err != nil {
+ logger.Log.Fatalln(err)
+ }
+
+ return display.Display(ctx, &displayable.Displayable{Data: dependency})
+ },
+}
diff --git a/pkg/graphql/dependency/dependency.go b/pkg/graphql/dependency/dependency.go
new file mode 100644
index 0000000..b84c8d4
--- /dev/null
+++ b/pkg/graphql/dependency/dependency.go
@@ -0,0 +1,40 @@
+// 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 (
+ "github.com/machinebox/graphql"
+ "github.com/urfave/cli"
+
+ api "skywalking.apache.org/repo/goapi/query"
+
+ "github.com/apache/skywalking-cli/assets"
+ "github.com/apache/skywalking-cli/pkg/graphql/client"
+)
+
+func EndpointDependency(ctx *cli.Context, endpointID string, duration api.Duration) (api.EndpointTopology, error) {
+ var response map[string]api.EndpointTopology
+
+ request := graphql.NewRequest(assets.Read("graphqls/dependency/EndpointDependency.graphql"))
+ request.Var("endpointId", endpointID)
+ request.Var("duration", duration)
+
+ err := client.ExecuteQuery(ctx, request, &response)
+
+ return response["result"], err
+}