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 ee371a2  Add the hierarchy related commands (#200)
ee371a2 is described below

commit ee371a210afe2dc6e65c2229b6a0519f8a4a2752
Author: mrproliu <741550...@qq.com>
AuthorDate: Tue Feb 27 23:10:24 2024 +0800

    Add the hierarchy related commands (#200)
---
 .github/workflows/CI.yaml                          |  2 +-
 CHANGES.md                                         |  2 +
 assets/graphqls/dependency/ServiceTopology.graphql |  1 +
 .../InstanceHierarchy.graphql}                     | 34 ++++++------
 .../ListLayerLevels.graphql}                       | 19 ++-----
 .../ServiceHierarchy.graphql}                      | 30 +++++------
 cmd/swctl/main.go                                  |  2 +
 dist/LICENSE                                       |  4 +-
 go.mod                                             |  4 +-
 go.sum                                             | 19 +++++--
 internal/commands/hierarchy/hierarchy.go           | 30 +++++++++++
 internal/commands/hierarchy/instance.go            | 58 ++++++++++++++++++++
 internal/commands/hierarchy/layers.go              | 43 +++++++++++++++
 internal/commands/hierarchy/service.go             | 57 ++++++++++++++++++++
 pkg/graphql/hierarchy/hierarchy.go                 | 63 ++++++++++++++++++++++
 test/cases/basic/expected/dependency-service.yml   |  4 ++
 test/cases/basic/expected/layer-list.yml           | 10 ++++
 17 files changed, 327 insertions(+), 55 deletions(-)

diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml
index 9b0f2d0..19bdecf 100644
--- a/.github/workflows/CI.yaml
+++ b/.github/workflows/CI.yaml
@@ -136,7 +136,7 @@ jobs:
     strategy:
       matrix:
         oap:
-          - 6fa89c79917cb10dbf48591c46abee3b513a2bab # March 28th
+          - a65a6e0ff2ef9c716131b36172399076307c35f1 # Feb 27th, 2024
     steps:
       - uses: actions/checkout@v3
       - name: Set up Go
diff --git a/CHANGES.md b/CHANGES.md
index 594972b..cdda2fd 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -9,6 +9,8 @@ Release Notes.
 
 * Add the sub-command `dependency global` for adapt the global dependency 
query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/198
 * 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
 
 ### Bug Fixes
 
diff --git a/assets/graphqls/dependency/ServiceTopology.graphql 
b/assets/graphqls/dependency/ServiceTopology.graphql
index 590171e..035933f 100644
--- a/assets/graphqls/dependency/ServiceTopology.graphql
+++ b/assets/graphqls/dependency/ServiceTopology.graphql
@@ -21,6 +21,7 @@ query ($serviceId: ID!, $duration: Duration!) {
             id
             name
             type
+            layers
             isReal
         }
         calls {
diff --git a/assets/graphqls/dependency/ServiceTopology.graphql 
b/assets/graphqls/hierarchy/InstanceHierarchy.graphql
similarity index 62%
copy from assets/graphqls/dependency/ServiceTopology.graphql
copy to assets/graphqls/hierarchy/InstanceHierarchy.graphql
index 590171e..32c6ab5 100644
--- a/assets/graphqls/dependency/ServiceTopology.graphql
+++ b/assets/graphqls/hierarchy/InstanceHierarchy.graphql
@@ -15,21 +15,25 @@
 # specific language governing permissions and limitations
 # under the License.
 
-query ($serviceId: ID!, $duration: Duration!) {
-    result: getServiceTopology(duration: $duration, serviceId: $serviceId) {
-        nodes {
-            id
-            name
-            type
-            isReal
-        }
-        calls {
-            id
-            source
-            detectPoints
-            target
-            sourceComponents
-            targetComponents
+query ($instanceId: ID!, $layer: String!) {
+    result: getInstanceHierarchy(instanceId: $instanceId, layer: $layer) {
+        relations {
+            upperInstance {
+                id
+                name
+                serviceId
+                serviceName
+                layer
+                normal
+            }
+            lowerInstance {
+                id
+                name
+                serviceId
+                serviceName
+                layer
+                normal
+            }
         }
     }
 }
diff --git a/assets/graphqls/dependency/ServiceTopology.graphql 
b/assets/graphqls/hierarchy/ListLayerLevels.graphql
similarity index 68%
copy from assets/graphqls/dependency/ServiceTopology.graphql
copy to assets/graphqls/hierarchy/ListLayerLevels.graphql
index 590171e..5fb191f 100644
--- a/assets/graphqls/dependency/ServiceTopology.graphql
+++ b/assets/graphqls/hierarchy/ListLayerLevels.graphql
@@ -15,21 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-query ($serviceId: ID!, $duration: Duration!) {
-    result: getServiceTopology(duration: $duration, serviceId: $serviceId) {
-        nodes {
-            id
-            name
-            type
-            isReal
-        }
-        calls {
-            id
-            source
-            detectPoints
-            target
-            sourceComponents
-            targetComponents
-        }
+query {
+    result: listLayerLevels {
+        layer level
     }
 }
diff --git a/assets/graphqls/dependency/ServiceTopology.graphql 
b/assets/graphqls/hierarchy/ServiceHierarchy.graphql
similarity index 68%
copy from assets/graphqls/dependency/ServiceTopology.graphql
copy to assets/graphqls/hierarchy/ServiceHierarchy.graphql
index 590171e..258a3d7 100644
--- a/assets/graphqls/dependency/ServiceTopology.graphql
+++ b/assets/graphqls/hierarchy/ServiceHierarchy.graphql
@@ -15,21 +15,21 @@
 # specific language governing permissions and limitations
 # under the License.
 
-query ($serviceId: ID!, $duration: Duration!) {
-    result: getServiceTopology(duration: $duration, serviceId: $serviceId) {
-        nodes {
-            id
-            name
-            type
-            isReal
-        }
-        calls {
-            id
-            source
-            detectPoints
-            target
-            sourceComponents
-            targetComponents
+query ($serviceId: ID!, $layer: String!) {
+    result: getServiceHierarchy(serviceId: $serviceId, layer: $layer) {
+        relations {
+            upperService {
+                id
+                name
+                layer
+                normal
+            }
+            lowerService {
+                id
+                name
+                layer
+                normal
+            }
         }
     }
 }
diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go
index 0dd5055..1023861 100644
--- a/cmd/swctl/main.go
+++ b/cmd/swctl/main.go
@@ -30,6 +30,7 @@ import (
        "github.com/apache/skywalking-cli/internal/commands/endpoint"
        "github.com/apache/skywalking-cli/internal/commands/event"
        "github.com/apache/skywalking-cli/internal/commands/healthcheck"
+       "github.com/apache/skywalking-cli/internal/commands/hierarchy"
        "github.com/apache/skywalking-cli/internal/commands/install"
        "github.com/apache/skywalking-cli/internal/commands/instance"
        "github.com/apache/skywalking-cli/internal/commands/interceptor"
@@ -108,6 +109,7 @@ services, service instances, etc.`
                profiling.Command,
                records.Command,
                menu.Command,
+               hierarchy.Command,
        }
 
        app.Before = interceptor.BeforeChain(
diff --git a/dist/LICENSE b/dist/LICENSE
index 2229975..b53f5be 100644
--- a/dist/LICENSE
+++ b/dist/LICENSE
@@ -213,7 +213,7 @@ The text of each license is also included at 
licenses/license-[project].txt.
     k8s.io/utils v0.0.0-20210802155522-efc7438f0176 Apache-2.0
     sigs.k8s.io/controller-runtime v0.10.0 Apache-2.0
     sigs.k8s.io/structured-merge-diff/v4 v4.1.2 Apache-2.0
-    skywalking.apache.org/repo/goapi v0.0.0-20230712035303-201c1fb2d6ec 
Apache-2.0
+    skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 
Apache-2.0
 
 ========================================================================
 BSD-2-Clause licenses
@@ -250,7 +250,7 @@ The text of each license is also included at 
licenses/license-[project].txt.
     golang.org/x/term v0.17.0 BSD-3-Clause
     golang.org/x/text v0.14.0 BSD-3-Clause
     golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac BSD-3-Clause
-    google.golang.org/protobuf v1.31.0 BSD-3-Clause
+    google.golang.org/protobuf v1.32.0 BSD-3-Clause
     gopkg.in/inf.v0 v0.9.1 BSD-3-Clause
 
 ========================================================================
diff --git a/go.mod b/go.mod
index 67dff75..c030ac6 100644
--- a/go.mod
+++ b/go.mod
@@ -18,7 +18,7 @@ require (
        gopkg.in/yaml.v2 v2.4.0
        k8s.io/apimachinery v0.22.1
        sigs.k8s.io/controller-runtime v0.10.0
-       skywalking.apache.org/repo/goapi v0.0.0-20230712035303-201c1fb2d6ec
+       skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361
 )
 
 require (
@@ -75,7 +75,7 @@ require (
        gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
        google.golang.org/appengine v1.6.7 // indirect
        google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 // 
indirect
-       google.golang.org/protobuf v1.31.0 // indirect
+       google.golang.org/protobuf v1.32.0 // indirect
        gopkg.in/inf.v0 v0.9.1 // indirect
        gopkg.in/ini.v1 v1.51.0 // indirect
        gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
diff --git a/go.sum b/go.sum
index 94929a3..c815258 100644
--- a/go.sum
+++ b/go.sum
@@ -505,6 +505,7 @@ golang.org/x/crypto 
v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
 golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod 
h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod 
h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod 
h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.18.0/go.mod 
h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
 golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
 golang.org/x/crypto v0.20.0/go.mod 
h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod 
h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -541,6 +542,7 @@ golang.org/x/mod v0.2.0/go.mod 
h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod 
h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
+golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod 
h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod 
h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod 
h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -577,6 +579,8 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod 
h1:OJAsFXCWl8Ukc7SiCT
 golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod 
h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod 
h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
+golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
+golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
 golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
 golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod 
h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -595,6 +599,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod 
h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod 
h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -647,6 +652,8 @@ golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod 
h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod 
h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
 golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod 
h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
@@ -654,6 +661,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod 
h1:bj7SfCRtBDWHUb9sn
 golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod 
h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod 
h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
+golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
+golang.org/x/term v0.16.0/go.mod 
h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
 golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
 golang.org/x/term v0.17.0/go.mod 
h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod 
h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -665,6 +674,7 @@ golang.org/x/text v0.3.5/go.mod 
h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
 golang.org/x/text v0.14.0/go.mod 
h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod 
h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -717,6 +727,7 @@ golang.org/x/tools v0.1.2/go.mod 
h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/tools v0.1.3/go.mod 
h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/tools v0.1.12/go.mod 
h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
+golang.org/x/tools v0.6.0/go.mod 
h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod 
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod 
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod 
h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -793,8 +804,8 @@ google.golang.org/protobuf v1.24.0/go.mod 
h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
 google.golang.org/protobuf v1.25.0/go.mod 
h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
 google.golang.org/protobuf v1.26.0-rc.1/go.mod 
h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
 google.golang.org/protobuf v1.26.0/go.mod 
h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-google.golang.org/protobuf v1.31.0 
h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
-google.golang.org/protobuf v1.31.0/go.mod 
h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.32.0 
h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
+google.golang.org/protobuf v1.32.0/go.mod 
h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod 
h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod 
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod 
h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -868,5 +879,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 
h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
 sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod 
h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
 sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
 sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
-skywalking.apache.org/repo/goapi v0.0.0-20230712035303-201c1fb2d6ec 
h1:s+C9qfKkom7OYFKo8sGtXlXk6jU8DjRiI6bh/CgrpD4=
-skywalking.apache.org/repo/goapi v0.0.0-20230712035303-201c1fb2d6ec/go.mod 
h1:onFubXaIoY/2FTRVrLMqCTlaNq4SilAEwF/2G0IcaBw=
+skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361 
h1:FCGGU4Tut3LI/zMRXSgJgUL/kmSQ4b7QktFgRBhqaDs=
+skywalking.apache.org/repo/goapi v0.0.0-20240227092755-edee3273b361/go.mod 
h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
diff --git a/internal/commands/hierarchy/hierarchy.go 
b/internal/commands/hierarchy/hierarchy.go
new file mode 100644
index 0000000..7f1423a
--- /dev/null
+++ b/internal/commands/hierarchy/hierarchy.go
@@ -0,0 +1,30 @@
+// 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 hierarchy
+
+import "github.com/urfave/cli/v2"
+
+var Command = &cli.Command{
+       Name:  "hierarchy",
+       Usage: "Hierarchy related sub-command",
+       Subcommands: []*cli.Command{
+               serviceCommand,
+               instanceCommand,
+               layerCommand,
+       },
+}
diff --git a/internal/commands/hierarchy/instance.go 
b/internal/commands/hierarchy/instance.go
new file mode 100644
index 0000000..7ff865f
--- /dev/null
+++ b/internal/commands/hierarchy/instance.go
@@ -0,0 +1,58 @@
+// 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 hierarchy
+
+import (
+       "github.com/apache/skywalking-cli/internal/commands/interceptor"
+       "github.com/apache/skywalking-cli/internal/flags"
+       "github.com/apache/skywalking-cli/pkg/display"
+       "github.com/apache/skywalking-cli/pkg/display/displayable"
+       "github.com/apache/skywalking-cli/pkg/graphql/hierarchy"
+
+       "github.com/urfave/cli/v2"
+)
+
+var instanceCommand = &cli.Command{
+       Name:    "instance",
+       Aliases: []string{"inst"},
+       Usage:   "Query the hierarchy of given service instance",
+       Flags: flags.Flags(
+               flags.ServiceFlags,
+               flags.InstanceFlags,
+               []cli.Flag{
+                       &cli.StringFlag{
+                               Name:     "layer",
+                               Usage:    "Name of the layer to query the 
hierarchy of this layer",
+                               Required: true,
+                       },
+               },
+       ),
+       Before: interceptor.BeforeChain(
+               interceptor.ParseInstance(true),
+       ),
+       Action: func(ctx *cli.Context) error {
+               instanceID := ctx.String("instance-id")
+               layer := ctx.String("layer")
+
+               hierarchy, err := hierarchy.InstanceHierarchy(ctx, instanceID, 
layer)
+               if err != nil {
+                       return err
+               }
+               return display.Display(ctx, &displayable.Displayable{Data: 
hierarchy, Condition: instanceID})
+       },
+}
diff --git a/internal/commands/hierarchy/layers.go 
b/internal/commands/hierarchy/layers.go
new file mode 100644
index 0000000..ffbdb20
--- /dev/null
+++ b/internal/commands/hierarchy/layers.go
@@ -0,0 +1,43 @@
+// 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 hierarchy
+
+import (
+       "github.com/apache/skywalking-cli/internal/commands/interceptor"
+       "github.com/apache/skywalking-cli/internal/flags"
+       "github.com/apache/skywalking-cli/pkg/display"
+       "github.com/apache/skywalking-cli/pkg/display/displayable"
+       "github.com/apache/skywalking-cli/pkg/graphql/hierarchy"
+
+       "github.com/urfave/cli/v2"
+)
+
+var layerCommand = &cli.Command{
+       Name:    "layer-levels",
+       Aliases: []string{"ll"},
+       Usage:   "Query all layer hierarchy levels",
+       Flags:   flags.Flags(),
+       Before:  interceptor.BeforeChain(),
+       Action: func(ctx *cli.Context) error {
+               levels, err := hierarchy.ListLayerLevels(ctx)
+               if err != nil {
+                       return err
+               }
+               return display.Display(ctx, &displayable.Displayable{Data: 
levels})
+       },
+}
diff --git a/internal/commands/hierarchy/service.go 
b/internal/commands/hierarchy/service.go
new file mode 100644
index 0000000..8d8beb7
--- /dev/null
+++ b/internal/commands/hierarchy/service.go
@@ -0,0 +1,57 @@
+// 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 hierarchy
+
+import (
+       "github.com/apache/skywalking-cli/internal/commands/interceptor"
+       "github.com/apache/skywalking-cli/internal/flags"
+       "github.com/apache/skywalking-cli/pkg/display"
+       "github.com/apache/skywalking-cli/pkg/display/displayable"
+       "github.com/apache/skywalking-cli/pkg/graphql/hierarchy"
+
+       "github.com/urfave/cli/v2"
+)
+
+var serviceCommand = &cli.Command{
+       Name:    "service",
+       Aliases: []string{"svc"},
+       Usage:   "Query the hierarchy of given service",
+       Flags: flags.Flags(
+               flags.ServiceFlags,
+               []cli.Flag{
+                       &cli.StringFlag{
+                               Name:     "layer",
+                               Usage:    "Name of the layer to query the 
hierarchy of this layer",
+                               Required: true,
+                       },
+               },
+       ),
+       Before: interceptor.BeforeChain(
+               interceptor.ParseService(true),
+       ),
+       Action: func(ctx *cli.Context) error {
+               serviceID := ctx.String("service-id")
+               layer := ctx.String("layer")
+
+               hierarchy, err := hierarchy.ServiceHierarchy(ctx, serviceID, 
layer)
+               if err != nil {
+                       return err
+               }
+               return display.Display(ctx, &displayable.Displayable{Data: 
hierarchy, Condition: serviceID})
+       },
+}
diff --git a/pkg/graphql/hierarchy/hierarchy.go 
b/pkg/graphql/hierarchy/hierarchy.go
new file mode 100644
index 0000000..52803b9
--- /dev/null
+++ b/pkg/graphql/hierarchy/hierarchy.go
@@ -0,0 +1,63 @@
+// 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 hierarchy
+
+import (
+       "github.com/apache/skywalking-cli/assets"
+       "github.com/apache/skywalking-cli/pkg/graphql/client"
+
+       "github.com/machinebox/graphql"
+
+       "github.com/urfave/cli/v2"
+
+       api "skywalking.apache.org/repo/goapi/query"
+)
+
+func ServiceHierarchy(ctx *cli.Context, serviceID, layer string) 
(api.ServiceHierarchy, error) {
+       var response map[string]api.ServiceHierarchy
+
+       request := 
graphql.NewRequest(assets.Read("graphqls/hierarchy/ServiceHierarchy.graphql"))
+       request.Var("serviceId", serviceID)
+       request.Var("layer", layer)
+
+       err := client.ExecuteQuery(ctx, request, &response)
+
+       return response["result"], err
+}
+
+func InstanceHierarchy(ctx *cli.Context, instanceID, layer string) 
(api.InstanceHierarchy, error) {
+       var response map[string]api.InstanceHierarchy
+
+       request := 
graphql.NewRequest(assets.Read("graphqls/hierarchy/InstanceHierarchy.graphql"))
+       request.Var("instanceId", instanceID)
+       request.Var("layer", layer)
+
+       err := client.ExecuteQuery(ctx, request, &response)
+
+       return response["result"], err
+}
+
+func ListLayerLevels(ctx *cli.Context) ([]api.LayerLevel, error) {
+       var response map[string][]api.LayerLevel
+
+       request := 
graphql.NewRequest(assets.Read("graphqls/hierarchy/ListLayerLevels.graphql"))
+
+       err := client.ExecuteQuery(ctx, request, &response)
+
+       return response["result"], err
+}
diff --git a/test/cases/basic/expected/dependency-service.yml 
b/test/cases/basic/expected/dependency-service.yml
index 7bcb353..6bf530f 100644
--- a/test/cases/basic/expected/dependency-service.yml
+++ b/test/cases/basic/expected/dependency-service.yml
@@ -19,10 +19,14 @@ nodes:
   name: provider
   type: Python
   isreal: true
+  layers:
+    - GENERAL
 - id: {{ b64enc "consumer" }}.1
   name: consumer
   type: Python
   isreal: true
+  layers:
+    - GENERAL
   {{- end }}
 calls:
   {{- contains .calls }}
diff --git a/test/cases/basic/expected/layer-list.yml 
b/test/cases/basic/expected/layer-list.yml
index d400af2..356d8be 100644
--- a/test/cases/basic/expected/layer-list.yml
+++ b/test/cases/basic/expected/layer-list.yml
@@ -14,10 +14,13 @@
 # limitations under the License.
 
 - BROWSER
+- RABBITMQ
 - MESH
 - GENERAL
 - FAAS
 - MESH_CP
+- AWS_GATEWAY
+- NGINX
 - SO11Y_SATELLITE
 - K8S_SERVICE
 - VIRTUAL_GATEWAY
@@ -27,14 +30,21 @@
 - VIRTUAL_DATABASE
 - K8S
 - VIRTUAL_MQ
+- PULSAR
+- MONGODB
 - CACHE
 - OS_WINDOWS
 - MESH_DP
 - SO11Y_OAP
 - DATABASE
 - OS_LINUX
+- REDIS
+- KAFKA
+- ELASTICSEARCH
+- ROCKETMQ
 - APISIX
 - VIRTUAL_CACHE
 - POSTGRESQL
 - AWS_S3
+- BOOKKEEPER
 - AWS_DYNAMODB
\ No newline at end of file

Reply via email to