Skip to content

Commit 67cbc89

Browse files
authored
Adapt alarm and MQE query API (#210)
1 parent 97319af commit 67cbc89

File tree

12 files changed

+240
-4
lines changed

12 files changed

+240
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Release Notes.
99

1010
* Add the sub-command `profiling async` for async-profiler query API by @zhengziyi0117 in https://github.com/apache/skywalking-cli/pull/203
1111
* Support the owner in MQE response by using [10.2 MQE query protocol](https://github.com/apache/skywalking-query-protocol/pull/141) by @zhengziyi0117 in https://github.com/apache/skywalking-cli/pull/203
12+
* Add the sub-command `alarm autocomplete-keys` and `alarm auto-complete-values` for alarm query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
13+
* Adapt the alarm message query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
14+
* Add the owner field in the `metrics exec` query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210
1215

1316
### Bug Fixes
1417

assets/graphqls/alarm/alarms.graphql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ query ($duration: Duration!, $scope: Scope, $keyword: String, $paging: Paginatio
2121
startTime
2222
scope
2323
id
24+
name
2425
message
2526
tags {
2627
key, value
@@ -39,6 +40,27 @@ query ($duration: Duration!, $scope: Scope, $keyword: String, $paging: Paginatio
3940
uuid
4041
layer
4142
}
43+
snapshot {
44+
expression
45+
metrics {
46+
name
47+
results {
48+
metric {
49+
labels {
50+
key value
51+
}
52+
}
53+
values {
54+
id
55+
value
56+
traceID
57+
owner {
58+
scope serviceID serviceName normal serviceInstanceID serviceInstanceName endpointID endpointName
59+
}
60+
}
61+
}
62+
}
63+
}
4264
}
4365
}
4466
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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: queryAlarmTagAutocompleteKeys(duration: $duration)
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 ($tagKey: String!, $duration: Duration!) {
19+
result: queryAlarmTagAutocompleteValues(tagKey: $tagKey, duration: $duration)
20+
}

assets/graphqls/metrics/ExecuteExpression.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ query ($expression: String!, $entity: Entity!, $duration: Duration!) {
2828
id
2929
value
3030
traceID
31+
owner {
32+
scope serviceID serviceName normal serviceInstanceID serviceInstanceName endpointID endpointName
33+
}
3134
}
3235
}
3336
error

dist/LICENSE

Lines changed: 1 addition & 1 deletion
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-20241129131257-944118bb91b8 Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46 Apache-2.0
217217

218218
========================================================================
219219
BSD-2-Clause licenses

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
gopkg.in/yaml.v2 v2.4.0
1919
k8s.io/apimachinery v0.22.1
2020
sigs.k8s.io/controller-runtime v0.10.0
21-
skywalking.apache.org/repo/goapi v0.0.0-20241129131257-944118bb91b8
21+
skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46
2222
)
2323

2424
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,5 +879,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
879879
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
880880
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
881881
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
882-
skywalking.apache.org/repo/goapi v0.0.0-20241129131257-944118bb91b8 h1:JkgizChUyT1mobFo2I3lI8+qsQU22i3FdxR0BSFC0uw=
883-
skywalking.apache.org/repo/goapi v0.0.0-20241129131257-944118bb91b8/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=
882+
skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46 h1:Lb9cumKH17PWZSs6BKT91dbwJAl1jCvYO7EQMM9yFTw=
883+
skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE=

internal/commands/alarm/alarm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ var Command = &cli.Command{
2626
Usage: "Alarm related sub-command",
2727
Subcommands: []*cli.Command{
2828
listCommand,
29+
autocompleteKeysCommand,
30+
autocompleteValuesCommand,
2931
},
3032
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 alarm
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/alarm"
29+
30+
api "skywalking.apache.org/repo/goapi/query"
31+
)
32+
33+
var autocompleteKeysCommand = &cli.Command{
34+
Name: "autocomplete-keys",
35+
Aliases: []string{"ks"},
36+
Usage: "Query autocomplete Keys",
37+
UsageText: `Query autocomplete keys
38+
39+
Examples:
40+
1. Query autocomplete keys:
41+
$ swctl alarm autocomplete-keys
42+
`,
43+
Flags: flags.Flags(
44+
flags.DurationFlags,
45+
),
46+
Before: interceptor.BeforeChain(
47+
interceptor.DurationInterceptor,
48+
),
49+
Action: func(ctx *cli.Context) error {
50+
start := ctx.String("start")
51+
end := ctx.String("end")
52+
step := ctx.Generic("step")
53+
54+
duration := api.Duration{
55+
Start: start,
56+
End: end,
57+
Step: step.(*model.StepEnumValue).Selected,
58+
}
59+
60+
autocompleteKeys, err := alarm.TagAutocompleteKeys(ctx, duration)
61+
if err != nil {
62+
return err
63+
}
64+
65+
return display.Display(ctx, &displayable.Displayable{Data: autocompleteKeys, Condition: duration})
66+
},
67+
}

0 commit comments

Comments
 (0)