Skip to content

Commit

Permalink
Add isEmptyValue field in metrics related commands (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Mar 29, 2023
1 parent f3eed66 commit 23debb3
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/command-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
matrix:
oap:
- e5950cc06279a83c64089f94613b06ec0ef0d911
- 6fa89c79917cb10dbf48591c46abee3b513a2bab
steps:
- uses: actions/checkout@v2
- name: Check for go file changes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
if: steps.changes.outputs.src == 'true'
uses: golangci/golangci-lint-action@v3
with:
version: latest
version: v1.50.0
args: --timeout 5m
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Release Notes.
* Add components in topology related sub-commands. @mrproliu in https://github.com/apache/skywalking-cli/pull/175
* Add the sub-command `metrics nullable` for query the nullable metrics value. @mrproliu in https://github.com/apache/skywalking-cli/pull/176
* Adapt the sub-command `profiling trace` for adapt the new trace profiling protocol. @mrproliu in https://github.com/apache/skywalking-cli/pull/177
* Add `isEmptyValue` field in metrics related sub-commands. @mrproliu in https://github.com/apache/skywalking-cli/pull/180

0.10.0
------------------
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ deps:
@$(GO_GET) -v -t -d ./...

$(GO_LINT):
@$(GO_LINT) version > /dev/null 2>&1 || go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@$(GO_LINT) version > /dev/null 2>&1 || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin v1.50.0
$(LICENSE_EYE):
@$(LICENSE_EYE) --version > /dev/null 2>&1 || go install github.com/apache/skywalking-eyes/cmd/license-eye@d38fe05

Expand Down
1 change: 1 addition & 0 deletions assets/graphqls/metrics/LabeledMetricsValues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ query ($condition: MetricsCondition!, $labels: [String!]!, $duration: Duration!)
values {
values {
value
isEmptyValue
}
}
}
Expand Down
1 change: 1 addition & 0 deletions assets/graphqls/metrics/MetricsValues.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ query ($condition: MetricsCondition!, $duration: Duration!) {
values {
values {
value
isEmptyValue
}
}
}
Expand Down
1 change: 1 addition & 0 deletions assets/graphqls/metrics/NullableMetricsValue.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
query ($condition: MetricsCondition!, $duration: Duration!) {
result: readNullableMetricsValue(condition: $condition, duration: $duration) {
value
isEmptyValue
}
}
2 changes: 1 addition & 1 deletion internal/commands/metrics/single/nullable-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ $ swctl metrics nullable --name endpoint_cpm --service-name business-zone::proje
return err
}

return display.Display(ctx, &displayable.Displayable{Data: metricsValue.Value})
return display.Display(ctx, &displayable.Displayable{Data: metricsValue})
},
}
23 changes: 23 additions & 0 deletions pkg/display/displayable/MetricValue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 displayable

type MetricValue struct {
Value float64
IsEmptyValue bool
}
2 changes: 1 addition & 1 deletion pkg/display/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

type (
Thermodynamic = api.HeatMap
LinearMetrics = map[string]float64
LinearMetrics = map[string]*d.MetricValue
MultiLinearMetrics = map[string]LinearMetrics
Trace = api.Trace
TraceBrief = api.TraceBrief
Expand Down
12 changes: 7 additions & 5 deletions pkg/display/graph/linear/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sort"
"strings"

"github.com/apache/skywalking-cli/pkg/display/displayable"

"github.com/mum4k/termdash"
"github.com/mum4k/termdash/container"
"github.com/mum4k/termdash/container/grid"
Expand All @@ -39,7 +41,7 @@ const RootID = "root"

const defaultSeriesLabel = "linear"

func NewLineChart(inputs map[string]float64) (lineChart *linechart.LineChart, err error) {
func NewLineChart(inputs map[string]*displayable.MetricValue) (lineChart *linechart.LineChart, err error) {
if lineChart, err = linechart.New(linechart.YAxisAdaptive()); err != nil {
return
}
Expand All @@ -49,13 +51,13 @@ func NewLineChart(inputs map[string]float64) (lineChart *linechart.LineChart, er
return lineChart, err
}

func SetLineChartSeries(lc *linechart.LineChart, inputs map[string]float64) error {
func SetLineChartSeries(lc *linechart.LineChart, inputs map[string]*displayable.MetricValue) error {
xLabels, yValues := processInputs(inputs)
return lc.Series(defaultSeriesLabel, yValues, linechart.SeriesXLabels(xLabels))
}

// processInputs converts inputs into xLabels and yValues for line charts.
func processInputs(inputs map[string]float64) (xLabels map[int]string, yValues []float64) {
func processInputs(inputs map[string]*displayable.MetricValue) (xLabels map[int]string, yValues []float64) {
index := 0

xLabels = map[int]string{}
Expand All @@ -70,7 +72,7 @@ func processInputs(inputs map[string]float64) (xLabels map[int]string, yValues [

for _, name := range names {
xLabels[index] = name
yValues[index] = inputs[name]
yValues[index] = inputs[name].Value
index++
}
return
Expand Down Expand Up @@ -131,7 +133,7 @@ func layout(rows [][]grid.Element) ([]container.Option, error) {
return builder.Build()
}

func Display(cliCtx *cli.Context, inputs map[string]map[string]float64) error {
func Display(cliCtx *cli.Context, inputs map[string]map[string]*displayable.MetricValue) error {
t, err := termbox.New()
if err != nil {
return err
Expand Down
12 changes: 7 additions & 5 deletions pkg/graphql/dashboard/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"sync"

"github.com/apache/skywalking-cli/pkg/display/displayable"

"golang.org/x/text/cases"
"golang.org/x/text/language"
api "skywalking.apache.org/repo/goapi/query"
Expand Down Expand Up @@ -67,9 +69,9 @@ type GlobalTemplate struct {
}

type GlobalData struct {
Metrics [][]*api.SelectedRecord `json:"metrics"`
ResponseLatency map[string]map[string]float64 `json:"responseLatency"`
HeatMap api.HeatMap `json:"heatMap"`
Metrics [][]*api.SelectedRecord `json:"metrics"`
ResponseLatency map[string]map[string]*displayable.MetricValue `json:"responseLatency"`
HeatMap api.HeatMap `json:"heatMap"`
}

// Use singleton pattern to make sure to load template only once.
Expand Down Expand Up @@ -166,7 +168,7 @@ func Metrics(ctx *cli.Context, duration api.Duration) ([][]*api.SelectedRecord,
return ret, nil
}

func responseLatency(ctx *cli.Context, duration api.Duration) map[string]map[string]float64 {
func responseLatency(ctx *cli.Context, duration api.Duration) map[string]map[string]*displayable.MetricValue {
template, err := LoadTemplate(ctx.String("template"))
if err != nil {
return nil
Expand Down Expand Up @@ -232,7 +234,7 @@ func Global(ctx *cli.Context, duration api.Duration) (*GlobalData, error) {
}
wg.Done()
}()
var rl map[string]map[string]float64
var rl map[string]map[string]*displayable.MetricValue
go func() {
rl = responseLatency(ctx, duration)
wg.Done()
Expand Down
16 changes: 11 additions & 5 deletions pkg/graphql/utils/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ package utils
import (
"time"

"github.com/apache/skywalking-cli/pkg/display/displayable"

api "skywalking.apache.org/repo/goapi/query"

"github.com/apache/skywalking-cli/internal/logger"
)

// MetricsValuesArrayToMap converts Array of MetricsValues into a map that uses time as key.
func MetricsValuesArrayToMap(duration api.Duration, mvArray []api.MetricsValues, labelsMap map[string]string) map[string]map[string]float64 {
ret := make(map[string]map[string]float64, len(mvArray))
func MetricsValuesArrayToMap(duration api.Duration, mvArray []api.MetricsValues,
labelsMap map[string]string) map[string]map[string]*displayable.MetricValue {
ret := make(map[string]map[string]*displayable.MetricValue, len(mvArray))
for _, mvs := range mvArray {
label := *mvs.Label
if l, ok := labelsMap[label]; ok {
Expand All @@ -39,9 +42,9 @@ func MetricsValuesArrayToMap(duration api.Duration, mvArray []api.MetricsValues,
}

// MetricsValuesToMap converts MetricsValues into a map that uses time as key.
func MetricsValuesToMap(duration api.Duration, metricsValues api.MetricsValues) map[string]float64 {
func MetricsValuesToMap(duration api.Duration, metricsValues api.MetricsValues) map[string]*displayable.MetricValue {
kvInts := metricsValues.Values.Values
ret := map[string]float64{}
ret := map[string]*displayable.MetricValue{}
format := StepFormats[duration.Step]
startTime, err := time.Parse(format, duration.Start)

Expand All @@ -51,7 +54,10 @@ func MetricsValuesToMap(duration api.Duration, metricsValues api.MetricsValues)

step := StepDuration[duration.Step]
for idx, value := range kvInts {
ret[startTime.Add(time.Duration(idx)*step).Format(format)] = float64(value.Value)
ret[startTime.Add(time.Duration(idx)*step).Format(format)] = &displayable.MetricValue{
Value: float64(value.Value),
IsEmptyValue: value.IsEmptyValue,
}
}

return ret
Expand Down
22 changes: 12 additions & 10 deletions pkg/graphql/utils/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"reflect"
"testing"

"github.com/apache/skywalking-cli/pkg/display/displayable"

api "skywalking.apache.org/repo/goapi/query"
)

Expand All @@ -32,7 +34,7 @@ func TestMetricsToMap(t *testing.T) {
tests := []struct {
name string
args args
want map[string]float64
want map[string]*displayable.MetricValue
}{
{
name: "Should convert to map",
Expand All @@ -57,15 +59,15 @@ func TestMetricsToMap(t *testing.T) {
},
},
},
want: map[string]float64{
"2020-01-01 0000": 0,
"2020-01-01 0001": 1,
"2020-01-01 0002": 2,
"2020-01-01 0003": 3,
"2020-01-01 0004": 4,
"2020-01-01 0005": 5,
"2020-01-01 0006": 6,
"2020-01-01 0007": 7,
want: map[string]*displayable.MetricValue{
"2020-01-01 0000": {Value: 0, IsEmptyValue: false},
"2020-01-01 0001": {Value: 1, IsEmptyValue: false},
"2020-01-01 0002": {Value: 2, IsEmptyValue: false},
"2020-01-01 0003": {Value: 3, IsEmptyValue: false},
"2020-01-01 0004": {Value: 4, IsEmptyValue: false},
"2020-01-01 0005": {Value: 5, IsEmptyValue: false},
"2020-01-01 0006": {Value: 6, IsEmptyValue: false},
"2020-01-01 0007": {Value: 7, IsEmptyValue: false},
},
},
}
Expand Down
8 changes: 3 additions & 5 deletions test/cases/basic/expected/dependency-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nodes:
{{- contains .nodes }}
- id: {{ b64enc "provider" }}.1_{{ b64enc "provider1" }}
name: provider1
type: Python
type: ""
isreal: true
serviceid: {{ b64enc "provider" }}.1
servicename: provider
Expand All @@ -31,11 +31,9 @@ nodes:
calls:
{{- contains .calls }}
- source: {{ b64enc "consumer" }}.1_{{ b64enc "consumer1" }}
sourcecomponents:
- Python
sourcecomponents: []
target: {{ b64enc "provider" }}.1_{{ b64enc "provider1" }}
targetcomponents:
- Python
targetcomponents: []
id: {{ b64enc "consumer" }}.1_{{ b64enc "consumer1" }}-{{ b64enc "provider" }}.1_{{ b64enc "provider1" }}
detectpoints:
{{- contains .detectpoints }}
Expand Down
16 changes: 10 additions & 6 deletions test/cases/basic/expected/layer-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@
# limitations under the License.

- BROWSER
- MESH
- GENERAL
- FAAS
- MESH_CP
- SO11Y_SATELLITE
- K8S_SERVICE
- VIRTUAL_GATEWAY
- AWS_EKS
- MQ
- MYSQL
- VIRTUAL_DATABASE
- K8S
- VIRTUAL_MQ
- MESH
- GENERAL
- CACHE
- FAAS
- MESH_CP
- OS_WINDOWS
- MESH_DP
- SO11Y_OAP
- DATABASE
- OS_LINUX
- SO11Y_SATELLITE
- K8S_SERVICE
- APISIX
- VIRTUAL_CACHE
- POSTGRESQL
- AWS_S3
- AWS_DYNAMODB
4 changes: 3 additions & 1 deletion test/cases/basic/expected/metrics-has-value.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@

{{- contains . }}
- key: {{ notEmpty .key }}
value: {{ ge .value 1 }}
value:
value: {{ ge .value.value 1 }}
isemptyvalue: false
{{- end }}

0 comments on commit 23debb3

Please sign in to comment.