Skip to content

Commit d5f3597

Browse files
authored
Support global dependency query command (#198)
1 parent d4f774f commit d5f3597

6 files changed

Lines changed: 189 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ Changes by Version
22
==================
33
Release Notes.
44

5+
0.14.0
6+
------------------
7+
8+
### Features
9+
10+
* Add the sub-command `dependency global` for adapt the global dependency query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/198
11+
12+
### Bug Fixes
13+
514
0.13.0
615
------------------
716

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ($layer: String, $duration: Duration!) {
19+
result: getGlobalTopology(duration: $duration, layer: $layer) {
20+
nodes {
21+
id
22+
name
23+
type
24+
isReal
25+
}
26+
calls {
27+
id
28+
source
29+
detectPoints
30+
target
31+
sourceComponents
32+
targetComponents
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ($duration: Duration!) {
19+
result: getGlobalTopology(duration: $duration) {
20+
nodes {
21+
id
22+
name
23+
type
24+
isReal
25+
}
26+
calls {
27+
id
28+
source
29+
detectPoints
30+
target
31+
sourceComponents
32+
targetComponents
33+
}
34+
}
35+
}

internal/commands/dependency/dependency.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ var Command = &cli.Command{
3030
ServiceCommand,
3131
InstanceCommand,
3232
ProcessCommand,
33+
GlobalCommand,
3334
},
3435
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
package dependency
19+
20+
import (
21+
"fmt"
22+
23+
"github.com/urfave/cli/v2"
24+
25+
"github.com/apache/skywalking-cli/internal/commands/interceptor"
26+
"github.com/apache/skywalking-cli/internal/flags"
27+
"github.com/apache/skywalking-cli/internal/model"
28+
"github.com/apache/skywalking-cli/pkg/display"
29+
"github.com/apache/skywalking-cli/pkg/display/displayable"
30+
"github.com/apache/skywalking-cli/pkg/graphql/dependency"
31+
"github.com/apache/skywalking-cli/pkg/graphql/metadata"
32+
33+
api "skywalking.apache.org/repo/goapi/query"
34+
)
35+
36+
var GlobalCommand = &cli.Command{
37+
Name: "global",
38+
Aliases: []string{"glb"},
39+
Usage: "Query the global dependencies",
40+
Flags: flags.Flags(
41+
flags.DurationFlags,
42+
[]cli.Flag{
43+
&cli.StringFlag{
44+
Name: "layer",
45+
Usage: "Name of the layer to query the dependency of this layer",
46+
Required: false,
47+
},
48+
},
49+
),
50+
Before: interceptor.BeforeChain(
51+
interceptor.DurationInterceptor,
52+
),
53+
Action: func(ctx *cli.Context) error {
54+
layer := ctx.String("layer")
55+
end := ctx.String("end")
56+
start := ctx.String("start")
57+
step := ctx.Generic("step")
58+
59+
duration := api.Duration{
60+
Start: start,
61+
End: end,
62+
Step: step.(*model.StepEnumValue).Selected,
63+
}
64+
65+
major, _, err := metadata.BackendVersion(ctx)
66+
if err != nil {
67+
return err
68+
}
69+
70+
var topology api.Topology
71+
if major >= 10 {
72+
topology, err = dependency.GlobalTopology(ctx, layer, duration)
73+
} else {
74+
if layer != "" {
75+
return fmt.Errorf("the layer parameter only available when OAP version >= 10.0.0")
76+
}
77+
topology, err = dependency.GlobalTopologyWithoutLayer(ctx, duration)
78+
}
79+
80+
if err != nil {
81+
return err
82+
}
83+
84+
return display.Display(ctx, &displayable.Displayable{Data: topology})
85+
},
86+
}

pkg/graphql/dependency/dependency.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ func EndpointDependency(ctx *cli.Context, endpointID string, duration api.Durati
3939
return response["result"], err
4040
}
4141

42+
func GlobalTopology(ctx *cli.Context, layer string, duration api.Duration) (api.Topology, error) {
43+
var response map[string]api.Topology
44+
45+
request := graphql.NewRequest(assets.Read("graphqls/dependency/GlobalTopology.graphql"))
46+
request.Var("layer", layer)
47+
request.Var("duration", duration)
48+
49+
err := client.ExecuteQuery(ctx, request, &response)
50+
51+
return response["result"], err
52+
}
53+
54+
func GlobalTopologyWithoutLayer(ctx *cli.Context, duration api.Duration) (api.Topology, error) {
55+
var response map[string]api.Topology
56+
57+
request := graphql.NewRequest(assets.Read("graphqls/dependency/GlobalTopologyWithoutLayer.graphql"))
58+
request.Var("duration", duration)
59+
60+
err := client.ExecuteQuery(ctx, request, &response)
61+
62+
return response["result"], err
63+
}
64+
4265
func ServiceTopology(ctx *cli.Context, serviceID string, duration api.Duration) (api.Topology, error) {
4366
var response map[string]api.Topology
4467

0 commit comments

Comments
 (0)