Skip to content

Commit 152d6ad

Browse files
authored
Add continuous profiling and metrics query related commands (#182)
1 parent 719681f commit 152d6ad

13 files changed

Lines changed: 282 additions & 8 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Release Notes.
4040
* Add the sub-command `metrics nullable` for query the nullable metrics value. @mrproliu in https://github.com/apache/skywalking-cli/pull/176
4141
* Adapt the sub-command `profiling trace` for adapt the new trace profiling protocol. @mrproliu in https://github.com/apache/skywalking-cli/pull/177
4242
* Add `isEmptyValue` field in metrics related sub-commands. @mrproliu in https://github.com/apache/skywalking-cli/pull/180
43+
* Add the sub-command `metrics execute` for execute the metrics query. @mrproliu in https://github.com/apache/skywalking-cli/pull/182
44+
* Add the sub-command `profiling continuous monitoring` for query all continuous profiling monitoring instances. @mrproliu in https://github.com/apache/skywalking-cli/pull/182
4345

4446
0.10.0
4547
------------------
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 ($expression: String!, $entity: Entity!, $duration: Duration!) {
19+
result: execExpression(expression: $expression, entity: $entity, duration: $duration) {
20+
type
21+
results {
22+
metric {
23+
labels {
24+
key value
25+
}
26+
}
27+
values {
28+
id
29+
value
30+
traceID
31+
}
32+
}
33+
error
34+
}
35+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 ($serviceId: ID!, $target: ContinuousProfilingTargetType!){
19+
result: queryContinuousProfilingMonitoringInstances(serviceId: $serviceId, target: $target) {
20+
id
21+
name
22+
attributes {
23+
name
24+
value
25+
}
26+
triggeredCount
27+
lastTriggerTimestamp
28+
29+
processes {
30+
id
31+
name
32+
detectType
33+
labels
34+
triggeredCount
35+
lastTriggerTimestamp
36+
}
37+
}
38+
}

assets/graphqls/profiling/continuous/QueryContinuousProfilingServiceTargets.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ query ($serviceId: ID!){
2626
uriList
2727
uriRegex
2828
}
29+
triggeredCount
30+
lastTriggerTimestamp
2931
}
3032
}

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-20230314034821-0c5a44bb767a Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20230608051849-a29bda277aac 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.29.0 BSD-3-Clause
253+
google.golang.org/protobuf v1.30.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-20230314034821-0c5a44bb767a
23+
skywalking.apache.org/repo/goapi v0.0.0-20230608051849-a29bda277aac
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.29.0 // indirect
80+
google.golang.org/protobuf v1.30.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.29.0 h1:44S3JjaKmLEE4YIkjzexaP+NzZsudE3Zin5Njn/pYX0=
793-
google.golang.org/protobuf v1.29.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
792+
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
793+
google.golang.org/protobuf v1.30.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-20230314034821-0c5a44bb767a h1:m8DTnaSEOEnPXRWmA6g7isbdqw7WPZP6SnaEHz1Sx7s=
868-
skywalking.apache.org/repo/goapi v0.0.0-20230314034821-0c5a44bb767a/go.mod h1:LcZMcxDjdJPn5yetydFnxe0l7rmiv8lvHEnzRbsey14=
867+
skywalking.apache.org/repo/goapi v0.0.0-20230608051849-a29bda277aac h1:8Ra0KXu0lNlEKCRvsNbBXYEFpMx5Tmfm0krekUM9FNE=
868+
skywalking.apache.org/repo/goapi v0.0.0-20230608051849-a29bda277aac/go.mod h1:bW4dg0GUN4rMCMS8DLlaY3ZiKUAJ1fQYKoZ91Bl0kTk=
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 expression
19+
20+
import (
21+
"github.com/apache/skywalking-cli/internal/commands/interceptor"
22+
"github.com/apache/skywalking-cli/internal/flags"
23+
"github.com/apache/skywalking-cli/internal/model"
24+
"github.com/apache/skywalking-cli/pkg/display"
25+
"github.com/apache/skywalking-cli/pkg/display/displayable"
26+
"github.com/apache/skywalking-cli/pkg/graphql/metrics"
27+
28+
"github.com/urfave/cli/v2"
29+
30+
api "skywalking.apache.org/repo/goapi/query"
31+
)
32+
33+
const expressionParameterName = "expression"
34+
35+
var ExecCommand = &cli.Command{
36+
Name: "execute",
37+
Aliases: []string{"exec"},
38+
Usage: `Execute a metrics expression.`,
39+
UsageText: `Execute a metrics expression.
40+
41+
Examples:
42+
1. Execute the given expression of service "business-zone::projectB"
43+
$ swctl metrics execute --expression="service_resp_time" --service-name business-zone::projectB`,
44+
Flags: flags.Flags(
45+
flags.DurationFlags,
46+
flags.InstanceRelationFlags,
47+
flags.EndpointRelationFlags,
48+
flags.ProcessRelationFlags,
49+
[]cli.Flag{
50+
&cli.StringFlag{
51+
Name: expressionParameterName,
52+
Usage: "metrics expression",
53+
Required: true,
54+
},
55+
},
56+
),
57+
Before: interceptor.BeforeChain(
58+
interceptor.DurationInterceptor,
59+
interceptor.ParseEndpointRelation(false),
60+
interceptor.ParseInstanceRelation(false),
61+
interceptor.ParseProcessRelation(false),
62+
),
63+
Action: func(ctx *cli.Context) error {
64+
end := ctx.String("end")
65+
start := ctx.String("start")
66+
step := ctx.Generic("step")
67+
68+
expression := ctx.String(expressionParameterName)
69+
entity, err := interceptor.ParseEntity(ctx)
70+
if err != nil {
71+
return err
72+
}
73+
74+
duration := api.Duration{
75+
Start: start,
76+
End: end,
77+
Step: step.(*model.StepEnumValue).Selected,
78+
}
79+
80+
result, err := metrics.Execute(ctx, expression, entity, duration)
81+
if err != nil {
82+
return err
83+
}
84+
85+
return display.Display(ctx, &displayable.Displayable{Data: result})
86+
},
87+
}

internal/commands/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/apache/skywalking-cli/internal/commands/metrics/thermodynamic"
2727

28+
"github.com/apache/skywalking-cli/internal/commands/metrics/expression"
2829
"github.com/apache/skywalking-cli/internal/commands/metrics/linear"
2930
"github.com/apache/skywalking-cli/internal/commands/metrics/single"
3031
)
@@ -42,5 +43,6 @@ var Command = &cli.Command{
4243
aggregation.SortedMetrics,
4344
aggregation.SampledRecords,
4445
list.Command,
46+
expression.ExecCommand,
4547
},
4648
}

internal/commands/profiling/continuous/continuous.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ var Command = &cli.Command{
2525
Subcommands: []*cli.Command{
2626
SetPolicyCommand,
2727
ListCommand,
28+
Monitoring,
2829
},
2930
}

0 commit comments

Comments
 (0)