This is an automated email from the ASF dual-hosted git repository. liuhan pushed a commit to branch alarm-mqe in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
commit 938ee91e271a724924ad3e7b6361e6dbf8ae8690 Author: mrproliu <[email protected]> AuthorDate: Tue Dec 31 16:25:09 2024 +0800 Adapt alarm and MQE query API --- CHANGES.md | 3 + assets/graphqls/alarm/alarms.graphql | 22 +++++++ .../tagAutocompleteKeys.graphql} | 19 +----- .../tagAutocompleteValues.graphql} | 19 +----- assets/graphqls/metrics/ExecuteExpression.graphql | 3 + go.mod | 2 +- go.sum | 4 +- internal/commands/alarm/alarm.go | 2 + internal/commands/alarm/autopleteKeys.go | 67 +++++++++++++++++++ internal/commands/alarm/autopleteValues.go | 76 ++++++++++++++++++++++ pkg/graphql/alarm/alarm.go | 23 +++++++ 11 files changed, 203 insertions(+), 37 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 44eb92e..fa7d53e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,9 @@ Release Notes. * Add the sub-command `profiling async` for async-profiler query API by @zhengziyi0117 in https://github.com/apache/skywalking-cli/pull/203 * 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 +* 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 +* Adapt the alarm message query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210 +* Add the owner field in the `metrics exec` query API by @mrproliu in https://github.com/apache/skywalking-cli/pull/210 ### Bug Fixes diff --git a/assets/graphqls/alarm/alarms.graphql b/assets/graphqls/alarm/alarms.graphql index d6370e5..da2cbbe 100644 --- a/assets/graphqls/alarm/alarms.graphql +++ b/assets/graphqls/alarm/alarms.graphql @@ -21,6 +21,7 @@ query ($duration: Duration!, $scope: Scope, $keyword: String, $paging: Paginatio startTime scope id + name message tags { key, value @@ -39,6 +40,27 @@ query ($duration: Duration!, $scope: Scope, $keyword: String, $paging: Paginatio uuid layer } + snapshot { + expression + metrics { + name + results { + metric { + labels { + key value + } + } + values { + id + value + traceID + owner { + scope serviceID serviceName normal serviceInstanceID serviceInstanceName endpointID endpointName + } + } + } + } + } } } } diff --git a/assets/graphqls/metrics/ExecuteExpression.graphql b/assets/graphqls/alarm/tagAutocompleteKeys.graphql similarity index 65% copy from assets/graphqls/metrics/ExecuteExpression.graphql copy to assets/graphqls/alarm/tagAutocompleteKeys.graphql index a03f378..ae0f52d 100644 --- a/assets/graphqls/metrics/ExecuteExpression.graphql +++ b/assets/graphqls/alarm/tagAutocompleteKeys.graphql @@ -15,21 +15,6 @@ # specific language governing permissions and limitations # under the License. -query ($expression: String!, $entity: Entity!, $duration: Duration!) { - result: execExpression(expression: $expression, entity: $entity, duration: $duration) { - type - results { - metric { - labels { - key value - } - } - values { - id - value - traceID - } - } - error - } +query ($duration: Duration!) { + result: queryAlarmTagAutocompleteKeys(duration: $duration) } diff --git a/assets/graphqls/metrics/ExecuteExpression.graphql b/assets/graphqls/alarm/tagAutocompleteValues.graphql similarity index 65% copy from assets/graphqls/metrics/ExecuteExpression.graphql copy to assets/graphqls/alarm/tagAutocompleteValues.graphql index a03f378..9ba9f6f 100644 --- a/assets/graphqls/metrics/ExecuteExpression.graphql +++ b/assets/graphqls/alarm/tagAutocompleteValues.graphql @@ -15,21 +15,6 @@ # specific language governing permissions and limitations # under the License. -query ($expression: String!, $entity: Entity!, $duration: Duration!) { - result: execExpression(expression: $expression, entity: $entity, duration: $duration) { - type - results { - metric { - labels { - key value - } - } - values { - id - value - traceID - } - } - error - } +query ($tagKey: String!, $duration: Duration!) { + result: queryAlarmTagAutocompleteValues(tagKey: $tagKey, duration: $duration) } diff --git a/assets/graphqls/metrics/ExecuteExpression.graphql b/assets/graphqls/metrics/ExecuteExpression.graphql index a03f378..04d89be 100644 --- a/assets/graphqls/metrics/ExecuteExpression.graphql +++ b/assets/graphqls/metrics/ExecuteExpression.graphql @@ -28,6 +28,9 @@ query ($expression: String!, $entity: Entity!, $duration: Duration!) { id value traceID + owner { + scope serviceID serviceName normal serviceInstanceID serviceInstanceName endpointID endpointName + } } } error diff --git a/go.mod b/go.mod index e98246d..af7daee 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-20241129131257-944118bb91b8 + skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46 ) require ( diff --git a/go.sum b/go.sum index bf5055a..9197db1 100644 --- a/go.sum +++ b/go.sum @@ -879,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-20241129131257-944118bb91b8 h1:JkgizChUyT1mobFo2I3lI8+qsQU22i3FdxR0BSFC0uw= -skywalking.apache.org/repo/goapi v0.0.0-20241129131257-944118bb91b8/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE= +skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46 h1:Lb9cumKH17PWZSs6BKT91dbwJAl1jCvYO7EQMM9yFTw= +skywalking.apache.org/repo/goapi v0.0.0-20241231024338-a68ffc997f46/go.mod h1:+n8BMuS8eRdzdnGh15ElRGBXPi0eYZSs2TKySBDmRTE= diff --git a/internal/commands/alarm/alarm.go b/internal/commands/alarm/alarm.go index ac25b40..88dc766 100644 --- a/internal/commands/alarm/alarm.go +++ b/internal/commands/alarm/alarm.go @@ -26,5 +26,7 @@ var Command = &cli.Command{ Usage: "Alarm related sub-command", Subcommands: []*cli.Command{ listCommand, + autocompleteKeysCommand, + autocompleteValuesCommand, }, } diff --git a/internal/commands/alarm/autopleteKeys.go b/internal/commands/alarm/autopleteKeys.go new file mode 100644 index 0000000..6a9b081 --- /dev/null +++ b/internal/commands/alarm/autopleteKeys.go @@ -0,0 +1,67 @@ +// 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 alarm + +import ( + "github.com/urfave/cli/v2" + + "github.com/apache/skywalking-cli/internal/commands/interceptor" + "github.com/apache/skywalking-cli/internal/flags" + "github.com/apache/skywalking-cli/internal/model" + "github.com/apache/skywalking-cli/pkg/display" + "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/alarm" + + api "skywalking.apache.org/repo/goapi/query" +) + +var autocompleteKeysCommand = &cli.Command{ + Name: "autocomplete-keys", + Aliases: []string{"ks"}, + Usage: "Query autocomplete Keys", + UsageText: `Query autocomplete keys + +Examples: +1. Query autocomplete keys: +$ swctl alarm autocomplete-keys +`, + Flags: flags.Flags( + flags.DurationFlags, + ), + Before: interceptor.BeforeChain( + interceptor.DurationInterceptor, + ), + Action: func(ctx *cli.Context) error { + start := ctx.String("start") + end := ctx.String("end") + step := ctx.Generic("step") + + duration := api.Duration{ + Start: start, + End: end, + Step: step.(*model.StepEnumValue).Selected, + } + + autocompleteKeys, err := alarm.TagAutocompleteKeys(ctx, duration) + if err != nil { + return err + } + + return display.Display(ctx, &displayable.Displayable{Data: autocompleteKeys, Condition: duration}) + }, +} diff --git a/internal/commands/alarm/autopleteValues.go b/internal/commands/alarm/autopleteValues.go new file mode 100644 index 0000000..8876e41 --- /dev/null +++ b/internal/commands/alarm/autopleteValues.go @@ -0,0 +1,76 @@ +// 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 alarm + +import ( + "github.com/urfave/cli/v2" + + "github.com/apache/skywalking-cli/internal/commands/interceptor" + "github.com/apache/skywalking-cli/internal/flags" + "github.com/apache/skywalking-cli/internal/model" + "github.com/apache/skywalking-cli/pkg/display" + "github.com/apache/skywalking-cli/pkg/display/displayable" + "github.com/apache/skywalking-cli/pkg/graphql/alarm" + + api "skywalking.apache.org/repo/goapi/query" +) + +var autocompleteValuesCommand = &cli.Command{ + Name: "autocomplete-values", + Aliases: []string{"vs"}, + Usage: "Query autocomplete Values", + UsageText: `Query autocomplete values + +Examples: +1. Query autocomplete values: +$ swctl alarm autocomplete-values --key=tagKey +`, + Flags: flags.Flags( + flags.DurationFlags, + []cli.Flag{ + &cli.StringFlag{ + Name: "key", + Usage: "autocomplete tag key", + Required: true, + }, + }, + ), + Before: interceptor.BeforeChain( + interceptor.DurationInterceptor, + ), + Action: func(ctx *cli.Context) error { + start := ctx.String("start") + end := ctx.String("end") + step := ctx.Generic("step") + + tagKey := ctx.String("key") + + duration := api.Duration{ + Start: start, + End: end, + Step: step.(*model.StepEnumValue).Selected, + } + + autocompleteValues, err := alarm.TagAutocompleteValues(ctx, duration, tagKey) + if err != nil { + return err + } + + return display.Display(ctx, &displayable.Displayable{Data: autocompleteValues, Condition: tagKey}) + }, +} diff --git a/pkg/graphql/alarm/alarm.go b/pkg/graphql/alarm/alarm.go index 3ac6def..87d6ad3 100644 --- a/pkg/graphql/alarm/alarm.go +++ b/pkg/graphql/alarm/alarm.go @@ -52,3 +52,26 @@ func Alarms(ctx *cli.Context, condition *ListAlarmCondition) (api.Alarms, error) return response["result"], err } + +func TagAutocompleteKeys(ctx *cli.Context, duration api.Duration) ([]string, error) { + var response map[string][]string + + request := graphql.NewRequest(assets.Read("graphqls/alarm/tagAutocompleteKeys.graphql")) + request.Var("duration", duration) + + err := client.ExecuteQuery(ctx, request, &response) + + return response["result"], err +} + +func TagAutocompleteValues(ctx *cli.Context, duration api.Duration, key string) ([]string, error) { + var response map[string][]string + + request := graphql.NewRequest(assets.Read("graphqls/alarm/tagAutocompleteValues.graphql")) + request.Var("duration", duration) + request.Var("tagKey", key) + + err := client.ExecuteQuery(ctx, request, &response) + + return response["result"], err +}
