Skip to content

Commit f3d3445

Browse files
authored
Add the sub-command metrics nullable for query the nullable metrics value (#176)
1 parent 9aa1e75 commit f3d3445

8 files changed

Lines changed: 130 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Release Notes.
3737
* Add the sub-command `profiling continuous` for adapt the new continuous profiling API by @mrproliu in https://github.com/apache/skywalking-cli/pull/173
3838
* Adapt the sub-command `metrics` for deprecate scope fron entity by @mrproliu in https://github.com/apache/skywalking-cli/pull/173
3939
* Add components in topology related sub-commands. @mrproliu in https://github.com/apache/skywalking-cli/pull/175
40+
* Add the sub-command `metrics nullable` for query the nullable metrics value. @mrproliu in https://github.com/apache/skywalking-cli/pull/176
4041

4142
0.10.0
4243
------------------
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 ($condition: MetricsCondition!, $duration: Duration!) {
19+
result: readNullableMetricsValue(condition: $condition, duration: $duration) {
20+
value
21+
}
22+
}

dist/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The text of each license is also included at licenses/license-[project].txt.
213213
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 Apache-2.0
214214
sigs.k8s.io/controller-runtime v0.10.0 Apache-2.0
215215
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 Apache-2.0
216-
skywalking.apache.org/repo/goapi v0.0.0-20230301143132-aa3f8469385b Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20230314034821-0c5a44bb767a Apache-2.0
217217

218218
========================================================================
219219
BSD-2-Clause licenses
@@ -250,7 +250,7 @@ The text of each license is also included at licenses/license-[project].txt.
250250
golang.org/x/term v0.5.0 BSD-3-Clause
251251
golang.org/x/text v0.7.0 BSD-3-Clause
252252
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac BSD-3-Clause
253-
google.golang.org/protobuf v1.28.1 BSD-3-Clause
253+
google.golang.org/protobuf v1.29.0 BSD-3-Clause
254254
gopkg.in/inf.v0 v0.9.1 BSD-3-Clause
255255

256256
========================================================================

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
gopkg.in/yaml.v2 v2.4.0
2121
k8s.io/apimachinery v0.22.1
2222
sigs.k8s.io/controller-runtime v0.10.0
23-
skywalking.apache.org/repo/goapi v0.0.0-20230301143132-aa3f8469385b
23+
skywalking.apache.org/repo/goapi v0.0.0-20230314034821-0c5a44bb767a
2424
)
2525

2626
require (
@@ -77,7 +77,7 @@ require (
7777
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
7878
google.golang.org/appengine v1.6.7 // indirect
7979
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 // indirect
80-
google.golang.org/protobuf v1.28.1 // indirect
80+
google.golang.org/protobuf v1.29.0 // indirect
8181
gopkg.in/inf.v0 v0.9.1 // indirect
8282
gopkg.in/ini.v1 v1.51.0 // indirect
8383
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
789789
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
790790
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
791791
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
792-
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
793-
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
792+
google.golang.org/protobuf v1.29.0 h1:44S3JjaKmLEE4YIkjzexaP+NzZsudE3Zin5Njn/pYX0=
793+
google.golang.org/protobuf v1.29.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
794794
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
795795
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
796796
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -864,5 +864,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
864864
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
865865
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
866866
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
867-
skywalking.apache.org/repo/goapi v0.0.0-20230301143132-aa3f8469385b h1:VAWQr1mJk4P/a8VZ9UASY8H53wj0zdLHgYvhddyQcXw=
868-
skywalking.apache.org/repo/goapi v0.0.0-20230301143132-aa3f8469385b/go.mod h1:WovoDv1GA+8VuvHPVJL7q/fL0KlYPBZq5rTMCFQRzJU=
867+
skywalking.apache.org/repo/goapi v0.0.0-20230314034821-0c5a44bb767a h1:m8DTnaSEOEnPXRWmA6g7isbdqw7WPZP6SnaEHz1Sx7s=
868+
skywalking.apache.org/repo/goapi v0.0.0-20230314034821-0c5a44bb767a/go.mod h1:LcZMcxDjdJPn5yetydFnxe0l7rmiv8lvHEnzRbsey14=

internal/commands/metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var Command = &cli.Command{
3434
Usage: "Query metrics defined in backend OAL",
3535
Subcommands: cli.Commands{
3636
single.Command,
37+
single.NullableCommand,
3738
linear.Single,
3839
linear.Multiple,
3940
thermodynamic.Command,
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 single
19+
20+
import (
21+
"github.com/urfave/cli/v2"
22+
23+
"github.com/apache/skywalking-cli/internal/commands/interceptor"
24+
"github.com/apache/skywalking-cli/internal/flags"
25+
"github.com/apache/skywalking-cli/internal/model"
26+
"github.com/apache/skywalking-cli/pkg/display"
27+
"github.com/apache/skywalking-cli/pkg/display/displayable"
28+
"github.com/apache/skywalking-cli/pkg/graphql/metrics"
29+
30+
api "skywalking.apache.org/repo/goapi/query"
31+
)
32+
33+
var NullableCommand = &cli.Command{
34+
Name: "nullable",
35+
Usage: "query nullable-value metrics defined in backend OAL",
36+
UsageText: `Query nullable-value metrics defined in backend OAL.
37+
38+
Examples:
39+
1. Query the traffic load (calls per minute) of service "business-zone:projectC"
40+
$ swctl metrics nullable --name service_cpm --service-name business-zone::projectC
41+
42+
2. Query the traffic load (calls per minute) of service "business-zone:projectC" endpoint "/projectC/{value}"
43+
$ swctl metrics nullable --name endpoint_cpm --service-name business-zone::projectC --endpoint-name /projectC/{value}`,
44+
Flags: flags.Flags(
45+
flags.DurationFlags,
46+
flags.MetricsFlags,
47+
flags.InstanceRelationFlags,
48+
flags.EndpointRelationFlags,
49+
flags.ProcessRelationFlags,
50+
),
51+
Before: interceptor.BeforeChain(
52+
interceptor.DurationInterceptor,
53+
interceptor.ParseEndpointRelation(false),
54+
interceptor.ParseInstanceRelation(false),
55+
interceptor.ParseProcessRelation(false),
56+
),
57+
Action: func(ctx *cli.Context) error {
58+
end := ctx.String("end")
59+
start := ctx.String("start")
60+
step := ctx.Generic("step")
61+
62+
metricsName := ctx.String("name")
63+
entity, err := interceptor.ParseEntity(ctx)
64+
if err != nil {
65+
return err
66+
}
67+
68+
duration := api.Duration{
69+
Start: start,
70+
End: end,
71+
Step: step.(*model.StepEnumValue).Selected,
72+
}
73+
74+
metricsValue, err := metrics.NullableIntValue(ctx, api.MetricsCondition{
75+
Name: metricsName,
76+
Entity: entity,
77+
}, duration)
78+
79+
if err != nil {
80+
return err
81+
}
82+
83+
return display.Display(ctx, &displayable.Displayable{Data: metricsValue.Value})
84+
},
85+
}

pkg/graphql/metrics/metrics.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ func IntValues(ctx *cli.Context, condition api.MetricsCondition, duration api.Du
4040
return response["result"], err
4141
}
4242

43+
func NullableIntValue(ctx *cli.Context, condition api.MetricsCondition, duration api.Duration) (api.NullableValue, error) {
44+
var response map[string]api.NullableValue
45+
46+
request := graphql.NewRequest(assets.Read("graphqls/metrics/NullableMetricsValue.graphql"))
47+
48+
request.Var("condition", condition)
49+
request.Var("duration", duration)
50+
51+
err := client.ExecuteQuery(ctx, request, &response)
52+
53+
return response["result"], err
54+
}
55+
4356
func LinearIntValues(ctx *cli.Context, condition api.MetricsCondition, duration api.Duration) (api.MetricsValues, error) {
4457
var response map[string]api.MetricsValues
4558

0 commit comments

Comments
 (0)