diff --git a/.golangci.toml b/.golangci.toml index 9dd31bd6a2d..470330212f3 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -21,6 +21,7 @@ packages = ["io/ioutil"] "io/ioutil" = "Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details." "gopkg.in/yaml.v2" = "Grafana packages are not allowed to depend on gopkg.in/yaml.v2 as gopkg.in/yaml.v3 is now available" "github.com/pkg/errors" = "Deprecated: Go 1.13 supports the functionality provided by pkg/errors in the standard library." +"github.com/xorcare/pointer" = "Use pkg/util.Pointer instead, which is a generic one-liner alternative" [linters-settings.gocritic] enabled-checks = ["ruleguard"] diff --git a/go.mod b/go.mod index 68fe21585a6..68183fa343c 100644 --- a/go.mod +++ b/go.mod @@ -105,7 +105,6 @@ require ( github.com/uber/jaeger-client-go v2.29.1+incompatible github.com/urfave/cli/v2 v2.3.0 github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae - github.com/xorcare/pointer v1.1.0 github.com/yalue/merged_fs v1.2.2 github.com/yudai/gojsondiff v1.0.0 go.opentelemetry.io/collector v0.31.0 diff --git a/go.sum b/go.sum index 7882251a8e7..4208219cc02 100644 --- a/go.sum +++ b/go.sum @@ -2297,8 +2297,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk= github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= -github.com/xorcare/pointer v1.1.0 h1:sFwXOhRF8QZ0tyVZrtxWGIoVZNEmRzBCaFWdONPQIUM= -github.com/xorcare/pointer v1.1.0/go.mod h1:6KLhkOh6YbuvZkT4YbxIbR/wzLBjyMxOiNzZhJTor2Y= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yalue/merged_fs v1.2.2 h1:vXHTpJBluJryju7BBpytr3PDIkzsPMpiEknxVGPhN/I= github.com/yalue/merged_fs v1.2.2/go.mod h1:WqqchfVYQyclV2tnR7wtRhBddzBvLVR83Cjw9BKQw0M= diff --git a/pkg/expr/classic/classic_test.go b/pkg/expr/classic/classic_test.go index 31ccdbe1425..e907c437f04 100644 --- a/pkg/expr/classic/classic_test.go +++ b/pkg/expr/classic/classic_test.go @@ -8,9 +8,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr/mathexp" + "github.com/grafana/grafana/pkg/util" ) func TestConditionsCmd(t *testing.T) { @@ -26,7 +26,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -40,7 +40,7 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(0)) + v := newNumber(util.Pointer(0.0)) v.SetMeta([]EvalMatch{}) return newResults(v) }, @@ -51,7 +51,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -65,8 +65,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(3)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(3.0)}}) return newResults(v) }, }, { @@ -74,7 +74,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -89,7 +89,7 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(0)) + v := newNumber(util.Pointer(0.0)) v.SetMeta([]EvalMatch{}) return newResults(v) }, @@ -98,7 +98,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -113,8 +113,8 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(4)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(4.0)}}) return newResults(v) }, }, { @@ -203,7 +203,7 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) + v := newNumber(util.Pointer(1.0)) v.SetMeta([]EvalMatch{{Value: nil}}) return newResults(v) }, @@ -225,7 +225,7 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) + v := newNumber(util.Pointer(1.0)) v.SetMeta([]EvalMatch{{Value: nil}}) return newResults(v) }, @@ -249,7 +249,7 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) + v := newNumber(util.Pointer(1.0)) v.SetMeta([]EvalMatch{{Value: nil}}) return newResults(v) }, @@ -261,7 +261,7 @@ func TestConditionsCmd(t *testing.T) { "A": mathexp.Results{ Values: []mathexp.Value{ newSeries(), - newSeries(ptr.Float64(2)), + newSeries(util.Pointer(2.0)), }, }, }, @@ -275,8 +275,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(2)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(2.0)}}) return newResults(v) }, }, { @@ -284,8 +284,8 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), - newSeries(ptr.Float64(2), ptr.Float64(10)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), + newSeries(util.Pointer(2.0), util.Pointer(10.0)), }, }, }, @@ -299,7 +299,7 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(0)) + v := newNumber(util.Pointer(0.0)) v.SetMeta([]EvalMatch{}) return mathexp.Results{Values: mathexp.Values{v}} }, @@ -308,8 +308,8 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), - newSeriesWithLabels(data.Labels{"foo": "bar"}, ptr.Float64(2), ptr.Float64(10)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), + newSeriesWithLabels(data.Labels{"foo": "bar"}, util.Pointer(2.0), util.Pointer(10.0)), }, }, }, @@ -323,8 +323,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(2), Labels: data.Labels{"foo": "bar"}}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(2.0), Labels: data.Labels{"foo": "bar"}}}) return newResults(v) }, }, { @@ -332,8 +332,8 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), - newSeriesWithLabels(data.Labels{"foo": "bar"}, ptr.Float64(2), ptr.Float64(10)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), + newSeriesWithLabels(data.Labels{"foo": "bar"}, util.Pointer(2.0), util.Pointer(10.0)), }, }, }, @@ -347,11 +347,11 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) + v := newNumber(util.Pointer(1.0)) v.SetMeta([]EvalMatch{{ - Value: ptr.Float64(1), + Value: util.Pointer(1.0), }, { - Value: ptr.Float64(2), + Value: util.Pointer(2.0), Labels: data.Labels{"foo": "bar"}, }}) return newResults(v) @@ -361,7 +361,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -380,8 +380,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(5.0)}}) return newResults(v) }, }, { @@ -389,7 +389,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -408,8 +408,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(1)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(1.0)}}) return newResults(v) }, }, { @@ -417,7 +417,7 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newSeries(ptr.Float64(1), ptr.Float64(5)), + newSeries(util.Pointer(1.0), util.Pointer(5.0)), }, }, }, @@ -436,8 +436,8 @@ func TestConditionsCmd(t *testing.T) { }, }}, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Value: ptr.Float64(1)}}) + v := newNumber(util.Pointer(1.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(5.0)}, {Value: util.Pointer(1.0)}}) return newResults(v) }, }, { @@ -445,9 +445,9 @@ func TestConditionsCmd(t *testing.T) { vars: mathexp.Vars{ "A": mathexp.Results{ Values: []mathexp.Value{ - newNumber(ptr.Float64(5)), - newNumber(ptr.Float64(10)), - newNumber(ptr.Float64(15)), + newNumber(util.Pointer(5.0)), + newNumber(util.Pointer(10.0)), + newNumber(util.Pointer(15.0)), }, }, }, @@ -462,11 +462,11 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(1)) + v := newNumber(util.Pointer(1.0)) v.SetMeta([]EvalMatch{ - {Value: ptr.Float64(5)}, - {Value: ptr.Float64(10)}, - {Value: ptr.Float64(15)}, + {Value: util.Pointer(5.0)}, + {Value: util.Pointer(10.0)}, + {Value: util.Pointer(15.0)}, }) return newResults(v) }, @@ -477,7 +477,7 @@ func TestConditionsCmd(t *testing.T) { Values: []mathexp.Value{mathexp.NoData{}.New()}, }, "B": mathexp.Results{ - Values: []mathexp.Value{newSeries(ptr.Float64(5))}, + Values: []mathexp.Value{newSeries(util.Pointer(5.0))}, }, }, cmd: &ConditionsCmd{ @@ -497,15 +497,15 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(0)) - v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}}) + v := newNumber(util.Pointer(0.0)) + v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: util.Pointer(5.0)}}) return newResults(v) }, }, { name: "two queries with two conditions using and operator and last is No Data", vars: mathexp.Vars{ "A": mathexp.Results{ - Values: []mathexp.Value{newSeries(ptr.Float64(5))}, + Values: []mathexp.Value{newSeries(util.Pointer(5.0))}, }, "B": mathexp.Results{ Values: []mathexp.Value{mathexp.NoData{}.New()}, @@ -528,8 +528,8 @@ func TestConditionsCmd(t *testing.T) { }, }, expected: func() mathexp.Results { - v := newNumber(ptr.Float64(0)) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}}) + v := newNumber(util.Pointer(0.0)) + v.SetMeta([]EvalMatch{{Value: util.Pointer(5.0)}, {Metric: "NoData"}}) return newResults(v) }, }, { @@ -539,7 +539,7 @@ func TestConditionsCmd(t *testing.T) { Values: []mathexp.Value{mathexp.NoData{}.New()}, }, "B": mathexp.Results{ - Values: []mathexp.Value{newSeries(ptr.Float64(5))}, + Values: []mathexp.Value{newSeries(util.Pointer(5.0))}, }, }, cmd: &ConditionsCmd{ @@ -560,14 +560,14 @@ func TestConditionsCmd(t *testing.T) { }, expected: func() mathexp.Results { v := newNumber(nil) - v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: ptr.Float64(5)}}) + v.SetMeta([]EvalMatch{{Metric: "NoData"}, {Value: util.Pointer(5.0)}}) return newResults(v) }, }, { name: "two queries with two conditions using or operator and last is No Data", vars: mathexp.Vars{ "A": mathexp.Results{ - Values: []mathexp.Value{newSeries(ptr.Float64(5))}, + Values: []mathexp.Value{newSeries(util.Pointer(5.0))}, }, "B": mathexp.Results{ Values: []mathexp.Value{mathexp.NoData{}.New()}, @@ -591,7 +591,7 @@ func TestConditionsCmd(t *testing.T) { }, expected: func() mathexp.Results { v := newNumber(nil) - v.SetMeta([]EvalMatch{{Value: ptr.Float64(5)}, {Metric: "NoData"}}) + v.SetMeta([]EvalMatch{{Value: util.Pointer(5.0)}, {Metric: "NoData"}}) return newResults(v) }, }} diff --git a/pkg/expr/classic/evaluator_test.go b/pkg/expr/classic/evaluator_test.go index 6cad30ff646..92aa7ad2a40 100644 --- a/pkg/expr/classic/evaluator_test.go +++ b/pkg/expr/classic/evaluator_test.go @@ -4,9 +4,9 @@ import ( "testing" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr/mathexp" + "github.com/grafana/grafana/pkg/util" ) func TestThresholdEvaluator(t *testing.T) { @@ -19,25 +19,25 @@ func TestThresholdEvaluator(t *testing.T) { { name: "value 3 is gt 1: true", evaluator: &thresholdEvaluator{"gt", 1}, - inputNumber: newNumber(ptr.Float64(3)), + inputNumber: newNumber(util.Pointer(3.0)), expected: true, }, { name: "value 1 is gt 3: false", evaluator: &thresholdEvaluator{"gt", 3}, - inputNumber: newNumber(ptr.Float64(1)), + inputNumber: newNumber(util.Pointer(1.0)), expected: false, }, { name: "value 3 is lt 1: true", evaluator: &thresholdEvaluator{"lt", 1}, - inputNumber: newNumber(ptr.Float64(3)), + inputNumber: newNumber(util.Pointer(3.0)), expected: false, }, { name: "value 1 is lt 3: false", evaluator: &thresholdEvaluator{"lt", 3}, - inputNumber: newNumber(ptr.Float64(1)), + inputNumber: newNumber(util.Pointer(1.0)), expected: true, }, } @@ -60,50 +60,50 @@ func TestRangedEvaluator(t *testing.T) { { name: "value 3 is within range 1, 100: true", evaluator: &rangedEvaluator{"within_range", 1, 100}, - inputNumber: newNumber(ptr.Float64(3)), + inputNumber: newNumber(util.Pointer(3.0)), expected: true, }, { name: "value 300 is within range 1, 100: false", evaluator: &rangedEvaluator{"within_range", 1, 100}, - inputNumber: newNumber(ptr.Float64(300)), + inputNumber: newNumber(util.Pointer(300.0)), expected: false, }, { name: "value 3 is within range 100, 1: true", evaluator: &rangedEvaluator{"within_range", 100, 1}, - inputNumber: newNumber(ptr.Float64(3)), + inputNumber: newNumber(util.Pointer(3.0)), expected: true, }, { name: "value 300 is within range 100, 1: false", evaluator: &rangedEvaluator{"within_range", 100, 1}, - inputNumber: newNumber(ptr.Float64(300)), + inputNumber: newNumber(util.Pointer(300.0)), expected: false, }, // outside { name: "value 1000 is outside range 1, 100: true", evaluator: &rangedEvaluator{"outside_range", 1, 100}, - inputNumber: newNumber(ptr.Float64(1000)), + inputNumber: newNumber(util.Pointer(1000.0)), expected: true, }, { name: "value 50 is outside range 1, 100: false", evaluator: &rangedEvaluator{"outside_range", 1, 100}, - inputNumber: newNumber(ptr.Float64(50)), + inputNumber: newNumber(util.Pointer(50.0)), expected: false, }, { name: "value 1000 is outside range 100, 1: true", evaluator: &rangedEvaluator{"outside_range", 100, 1}, - inputNumber: newNumber(ptr.Float64(1000)), + inputNumber: newNumber(util.Pointer(1000.0)), expected: true, }, { name: "value 50 is outside range 100, 1: false", evaluator: &rangedEvaluator{"outside_range", 100, 1}, - inputNumber: newNumber(ptr.Float64(50)), + inputNumber: newNumber(util.Pointer(50.0)), expected: false, }, } @@ -125,7 +125,7 @@ func TestNoValueEvaluator(t *testing.T) { { name: "value 50 is no_value: false", evaluator: &noValueEvaluator{}, - inputNumber: newNumber(ptr.Float64(50)), + inputNumber: newNumber(util.Pointer(50.0)), expected: false, }, { diff --git a/pkg/expr/classic/reduce_test.go b/pkg/expr/classic/reduce_test.go index f46798449ed..7725dcf68f8 100644 --- a/pkg/expr/classic/reduce_test.go +++ b/pkg/expr/classic/reduce_test.go @@ -7,9 +7,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr/mathexp" + "github.com/grafana/grafana/pkg/util" ) func TestReducer(t *testing.T) { @@ -22,68 +22,68 @@ func TestReducer(t *testing.T) { { name: "sum", reducer: reducer("sum"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3)), - expectedNumber: newNumber(ptr.Float64(6)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3.0)), + expectedNumber: newNumber(util.Pointer(6.0)), }, { name: "min", reducer: reducer("min"), - inputSeries: newSeries(ptr.Float64(3), ptr.Float64(2), ptr.Float64(1)), - expectedNumber: newNumber(ptr.Float64(1)), + inputSeries: newSeries(util.Pointer(3.0), util.Pointer(2.0), util.Pointer(1.0)), + expectedNumber: newNumber(util.Pointer(1.0)), }, { name: "min with NaNs only", reducer: reducer("min"), - inputSeries: newSeries(ptr.Float64(math.NaN()), ptr.Float64(math.NaN()), ptr.Float64(math.NaN())), + inputSeries: newSeries(util.Pointer(math.NaN()), util.Pointer(math.NaN()), util.Pointer(math.NaN())), expectedNumber: newNumber(nil), }, { name: "max", reducer: reducer("max"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3)), - expectedNumber: newNumber(ptr.Float64(3)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3.0)), + expectedNumber: newNumber(util.Pointer(3.0)), }, { name: "count", reducer: reducer("count"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3000)), - expectedNumber: newNumber(ptr.Float64(3)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3000.0)), + expectedNumber: newNumber(util.Pointer(3.0)), }, { name: "last", reducer: reducer("last"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3000)), - expectedNumber: newNumber(ptr.Float64(3000)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3000.0)), + expectedNumber: newNumber(util.Pointer(3000.0)), }, { name: "median with odd amount of numbers", reducer: reducer("median"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3000)), - expectedNumber: newNumber(ptr.Float64(2)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3000.0)), + expectedNumber: newNumber(util.Pointer(2.0)), }, { name: "median with even amount of numbers", reducer: reducer("median"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(4), ptr.Float64(3000)), - expectedNumber: newNumber(ptr.Float64(3)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(4.0), util.Pointer(3000.0)), + expectedNumber: newNumber(util.Pointer(3.0)), }, { name: "median with one value", reducer: reducer("median"), - inputSeries: newSeries(ptr.Float64(1)), - expectedNumber: newNumber(ptr.Float64(1)), + inputSeries: newSeries(util.Pointer(1.0)), + expectedNumber: newNumber(util.Pointer(1.0)), }, { name: "median should ignore null values", reducer: reducer("median"), - inputSeries: newSeries(nil, nil, nil, ptr.Float64(1), ptr.Float64(2), ptr.Float64(3)), - expectedNumber: newNumber(ptr.Float64(2)), + inputSeries: newSeries(nil, nil, nil, util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3.0)), + expectedNumber: newNumber(util.Pointer(2.0)), }, { name: "avg", reducer: reducer("avg"), - inputSeries: newSeries(ptr.Float64(1), ptr.Float64(2), ptr.Float64(3)), - expectedNumber: newNumber(ptr.Float64(2)), + inputSeries: newSeries(util.Pointer(1.0), util.Pointer(2.0), util.Pointer(3.0)), + expectedNumber: newNumber(util.Pointer(2.0)), }, { name: "avg with only nulls", @@ -94,20 +94,20 @@ func TestReducer(t *testing.T) { { name: "avg of number values and null values should ignore nulls", reducer: reducer("avg"), - inputSeries: newSeries(ptr.Float64(3), nil, nil, ptr.Float64(3)), - expectedNumber: newNumber(ptr.Float64(3)), + inputSeries: newSeries(util.Pointer(3.0), nil, nil, util.Pointer(3.0)), + expectedNumber: newNumber(util.Pointer(3.0)), }, { name: "count_non_null with mixed null/real values", reducer: reducer("count_non_null"), - inputSeries: newSeries(nil, nil, ptr.Float64(3), ptr.Float64(4)), - expectedNumber: newNumber(ptr.Float64(2)), + inputSeries: newSeries(nil, nil, util.Pointer(3.0), util.Pointer(4.0)), + expectedNumber: newNumber(util.Pointer(2.0)), }, { name: "count_non_null with mixed null/real values", reducer: reducer("count_non_null"), - inputSeries: newSeries(nil, nil, ptr.Float64(3), ptr.Float64(4)), - expectedNumber: newNumber(ptr.Float64(2)), + inputSeries: newSeries(nil, nil, util.Pointer(3.0), util.Pointer(4.0)), + expectedNumber: newNumber(util.Pointer(2.0)), }, { name: "count_non_null with no values", @@ -134,53 +134,53 @@ func TestDiffReducer(t *testing.T) { }{ { name: "diff of one positive point", - inputSeries: newSeries(ptr.Float64(30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "diff of one negative point", - inputSeries: newSeries(ptr.Float64(-30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(-30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "diff two positive points [1]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(10)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(10.0)), }, { name: "diff two positive points [2]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(20)), - expectedNumber: newNumber(ptr.Float64(-10)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(20.0)), + expectedNumber: newNumber(util.Pointer(-10.0)), }, { name: "diff two negative points [1]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(-10)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(-10.0)), }, { name: "diff two negative points [2]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-10)), - expectedNumber: newNumber(ptr.Float64(20)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-10.0)), + expectedNumber: newNumber(util.Pointer(20.0)), }, { name: "diff of one positive and one negative point", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(-70)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(-70.0)), }, { name: "diff of one negative and one positive point", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(70)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(70.0)), }, { name: "diff of three positive points", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40), ptr.Float64(50)), - expectedNumber: newNumber(ptr.Float64(20)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0), util.Pointer(50.0)), + expectedNumber: newNumber(util.Pointer(20.0)), }, { name: "diff of three negative points", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40), ptr.Float64(-50)), - expectedNumber: newNumber(ptr.Float64(-20)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0), util.Pointer(-50.0)), + expectedNumber: newNumber(util.Pointer(-20.0)), }, { name: "diff with only nulls", @@ -204,53 +204,53 @@ func TestDiffAbsReducer(t *testing.T) { }{ { name: "diff_abs of one positive point", - inputSeries: newSeries(ptr.Float64(30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "diff_abs of one negative point", - inputSeries: newSeries(ptr.Float64(-30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(-30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "diff_abs two positive points [1]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(10)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(10.0)), }, { name: "diff_abs two positive points [2]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(20)), - expectedNumber: newNumber(ptr.Float64(10)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(20.0)), + expectedNumber: newNumber(util.Pointer(10.0)), }, { name: "diff_abs two negative points [1]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(10)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(10.0)), }, { name: "diff_abs two negative points [2]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-10)), - expectedNumber: newNumber(ptr.Float64(20)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-10.0)), + expectedNumber: newNumber(util.Pointer(20.0)), }, { name: "diff_abs of one positive and one negative point", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(70)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(70.0)), }, { name: "diff_abs of one negative and one positive point", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(70)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(70.0)), }, { name: "diff_abs of three positive points", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40), ptr.Float64(50)), - expectedNumber: newNumber(ptr.Float64(20)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0), util.Pointer(50.0)), + expectedNumber: newNumber(util.Pointer(20.0)), }, { name: "diff_abs of three negative points", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40), ptr.Float64(-50)), - expectedNumber: newNumber(ptr.Float64(20)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0), util.Pointer(-50.0)), + expectedNumber: newNumber(util.Pointer(20.0)), }, { name: "diff_abs with only nulls", @@ -274,53 +274,53 @@ func TestPercentDiffReducer(t *testing.T) { }{ { name: "percent_diff of one positive point", - inputSeries: newSeries(ptr.Float64(30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "percent_diff of one negative point", - inputSeries: newSeries(ptr.Float64(-30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(-30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "percent_diff two positive points [1]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(33.33333333333333)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(33.33333333333333)), }, { name: "percent_diff two positive points [2]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(20)), - expectedNumber: newNumber(ptr.Float64(-33.33333333333333)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(20.0)), + expectedNumber: newNumber(util.Pointer(-33.33333333333333)), }, { name: "percent_diff two negative points [1]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(-33.33333333333333)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(-33.33333333333333)), }, { name: "percent_diff two negative points [2]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-10)), - expectedNumber: newNumber(ptr.Float64(66.66666666666666)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-10.0)), + expectedNumber: newNumber(util.Pointer(66.66666666666666)), }, { name: "percent_diff of one positive and one negative point", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(-233.33333333333334)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(-233.33333333333334)), }, { name: "percent_diff of one negative and one positive point", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(233.33333333333334)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(233.33333333333334)), }, { name: "percent_diff of three positive points", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40), ptr.Float64(50)), - expectedNumber: newNumber(ptr.Float64(66.66666666666666)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0), util.Pointer(50.0)), + expectedNumber: newNumber(util.Pointer(66.66666666666666)), }, { name: "percent_diff of three negative points", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40), ptr.Float64(-50)), - expectedNumber: newNumber(ptr.Float64(-66.66666666666666)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0), util.Pointer(-50.0)), + expectedNumber: newNumber(util.Pointer(-66.66666666666666)), }, { name: "percent_diff with only nulls", @@ -344,53 +344,53 @@ func TestPercentDiffAbsReducer(t *testing.T) { }{ { name: "percent_diff_abs of one positive point", - inputSeries: newSeries(ptr.Float64(30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "percent_diff_abs of one negative point", - inputSeries: newSeries(ptr.Float64(-30)), - expectedNumber: newNumber(ptr.Float64(0)), + inputSeries: newSeries(util.Pointer(-30.0)), + expectedNumber: newNumber(util.Pointer(0.0)), }, { name: "percent_diff_abs two positive points [1]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(33.33333333333333)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(33.33333333333333)), }, { name: "percent_diff_abs two positive points [2]", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(20)), - expectedNumber: newNumber(ptr.Float64(33.33333333333333)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(20.0)), + expectedNumber: newNumber(util.Pointer(33.33333333333333)), }, { name: "percent_diff_abs two negative points [1]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(33.33333333333333)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(33.33333333333333)), }, { name: "percent_diff_abs two negative points [2]", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-10)), - expectedNumber: newNumber(ptr.Float64(66.66666666666666)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-10.0)), + expectedNumber: newNumber(util.Pointer(66.66666666666666)), }, { name: "percent_diff_abs of one positive and one negative point", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(-40)), - expectedNumber: newNumber(ptr.Float64(233.33333333333334)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(-40.0)), + expectedNumber: newNumber(util.Pointer(233.33333333333334)), }, { name: "percent_diff_abs of one negative and one positive point", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(40)), - expectedNumber: newNumber(ptr.Float64(233.33333333333334)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(40.0)), + expectedNumber: newNumber(util.Pointer(233.33333333333334)), }, { name: "percent_diff_abs of three positive points", - inputSeries: newSeries(ptr.Float64(30), ptr.Float64(40), ptr.Float64(50)), - expectedNumber: newNumber(ptr.Float64(66.66666666666666)), + inputSeries: newSeries(util.Pointer(30.0), util.Pointer(40.0), util.Pointer(50.0)), + expectedNumber: newNumber(util.Pointer(66.66666666666666)), }, { name: "percent_diff_abs of three negative points", - inputSeries: newSeries(ptr.Float64(-30), ptr.Float64(-40), ptr.Float64(-50)), - expectedNumber: newNumber(ptr.Float64(66.66666666666666)), + inputSeries: newSeries(util.Pointer(-30.0), util.Pointer(-40.0), util.Pointer(-50.0)), + expectedNumber: newNumber(util.Pointer(66.66666666666666)), }, { name: "percent_diff_abs with only nulls", diff --git a/pkg/expr/commands_test.go b/pkg/expr/commands_test.go index 9109e6fc6ec..4228c280247 100644 --- a/pkg/expr/commands_test.go +++ b/pkg/expr/commands_test.go @@ -11,7 +11,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr/mathexp" "github.com/grafana/grafana/pkg/expr/mathexp/parse" @@ -105,9 +104,9 @@ func TestReduceExecute(t *testing.T) { t.Run("should noop if Number", func(t *testing.T) { var numbers mathexp.Values = []mathexp.Value{ - mathexp.GenerateNumber(ptr.Float64(rand.Float64())), - mathexp.GenerateNumber(ptr.Float64(rand.Float64())), - mathexp.GenerateNumber(ptr.Float64(rand.Float64())), + mathexp.GenerateNumber(util.Pointer(rand.Float64())), + mathexp.GenerateNumber(util.Pointer(rand.Float64())), + mathexp.GenerateNumber(util.Pointer(rand.Float64())), } vars := map[string]mathexp.Results{ @@ -202,7 +201,7 @@ func TestResampleCommand_Execute(t *testing.T) { isError: true, }, { name: "should return error when input Scalar", - vals: mathexp.NewScalar("test", ptr.Float64(rand.Float64())), + vals: mathexp.NewScalar("test", util.Pointer(rand.Float64())), isError: true, }, } diff --git a/pkg/services/alerting/conditions/query_test.go b/pkg/services/alerting/conditions/query_test.go index b37e7707993..d3dcea599d6 100644 --- a/pkg/services/alerting/conditions/query_test.go +++ b/pkg/services/alerting/conditions/query_test.go @@ -10,7 +10,6 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/components/null" "github.com/grafana/grafana/pkg/components/simplejson" @@ -22,6 +21,7 @@ import ( "github.com/grafana/grafana/pkg/services/validations" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb/legacydata" + "github.com/grafana/grafana/pkg/util" ) func newTimeSeriesPointsFromArgs(values ...float64) legacydata.DataTimeSeriesPoints { @@ -276,7 +276,7 @@ func TestFrameToSeriesSlice(t *testing.T) { }), data.NewField(`Values Int64s`, data.Labels{"Animal Factor": "cat"}, []*int64{ nil, - pointer.Int64(3), + util.Pointer(int64(3)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []float64{ 2.0, diff --git a/pkg/services/dashboards/service/dashboard_service_test.go b/pkg/services/dashboards/service/dashboard_service_test.go index 6e2ce1377ed..a55a16083cd 100644 --- a/pkg/services/dashboards/service/dashboard_service_test.go +++ b/pkg/services/dashboards/service/dashboard_service_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/appcontext" @@ -18,6 +17,7 @@ import ( "github.com/grafana/grafana/pkg/services/guardian" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util" ) func TestDashboardService(t *testing.T) { @@ -120,7 +120,7 @@ func TestDashboardService(t *testing.T) { if origAlertingEnabledSet { origAlertingEnabledVal = *setting.AlertingEnabled } - setting.AlertingEnabled = pointer.Bool(true) + setting.AlertingEnabled = util.Pointer(true) t.Cleanup(func() { if !origAlertingEnabledSet { setting.AlertingEnabled = nil diff --git a/pkg/services/ngalert/eval/eval_test.go b/pkg/services/ngalert/eval/eval_test.go index 866638b0d25..14fdd65cb54 100644 --- a/pkg/services/ngalert/eval/eval_test.go +++ b/pkg/services/ngalert/eval/eval_test.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/plugins" @@ -33,7 +32,7 @@ func TestEvaluateExecutionResult(t *testing.T) { desc: "zero valued single instance is single Normal state result", execResults: ExecutionResults{ Condition: []*data.Frame{ - data.NewFrame("", data.NewField("", nil, []*float64{ptr.Float64(0)})), + data.NewFrame("", data.NewField("", nil, []*float64{util.Pointer(0.0)})), }, }, expectResultLength: 1, @@ -47,7 +46,7 @@ func TestEvaluateExecutionResult(t *testing.T) { desc: "non-zero valued single instance is single Alerting state result", execResults: ExecutionResults{ Condition: []*data.Frame{ - data.NewFrame("", data.NewField("", nil, []*float64{ptr.Float64(1)})), + data.NewFrame("", data.NewField("", nil, []*float64{util.Pointer(1.0)})), }, }, expectResultLength: 1, @@ -142,7 +141,7 @@ func TestEvaluateExecutionResult(t *testing.T) { execResults: ExecutionResults{ Condition: []*data.Frame{ data.NewFrame("", - data.NewField("", nil, []*float64{ptr.Float64(23)}), + data.NewField("", nil, []*float64{util.Pointer(23.0)}), data.NewField("", nil, []*float64{}), ), }, @@ -178,7 +177,7 @@ func TestEvaluateExecutionResult(t *testing.T) { execResults: ExecutionResults{ Condition: []*data.Frame{ data.NewFrame("", - data.NewField("", nil, []*float64{ptr.Float64(2), ptr.Float64(3)}), + data.NewField("", nil, []*float64{util.Pointer(2.0), util.Pointer(3.0)}), ), }, }, @@ -229,10 +228,10 @@ func TestEvaluateExecutionResult(t *testing.T) { execResults: ExecutionResults{ Condition: []*data.Frame{ data.NewFrame("", - data.NewField("", nil, []*float64{ptr.Float64(1)}), + data.NewField("", nil, []*float64{util.Pointer(1.0)}), ), data.NewFrame("", - data.NewField("", nil, []*float64{ptr.Float64(2)}), + data.NewField("", nil, []*float64{util.Pointer(2.0)}), ), }, }, @@ -272,7 +271,7 @@ func TestEvaluateExecutionResult(t *testing.T) { data.NewField("", nil, []float64{3}), ), data.NewFrame("", - data.NewField("", data.Labels{"a": "b"}, []*float64{ptr.Float64(2)}), + data.NewField("", data.Labels{"a": "b"}, []*float64{util.Pointer(2.0)}), ), }, }, diff --git a/pkg/services/ngalert/eval/extract_md_test.go b/pkg/services/ngalert/eval/extract_md_test.go index 6951a8caa15..844ac0eccb1 100644 --- a/pkg/services/ngalert/eval/extract_md_test.go +++ b/pkg/services/ngalert/eval/extract_md_test.go @@ -5,9 +5,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/expr/classic" + "github.com/grafana/grafana/pkg/util" ) func TestExtractEvalString(t *testing.T) { @@ -19,25 +19,25 @@ func TestExtractEvalString(t *testing.T) { { desc: "1 EvalMatch", inFrame: newMetaFrame([]classic.EvalMatch{ - {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(32.3)}, - }, ptr.Float64(1)), + {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(32.3)}, + }, util.Pointer(1.0)), outString: `[ var='0' metric='Test' labels={host=foo} value=32.3 ]`, }, { desc: "2 EvalMatches", inFrame: newMetaFrame([]classic.EvalMatch{ - {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(32.3)}, - {Metric: "Test", Labels: data.Labels{"host": "baz"}, Value: ptr.Float64(10)}, - }, ptr.Float64(1), withRefID("A")), + {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(32.3)}, + {Metric: "Test", Labels: data.Labels{"host": "baz"}, Value: util.Pointer(10.0)}, + }, util.Pointer(1.0), withRefID("A")), outString: `[ var='A0' metric='Test' labels={host=foo} value=32.3 ], [ var='A1' metric='Test' labels={host=baz} value=10 ]`, }, { desc: "3 EvalMatches", inFrame: newMetaFrame([]classic.EvalMatch{ - {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(32.3)}, - {Metric: "Test", Labels: data.Labels{"host": "baz"}, Value: ptr.Float64(10)}, - {Metric: "TestA", Labels: data.Labels{"host": "zip"}, Value: ptr.Float64(11)}, - }, ptr.Float64(1), withRefID("A")), + {Metric: "Test", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(32.3)}, + {Metric: "Test", Labels: data.Labels{"host": "baz"}, Value: util.Pointer(10.0)}, + {Metric: "TestA", Labels: data.Labels{"host": "zip"}, Value: util.Pointer(11.0)}, + }, util.Pointer(1.0), withRefID("A")), outString: `[ var='A0' metric='Test' labels={host=foo} value=32.3 ], [ var='A1' metric='Test' labels={host=baz} value=10 ], [ var='A2' metric='TestA' labels={host=zip} value=11 ]`, }, } @@ -55,51 +55,51 @@ func TestExtractValues(t *testing.T) { values map[string]NumberValueCapture }{{ desc: "No values in frame returns nil", - inFrame: newMetaFrame(nil, ptr.Float64(1)), + inFrame: newMetaFrame(nil, util.Pointer(1.0)), values: nil, }, { desc: "Classic condition frame with one match", inFrame: newMetaFrame([]classic.EvalMatch{ - {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - }, ptr.Float64(1), withRefID("A")), + {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + }, util.Pointer(1.0), withRefID("A")), values: map[string]NumberValueCapture{ - "A0": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, + "A0": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, }, }, { desc: "Classic condition frame with multiple matches", inFrame: newMetaFrame([]classic.EvalMatch{ - {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(3)}, - }, ptr.Float64(1), withRefID("A")), + {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + {Metric: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(3.0)}, + }, util.Pointer(1.0), withRefID("A")), values: map[string]NumberValueCapture{ - "A0": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - "A1": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(3)}, + "A0": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + "A1": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(3.0)}, }, }, { desc: "Nil value", inFrame: newMetaFrame([]NumberValueCapture{ {Var: "A", Labels: data.Labels{"host": "foo"}, Value: nil}, - }, ptr.Float64(1)), + }, util.Pointer(1.0)), values: map[string]NumberValueCapture{ "A": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: nil}, }, }, { desc: "1 value", inFrame: newMetaFrame([]NumberValueCapture{ - {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - }, ptr.Float64(1)), + {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + }, util.Pointer(1.0)), values: map[string]NumberValueCapture{ - "A": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, + "A": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, }, }, { desc: "2 values", inFrame: newMetaFrame([]NumberValueCapture{ - {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - {Var: "B", Labels: nil, Value: ptr.Float64(2)}, - }, ptr.Float64(1)), + {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + {Var: "B", Labels: nil, Value: util.Pointer(2.0)}, + }, util.Pointer(1.0)), values: map[string]NumberValueCapture{ - "A": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: ptr.Float64(1)}, - "B": {Var: "B", Value: ptr.Float64(2)}, + "A": {Var: "A", Labels: data.Labels{"host": "foo"}, Value: util.Pointer(1.0)}, + "B": {Var: "B", Value: util.Pointer(2.0)}, }, }} for _, tc := range cases { diff --git a/pkg/services/ngalert/image/service_test.go b/pkg/services/ngalert/image/service_test.go index 03a60f65215..afd55747c02 100644 --- a/pkg/services/ngalert/image/service_test.go +++ b/pkg/services/ngalert/image/service_test.go @@ -10,13 +10,13 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/components/imguploader" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/ngalert/store" "github.com/grafana/grafana/pkg/services/screenshot" + "github.com/grafana/grafana/pkg/util" ) func TestScreenshotImageService(t *testing.T) { @@ -68,8 +68,8 @@ func TestScreenshotImageService(t *testing.T) { image, err := s.NewImage(ctx, &models.AlertRule{ OrgID: 1, UID: "foo", - DashboardUID: pointer.String("foo"), - PanelID: pointer.Int64(1)}) + DashboardUID: util.Pointer("foo"), + PanelID: util.Pointer(int64(1))}) require.NoError(t, err) assert.Equal(t, expected, *image) }) @@ -105,8 +105,8 @@ func TestScreenshotImageService(t *testing.T) { image, err := s.NewImage(ctx, &models.AlertRule{ OrgID: 1, UID: "bar", - DashboardUID: pointer.String("bar"), - PanelID: pointer.Int64(1)}) + DashboardUID: util.Pointer("bar"), + PanelID: util.Pointer(int64(1))}) require.NoError(t, err) assert.Equal(t, expected, *image) }) @@ -120,8 +120,8 @@ func TestScreenshotImageService(t *testing.T) { image, err := s.NewImage(ctx, &models.AlertRule{ OrgID: 1, UID: "baz", - DashboardUID: pointer.String("baz"), - PanelID: pointer.Int64(1)}) + DashboardUID: util.Pointer("baz"), + PanelID: util.Pointer(int64(1))}) require.NoError(t, err) assert.Equal(t, expected, *image) }) @@ -141,8 +141,8 @@ func TestScreenshotImageService(t *testing.T) { image, err := s.NewImage(ctx, &models.AlertRule{ OrgID: 1, UID: "qux", - DashboardUID: pointer.String("qux"), - PanelID: pointer.Int64(1)}) + DashboardUID: util.Pointer("qux"), + PanelID: util.Pointer(int64(1))}) assert.EqualError(t, err, "context deadline exceeded") assert.Nil(t, image) }) diff --git a/pkg/services/ngalert/state/state_test.go b/pkg/services/ngalert/state/state_test.go index 45680d8c2a1..95ced7f8fe3 100644 --- a/pkg/services/ngalert/state/state_test.go +++ b/pkg/services/ngalert/state/state_test.go @@ -12,11 +12,11 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/services/ngalert/eval" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" "github.com/grafana/grafana/pkg/services/screenshot" + "github.com/grafana/grafana/pkg/util" ) func TestSetAlerting(t *testing.T) { @@ -488,7 +488,7 @@ func TestGetLastEvaluationValuesForCondition(t *testing.T) { EvaluationTime: time.Time{}, EvaluationState: 0, Values: map[string]*float64{ - "A": ptr.Float64(rand.Float64()), + "A": util.Pointer(rand.Float64()), }, Condition: "A", }, @@ -496,8 +496,8 @@ func TestGetLastEvaluationValuesForCondition(t *testing.T) { EvaluationTime: time.Time{}, EvaluationState: 0, Values: map[string]*float64{ - "B": ptr.Float64(rand.Float64()), - "A": ptr.Float64(expected), + "B": util.Pointer(rand.Float64()), + "A": util.Pointer(expected), }, Condition: "A", }, @@ -513,7 +513,7 @@ func TestGetLastEvaluationValuesForCondition(t *testing.T) { EvaluationTime: time.Time{}, EvaluationState: 0, Values: map[string]*float64{ - "C": ptr.Float64(rand.Float64()), + "C": util.Pointer(rand.Float64()), }, Condition: "A", }, @@ -614,7 +614,7 @@ func TestTakeImage(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - r := ngmodels.AlertRule{DashboardUID: ptr.String("foo")} + r := ngmodels.AlertRule{DashboardUID: util.Pointer("foo")} s := NewMockImageCapturer(ctrl) s.EXPECT().NewImage(ctx, &r).Return(nil, ngmodels.ErrNoPanel) @@ -628,7 +628,7 @@ func TestTakeImage(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - r := ngmodels.AlertRule{DashboardUID: ptr.String("foo"), PanelID: ptr.Int64(1)} + r := ngmodels.AlertRule{DashboardUID: util.Pointer("foo"), PanelID: util.Pointer(int64(1))} s := NewMockImageCapturer(ctrl) s.EXPECT().NewImage(ctx, &r).Return(nil, screenshot.ErrScreenshotsUnavailable) @@ -642,7 +642,7 @@ func TestTakeImage(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - r := ngmodels.AlertRule{DashboardUID: ptr.String("foo"), PanelID: ptr.Int64(1)} + r := ngmodels.AlertRule{DashboardUID: util.Pointer("foo"), PanelID: util.Pointer(int64(1))} s := NewMockImageCapturer(ctrl) s.EXPECT().NewImage(ctx, &r).Return(nil, errors.New("unknown error")) @@ -656,7 +656,7 @@ func TestTakeImage(t *testing.T) { defer ctrl.Finish() ctx := context.Background() - r := ngmodels.AlertRule{DashboardUID: ptr.String("foo"), PanelID: ptr.Int64(1)} + r := ngmodels.AlertRule{DashboardUID: util.Pointer("foo"), PanelID: util.Pointer(int64(1))} s := NewMockImageCapturer(ctrl) s.EXPECT().NewImage(ctx, &r).Return(&ngmodels.Image{Path: "foo.png"}, nil) diff --git a/pkg/services/ngalert/state/template/template_test.go b/pkg/services/ngalert/state/template/template_test.go index db361349842..d0ae80abc32 100644 --- a/pkg/services/ngalert/state/template/template_test.go +++ b/pkg/services/ngalert/state/template/template_test.go @@ -9,9 +9,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/services/ngalert/eval" + "github.com/grafana/grafana/pkg/util" ) func TestLabelsString(t *testing.T) { @@ -96,7 +96,7 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{"instance": "foo"}, - Value: ptr.Float64(1), + Value: util.Pointer(1.0), }, }, }, @@ -109,7 +109,7 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{"instance": "foo"}, - Value: ptr.Float64(1.1), + Value: util.Pointer(1.1), }, }, }, @@ -122,7 +122,7 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{}, - Value: ptr.Float64(1), + Value: util.Pointer(1.0), }, }, }, @@ -176,22 +176,22 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{}, - Value: ptr.Float64(0.0), + Value: util.Pointer(0.0), }, "B": { Var: "B", Labels: data.Labels{}, - Value: ptr.Float64(1.0), + Value: util.Pointer(1.0), }, "C": { Var: "C", Labels: data.Labels{}, - Value: ptr.Float64(1048576.0), + Value: util.Pointer(1048576.0), }, "D": { Var: "D", Labels: data.Labels{}, - Value: ptr.Float64(.12), + Value: util.Pointer(.12), }, }, }, @@ -211,42 +211,42 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{}, - Value: ptr.Float64(0), + Value: util.Pointer(0.0), }, "B": { Var: "B", Labels: data.Labels{}, - Value: ptr.Float64(1), + Value: util.Pointer(1.0), }, "C": { Var: "C", Labels: data.Labels{}, - Value: ptr.Float64(60), + Value: util.Pointer(60.0), }, "D": { Var: "D", Labels: data.Labels{}, - Value: ptr.Float64(3600), + Value: util.Pointer(3600.0), }, "E": { Var: "E", Labels: data.Labels{}, - Value: ptr.Float64(86400), + Value: util.Pointer(86400.0), }, "F": { Var: "F", Labels: data.Labels{}, - Value: ptr.Float64(86400 + 3600), + Value: util.Pointer(86400.0 + 3600.0), }, "G": { Var: "G", Labels: data.Labels{}, - Value: ptr.Float64(-(86400*2 + 3600*3 + 60*4 + 5)), + Value: util.Pointer(-(86400*2 + 3600*3 + 60*4 + 5.0)), }, "H": { Var: "H", Labels: data.Labels{}, - Value: ptr.Float64(899.99), + Value: util.Pointer(899.99), }, }, }, @@ -266,37 +266,37 @@ func TestExpandTemplate(t *testing.T) { "A": { Var: "A", Labels: data.Labels{}, - Value: ptr.Float64(.1), + Value: util.Pointer(.1), }, "B": { Var: "B", Labels: data.Labels{}, - Value: ptr.Float64(.0001), + Value: util.Pointer(.0001), }, "C": { Var: "C", Labels: data.Labels{}, - Value: ptr.Float64(.12345), + Value: util.Pointer(.12345), }, "D": { Var: "D", Labels: data.Labels{}, - Value: ptr.Float64(60.1), + Value: util.Pointer(60.1), }, "E": { Var: "E", Labels: data.Labels{}, - Value: ptr.Float64(60.5), + Value: util.Pointer(60.5), }, "F": { Var: "F", Labels: data.Labels{}, - Value: ptr.Float64(1.2345), + Value: util.Pointer(1.2345), }, "G": { Var: "G", Labels: data.Labels{}, - Value: ptr.Float64(12.345), + Value: util.Pointer(12.345), }, }, }, diff --git a/pkg/services/quota/quotaimpl/quota_test.go b/pkg/services/quota/quotaimpl/quota_test.go index 20570ca46f6..e9e289508b0 100644 --- a/pkg/services/quota/quotaimpl/quota_test.go +++ b/pkg/services/quota/quotaimpl/quota_test.go @@ -7,7 +7,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/api/routing" "github.com/grafana/grafana/pkg/bus" @@ -43,6 +42,7 @@ import ( "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/services/user/userimpl" "github.com/grafana/grafana/pkg/setting" + "github.com/grafana/grafana/pkg/util" ) func TestQuotaService(t *testing.T) { @@ -221,7 +221,7 @@ func TestIntegrationQuotaCommandsAndQueries(t *testing.T) { t.Run("Should be able to get zero used org alert quota when table does not exist (ngalert is not enabled - default case)", func(t *testing.T) { // disable Grafana Alerting cfg := *sqlStore.Cfg - cfg.UnifiedAlerting = setting.UnifiedAlertingSettings{Enabled: pointer.Bool(false)} + cfg.UnifiedAlerting = setting.UnifiedAlertingSettings{Enabled: util.Pointer(false)} quotaSrv := ProvideService(sqlStore, &cfg) q, err := getQuotaBySrvTargetScope(t, quotaSrv, ngalertmodels.QuotaTargetSrv, ngalertmodels.QuotaTarget, quota.OrgScope, "a.ScopeParameters{OrgID: o.ID}) diff --git a/pkg/tsdb/azuremonitor/loganalytics/azure-response-table-frame_test.go b/pkg/tsdb/azuremonitor/loganalytics/azure-response-table-frame_test.go index afda6263816..850c58bd71e 100644 --- a/pkg/tsdb/azuremonitor/loganalytics/azure-response-table-frame_test.go +++ b/pkg/tsdb/azuremonitor/loganalytics/azure-response-table-frame_test.go @@ -10,9 +10,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" ) func TestLogTableToFrame(t *testing.T) { @@ -27,19 +27,19 @@ func TestLogTableToFrame(t *testing.T) { expectedFrame: func() *data.Frame { frame := data.NewFrame("", data.NewField("TimeGenerated", nil, []*time.Time{ - pointer.Time(time.Date(2020, 4, 19, 19, 16, 6, 5e8, time.UTC)), - pointer.Time(time.Date(2020, 4, 19, 19, 16, 16, 5e8, time.UTC)), - pointer.Time(time.Date(2020, 4, 19, 19, 16, 26, 5e8, time.UTC)), + util.Pointer(time.Date(2020, 4, 19, 19, 16, 6, 5e8, time.UTC)), + util.Pointer(time.Date(2020, 4, 19, 19, 16, 16, 5e8, time.UTC)), + util.Pointer(time.Date(2020, 4, 19, 19, 16, 26, 5e8, time.UTC)), }), data.NewField("Computer", nil, []*string{ - pointer.String("grafana-vm"), - pointer.String("grafana-vm"), - pointer.String("grafana-vm"), + util.Pointer("grafana-vm"), + util.Pointer("grafana-vm"), + util.Pointer("grafana-vm"), }), data.NewField("avg_CounterValue", nil, []*float64{ - pointer.Float64(1.1), - pointer.Float64(2.2), - pointer.Float64(3.3), + util.Pointer(1.1), + util.Pointer(2.2), + util.Pointer(3.3), }), ) frame.Meta = &data.FrameMeta{ @@ -54,42 +54,42 @@ func TestLogTableToFrame(t *testing.T) { expectedFrame: func() *data.Frame { frame := data.NewFrame("", data.NewField("TenantId", nil, []*string{ - pointer.String("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), - pointer.String("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), - pointer.String("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), + util.Pointer("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), + util.Pointer("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), + util.Pointer("a2c1b44e-3e57-4410-b027-6cc0ae6dee67"), }), data.NewField("Computer", nil, []*string{ - pointer.String("grafana-vm"), - pointer.String("grafana-vm"), - pointer.String("grafana-vm"), + util.Pointer("grafana-vm"), + util.Pointer("grafana-vm"), + util.Pointer("grafana-vm"), }), data.NewField("ObjectName", nil, []*string{ - pointer.String("Memory"), - pointer.String("Memory"), - pointer.String("Memory"), + util.Pointer("Memory"), + util.Pointer("Memory"), + util.Pointer("Memory"), }), data.NewField("CounterName", nil, []*string{ - pointer.String("Available MBytes Memory"), - pointer.String("Available MBytes Memory"), - pointer.String("Available MBytes Memory"), + util.Pointer("Available MBytes Memory"), + util.Pointer("Available MBytes Memory"), + util.Pointer("Available MBytes Memory"), }), data.NewField("InstanceName", nil, []*string{ - pointer.String("Memory"), - pointer.String("Memory"), - pointer.String("Memory"), + util.Pointer("Memory"), + util.Pointer("Memory"), + util.Pointer("Memory"), }), data.NewField("Min", nil, []*float64{nil, nil, nil}), data.NewField("Max", nil, []*float64{nil, nil, nil}), data.NewField("SampleCount", nil, []*int32{nil, nil, nil}), data.NewField("CounterValue", nil, []*float64{ - pointer.Float64(2040), - pointer.Float64(2066), - pointer.Float64(2066), + util.Pointer(2040.0), + util.Pointer(2066.0), + util.Pointer(2066.0), }), data.NewField("TimeGenerated", nil, []*time.Time{ - pointer.Time(time.Date(2020, 4, 23, 11, 46, 3, 857e6, time.UTC)), - pointer.Time(time.Date(2020, 4, 23, 11, 46, 13, 857e6, time.UTC)), - pointer.Time(time.Date(2020, 4, 23, 11, 46, 23, 857e6, time.UTC)), + util.Pointer(time.Date(2020, 4, 23, 11, 46, 3, 857e6, time.UTC)), + util.Pointer(time.Date(2020, 4, 23, 11, 46, 13, 857e6, time.UTC)), + util.Pointer(time.Date(2020, 4, 23, 11, 46, 23, 857e6, time.UTC)), }), ) frame.Meta = &data.FrameMeta{ @@ -104,18 +104,18 @@ func TestLogTableToFrame(t *testing.T) { testFile: "loganalytics/7-log-analytics-all-types-table.json", expectedFrame: func() *data.Frame { frame := data.NewFrame("", - data.NewField("XBool", nil, []*bool{pointer.Bool(true)}), - data.NewField("XString", nil, []*string{pointer.String("Grafana")}), - data.NewField("XDateTime", nil, []*time.Time{pointer.Time(time.Date(2006, 1, 2, 22, 4, 5, 1*1e8, time.UTC))}), - data.NewField("XDynamic", nil, []*string{pointer.String(`[{"person":"Daniel"},{"cats":23},{"diagnosis":"cat problem"}]`)}), - data.NewField("XGuid", nil, []*string{pointer.String("74be27de-1e4e-49d9-b579-fe0b331d3642")}), - data.NewField("XInt", nil, []*int32{pointer.Int32(2147483647)}), - data.NewField("XLong", nil, []*int64{pointer.Int64(9223372036854775807)}), - data.NewField("XReal", nil, []*float64{pointer.Float64(1.797693134862315708145274237317043567981e+308)}), - data.NewField("XTimeSpan", nil, []*string{pointer.String("00:00:00.0000001")}), - data.NewField("XDecimal", nil, []*float64{pointer.Float64(79228162514264337593543950335)}), - data.NewField("XObject", nil, []*string{pointer.String(`"{\"person\": \"Daniel\", \"cats\": 23, \"diagnosis\": \"cat problem\"}"`)}), - data.NewField("XNumber", nil, []*float64{pointer.Float64(79228162514264337593543950335)}), + data.NewField("XBool", nil, []*bool{util.Pointer(true)}), + data.NewField("XString", nil, []*string{util.Pointer("Grafana")}), + data.NewField("XDateTime", nil, []*time.Time{util.Pointer(time.Date(2006, 1, 2, 22, 4, 5, 1*1e8, time.UTC))}), + data.NewField("XDynamic", nil, []*string{util.Pointer(`[{"person":"Daniel"},{"cats":23},{"diagnosis":"cat problem"}]`)}), + data.NewField("XGuid", nil, []*string{util.Pointer("74be27de-1e4e-49d9-b579-fe0b331d3642")}), + data.NewField("XInt", nil, []*int32{util.Pointer(int32(2147483647))}), + data.NewField("XLong", nil, []*int64{util.Pointer(int64(9223372036854775807))}), + data.NewField("XReal", nil, []*float64{util.Pointer(1.797693134862315708145274237317043567981e+308)}), + data.NewField("XTimeSpan", nil, []*string{util.Pointer("00:00:00.0000001")}), + data.NewField("XDecimal", nil, []*float64{util.Pointer(79228162514264337593543950335.0)}), + data.NewField("XObject", nil, []*string{util.Pointer(`"{\"person\": \"Daniel\", \"cats\": 23, \"diagnosis\": \"cat problem\"}"`)}), + data.NewField("XNumber", nil, []*float64{util.Pointer(79228162514264337593543950335.0)}), ) frame.Meta = &data.FrameMeta{ Custom: &LogAnalyticsMeta{ColumnTypes: []string{"bool", "string", "datetime", @@ -129,9 +129,9 @@ func TestLogTableToFrame(t *testing.T) { testFile: "loganalytics/8-log-analytics-response-nan-inf.json", expectedFrame: func() *data.Frame { frame := data.NewFrame("", - data.NewField("XInf", nil, []*float64{pointer.Float64(math.Inf(0))}), - data.NewField("XInfNeg", nil, []*float64{pointer.Float64(math.Inf(-2))}), - data.NewField("XNan", nil, []*float64{pointer.Float64(math.NaN())}), + data.NewField("XInf", nil, []*float64{util.Pointer(math.Inf(0))}), + data.NewField("XInfNeg", nil, []*float64{util.Pointer(math.Inf(-2))}), + data.NewField("XNan", nil, []*float64{util.Pointer(math.NaN())}), ) frame.Meta = &data.FrameMeta{ Custom: &LogAnalyticsMeta{ColumnTypes: []string{"real", "real", "real"}}, @@ -144,8 +144,8 @@ func TestLogTableToFrame(t *testing.T) { testFile: "loganalytics/9-log-analytics-response-error.json", expectedFrame: func() *data.Frame { frame := data.NewFrame("", - data.NewField("OperationName", nil, []*string{pointer.String("Create or Update Virtual Machine")}), - data.NewField("Level", nil, []*string{pointer.String("Informational")}), + data.NewField("OperationName", nil, []*string{util.Pointer("Create or Update Virtual Machine")}), + data.NewField("Level", nil, []*string{util.Pointer("Informational")}), ) frame.Meta = &data.FrameMeta{ Custom: &LogAnalyticsMeta{ColumnTypes: []string{"string", "string"}}, @@ -159,8 +159,8 @@ func TestLogTableToFrame(t *testing.T) { testFile: "loganalytics/10-log-analytics-response-warning.json", expectedFrame: func() *data.Frame { frame := data.NewFrame("", - data.NewField("OperationName", nil, []*string{pointer.String("Create or Update Virtual Machine")}), - data.NewField("Level", nil, []*string{pointer.String("Informational")}), + data.NewField("OperationName", nil, []*string{util.Pointer("Create or Update Virtual Machine")}), + data.NewField("Level", nil, []*string{util.Pointer("Informational")}), ) frame.Meta = &data.FrameMeta{ Custom: &LogAnalyticsMeta{ColumnTypes: []string{"string", "string"}}, diff --git a/pkg/tsdb/azuremonitor/metrics/azuremonitor-datasource_test.go b/pkg/tsdb/azuremonitor/metrics/azuremonitor-datasource_test.go index 0847e163d9d..ba7fffefa1c 100644 --- a/pkg/tsdb/azuremonitor/metrics/azuremonitor-datasource_test.go +++ b/pkg/tsdb/azuremonitor/metrics/azuremonitor-datasource_test.go @@ -17,12 +17,12 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/log" azTime "github.com/grafana/grafana/pkg/tsdb/azuremonitor/time" "github.com/grafana/grafana/pkg/tsdb/azuremonitor/types" + "github.com/grafana/grafana/pkg/util" ) func TestAzureMonitorBuildQueries(t *testing.T) { @@ -115,7 +115,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob eq '*'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "legacy query without resourceURI and has dimensionFilter*s* property with two dimensions", @@ -128,7 +128,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob eq '*' and tier eq '*'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "legacy query without resourceURI and has a dimension filter without specifying a top", @@ -153,7 +153,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob ne 'test'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "has dimensionFilter*s* property with startsWith operator", @@ -166,7 +166,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob sw 'test'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A3%2C%22values%22%3A%5B%22test%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A3%2C%22values%22%3A%5B%22test%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "correctly sets dimension operator to eq (irrespective of operator) when filter value is '*'", @@ -179,7 +179,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob eq '*' and tier eq '*'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "correctly constructs target when multiple filter values are provided for the 'eq' operator", @@ -192,7 +192,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob eq 'test' or blob eq 'test2'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A0%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A0%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "correctly constructs target when multiple filter values are provided for ne 'eq' operator", @@ -205,7 +205,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedInterval: "PT1M", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedParamFilter: "blob ne 'test' and blob ne 'test2'", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, { name: "Includes a region", @@ -255,7 +255,7 @@ func TestAzureMonitorBuildQueries(t *testing.T) { expectedURL: "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/providers/microsoft.insights/metrics", azureMonitorQueryTarget: "aggregation=Average&api-version=2021-05-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute%2FvirtualMachines×pan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30", expectedBodyFilter: "(Microsoft.ResourceId eq '/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm' or Microsoft.ResourceId eq '/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/rg2/providers/Microsoft.Compute/virtualMachines/vm2') and (blob ne 'test' and blob ne 'test2')", - expectedPortalURL: ptr.String("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), + expectedPortalURL: util.Pointer("http://ds/#blade/Microsoft_Azure_MonitoringMetrics/Metrics.ReactView/Referer/MetricsExplorer/TimeContext/%7B%22absolute%22%3A%7B%22startTime%22%3A%222018-03-15T13%3A00%3A00Z%22%2C%22endTime%22%3A%222018-03-15T13%3A34%3A00Z%22%7D%7D/ChartDefinition/%7B%22v2charts%22%3A%5B%7B%22filterCollection%22%3A%7B%22filters%22%3A%5B%7B%22key%22%3A%22blob%22%2C%22operator%22%3A1%2C%22values%22%3A%5B%22test%22%2C%22test2%22%5D%7D%5D%7D%2C%22grouping%22%3A%7B%22dimension%22%3A%22blob%22%2C%22sort%22%3A2%2C%22top%22%3A10%7D%2C%22metrics%22%3A%5B%7B%22resourceMetadata%22%3A%7B%22id%22%3A%22%2Fsubscriptions%2F12345678-aaaa-bbbb-cccc-123456789abc%2FresourceGroups%2Fgrafanastaging%2Fproviders%2FMicrosoft.Compute%2FvirtualMachines%2Fgrafana%22%7D%2C%22name%22%3A%22Percentage%20CPU%22%2C%22aggregationType%22%3A4%2C%22namespace%22%3A%22Microsoft.Compute%2FvirtualMachines%22%2C%22metricVisualization%22%3A%7B%22displayName%22%3A%22Percentage%20CPU%22%2C%22resourceDisplayName%22%3A%22grafana%22%7D%7D%5D%7D%5D%7D"), }, } @@ -406,7 +406,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(2.0875), ptr.Float64(2.1525), ptr.Float64(2.155), ptr.Float64(3.6925), ptr.Float64(2.44), + util.Pointer(2.0875), util.Pointer(2.1525), util.Pointer(2.155), util.Pointer(3.6925), util.Pointer(2.44), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{averageLink}})), }, }, @@ -425,7 +425,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{totalLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52), + util.Pointer(8.26), util.Pointer(8.7), util.Pointer(14.82), util.Pointer(10.07), util.Pointer(8.52), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{totalLink}})), }, }, @@ -444,7 +444,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 14, 26, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{maxLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(3.07), ptr.Float64(2.92), ptr.Float64(2.87), ptr.Float64(2.27), ptr.Float64(2.52), + util.Pointer(3.07), util.Pointer(2.92), util.Pointer(2.87), util.Pointer(2.27), util.Pointer(2.52), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{maxLink}})), }, }, @@ -463,7 +463,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 14, 43, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{minLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(1.51), ptr.Float64(2.38), ptr.Float64(1.69), ptr.Float64(2.27), ptr.Float64(1.96), + util.Pointer(1.51), util.Pointer(2.38), util.Pointer(1.69), util.Pointer(2.27), util.Pointer(1.96), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{minLink}})), }, }, @@ -482,7 +482,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 14, 44, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{countLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(4), ptr.Float64(4), ptr.Float64(4), ptr.Float64(4), ptr.Float64(4), + util.Pointer(4.0), util.Pointer(4.0), util.Pointer(4.0), util.Pointer(4.0), util.Pointer(4.0), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{countLink}})), }, }, @@ -501,7 +501,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"}, - []*float64{ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), nil}). + []*float64{util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), nil}). SetConfig(&data.FieldConfig{Unit: "short", Links: []data.DataLink{averageLink}, DisplayName: "Blob Count grafana"})), data.NewFrame("", @@ -509,7 +509,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, - []*float64{ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), nil}). + []*float64{util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), nil}). SetConfig(&data.FieldConfig{Unit: "short", Links: []data.DataLink{averageLink}, DisplayName: "Blob Count grafana"})), data.NewFrame("", @@ -517,7 +517,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, - []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), nil}). + []*float64{util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), nil}). SetConfig(&data.FieldConfig{Unit: "short", Links: []data.DataLink{averageLink}, DisplayName: "Blob Count grafana"})), }, }, @@ -537,7 +537,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{totalLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52), + util.Pointer(8.26), util.Pointer(8.7), util.Pointer(14.82), util.Pointer(10.07), util.Pointer(8.52), }).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU", Links: []data.DataLink{totalLink}})), }, }, @@ -557,14 +557,14 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"}, - []*float64{ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), nil}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=PageBlob", Links: []data.DataLink{averageLink}})), + []*float64{util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), util.Pointer(3.0), nil}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=PageBlob", Links: []data.DataLink{averageLink}})), data.NewFrame("", data.NewField("Time", nil, makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, []*float64{ - ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), nil, + util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), util.Pointer(1.0), nil, }).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=BlockBlob", Links: []data.DataLink{averageLink}})), data.NewFrame("", @@ -572,7 +572,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, []*float64{ - ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), nil, + util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0), nil, }).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=Azure Data Lake Storage", Links: []data.DataLink{averageLink}})), }, }, @@ -592,7 +592,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Capacity", data.Labels{"blobtype": "PageBlob", "tier": "Standard"}, - []*float64{ptr.Float64(675530), ptr.Float64(675530), ptr.Float64(675530)}).SetConfig( + []*float64{util.Pointer(675530.0), util.Pointer(675530.0), util.Pointer(675530.0)}).SetConfig( &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=PageBlob, Tier=Standard}", Links: []data.DataLink{averageLink}})), data.NewFrame("", @@ -600,7 +600,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Capacity", data.Labels{"blobtype": "BlockBlob", "tier": "Hot"}, - []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0)}).SetConfig( + []*float64{util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0)}).SetConfig( &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=BlockBlob, Tier=Hot}", Links: []data.DataLink{averageLink}})), data.NewFrame("", @@ -608,7 +608,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Blob Capacity", data.Labels{"blobtype": "Azure Data Lake Storage", "tier": "Cool"}, - []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0)}).SetConfig( + []*float64{util.Pointer(0.0), util.Pointer(0.0), util.Pointer(0.0)}).SetConfig( &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}", Links: []data.DataLink{averageLink}})), }, }, @@ -628,7 +628,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { []time.Time{time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC)}, ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(2.0875), + util.Pointer(2.0875), }).SetConfig(&data.FieldConfig{DisplayName: "custom", Links: []data.DataLink{averageLink}})), }, }, @@ -648,7 +648,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{totalLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52), + util.Pointer(8.26), util.Pointer(8.7), util.Pointer(14.82), util.Pointer(10.07), util.Pointer(8.52), }).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU", Links: []data.DataLink{totalLink}})), }, }, @@ -668,7 +668,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{totalLink}}), data.NewField("Percentage CPU", nil, []*float64{ - ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52), + util.Pointer(8.26), util.Pointer(8.7), util.Pointer(14.82), util.Pointer(10.07), util.Pointer(8.52), }).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU", Links: []data.DataLink{totalLink}})), }, }, @@ -687,7 +687,7 @@ func TestAzureMonitorParseResponse(t *testing.T) { makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute), ).SetConfig(&data.FieldConfig{Links: []data.DataLink{averageLink}}), data.NewField("Percentage CPU", data.Labels{"microsoft.resourceid": "/subscriptions/12345678-aaaa-bbbb-cccc-123456789abc/resourceGroups/grafanastaging/providers/Microsoft.Compute/virtualMachines/grafana"}, []*float64{ - ptr.Float64(2.0875), ptr.Float64(2.1525), ptr.Float64(2.155), ptr.Float64(3.6925), ptr.Float64(2.44), + util.Pointer(2.0875), util.Pointer(2.1525), util.Pointer(2.155), util.Pointer(3.6925), util.Pointer(2.44), }).SetConfig(&data.FieldConfig{Unit: "percent", Links: []data.DataLink{averageLink}, DisplayName: "Percentage CPU grafana"}), ), }, diff --git a/pkg/tsdb/influxdb/flux/executor_test.go b/pkg/tsdb/influxdb/flux/executor_test.go index 0bb8398d666..b39d4004bc1 100644 --- a/pkg/tsdb/influxdb/flux/executor_test.go +++ b/pkg/tsdb/influxdb/flux/executor_test.go @@ -18,10 +18,10 @@ import ( "github.com/influxdata/influxdb-client-go/v2/api" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/tsdb/influxdb/models" + "github.com/grafana/grafana/pkg/util" ) //-------------------------------------------------------------- @@ -152,9 +152,9 @@ func TestAggregateGrouping(t *testing.T) { expectedFrame := data.NewFrame("", data.NewField("Time", nil, []*time.Time{&t1, &t2, &t3}), data.NewField("Value", map[string]string{"host": "hostname.ru"}, []*float64{ - pointer.Float64(8.291), - pointer.Float64(0.534), - pointer.Float64(0.667), + util.Pointer(8.291), + util.Pointer(0.534), + util.Pointer(0.667), }), ) expectedFrame.Meta = &data.FrameMeta{} @@ -187,7 +187,7 @@ func TestNonStandardTimeColumn(t *testing.T) { data.NewField("_start_water", map[string]string{"st": "1"}, []*time.Time{&t1}), data.NewField("_stop_water", map[string]string{"st": "1"}, []*time.Time{&t2}), data.NewField("_value", map[string]string{"st": "1"}, []*float64{ - pointer.Float64(156.304), + util.Pointer(156.304), }), ) expectedFrame.Meta = &data.FrameMeta{} diff --git a/pkg/tsdb/influxdb/response_parser_test.go b/pkg/tsdb/influxdb/response_parser_test.go index cc43c83f518..fcb11de46d1 100644 --- a/pkg/tsdb/influxdb/response_parser_test.go +++ b/pkg/tsdb/influxdb/response_parser_test.go @@ -10,9 +10,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" ) func prepare(text string) io.ReadCloser { @@ -70,7 +70,7 @@ func TestInfluxdbResponseParser(t *testing.T) { require.Nil(t, err) floatField := data.NewField("value", labels, []*float64{ - pointer.Float64(222), pointer.Float64(222), nil, + util.Pointer(222.0), util.Pointer(222.0), nil, }) floatField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean { datacenter: America }"} floatFrame := data.NewFrame("cpu.mean { datacenter: America }", @@ -293,7 +293,7 @@ func TestInfluxdbResponseParser(t *testing.T) { query := &Query{} newField := data.NewField("value", nil, []*float64{ - pointer.Float64(50), nil, pointer.Float64(52), + util.Pointer(50.0), nil, util.Pointer(52.0), }) newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean"} testFrame := data.NewFrame("cpu.mean", @@ -342,7 +342,7 @@ func TestInfluxdbResponseParser(t *testing.T) { query := &Query{} newField := data.NewField("value", nil, []*float64{ - pointer.Float64(50), pointer.Float64(52), + util.Pointer(50.0), util.Pointer(52.0), }) newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean"} testFrame := data.NewFrame("cpu.mean", @@ -395,7 +395,7 @@ func TestInfluxdbResponseParser(t *testing.T) { labels, err := data.LabelsFromString("/cluster/name/=Cluster/, @cluster@name@=Cluster@, cluster-name=Cluster, datacenter=America, dc.region.name=Northeast") require.Nil(t, err) newField := data.NewField("value", labels, []*float64{ - pointer.Float64(222), + util.Pointer(222.0), }) newField.Config = &data.FieldConfig{DisplayNameFromDS: "series alias"} testFrame := data.NewFrame("series alias", @@ -436,7 +436,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias sum" testFrame.Name = name newField = data.NewField("value", labels, []*float64{ - pointer.Float64(333), + util.Pointer(333.0), }) testFrame.Fields[1] = newField testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} @@ -450,7 +450,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias America" testFrame.Name = name newField = data.NewField("value", labels, []*float64{ - pointer.Float64(222), + util.Pointer(222.0), }) testFrame.Fields[1] = newField testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} @@ -464,7 +464,7 @@ func TestInfluxdbResponseParser(t *testing.T) { name = "alias America/America" testFrame.Name = name newField = data.NewField("value", labels, []*float64{ - pointer.Float64(222), + util.Pointer(222.0), }) testFrame.Fields[1] = newField testFrame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: name} @@ -660,7 +660,7 @@ func TestInfluxdbResponseParser(t *testing.T) { labels, err := data.LabelsFromString("datacenter=America") require.Nil(t, err) newField := data.NewField("value", labels, []*float64{ - pointer.Float64(222), pointer.Float64(222), nil, + util.Pointer(222.0), util.Pointer(222.0), nil, }) newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean { datacenter: America }"} testFrame := data.NewFrame("cpu.mean { datacenter: America }", @@ -748,7 +748,7 @@ func TestResponseParser_Parse(t *testing.T) { ] }]}]}`, f: func(t *testing.T, got *backend.QueryDataResponse) { - newField := data.NewField("value", nil, []*float64{nil, nil, pointer.Float64(52)}) + newField := data.NewField("value", nil, []*float64{nil, nil, util.Pointer(52.0)}) newField.Config = &data.FieldConfig{DisplayNameFromDS: "cpu.mean"} testFrame := data.NewFrame("cpu.mean", data.NewField("time", nil, diff --git a/pkg/tsdb/sqleng/resample_test.go b/pkg/tsdb/sqleng/resample_test.go index d6c121d7856..17e052d75a2 100644 --- a/pkg/tsdb/sqleng/resample_test.go +++ b/pkg/tsdb/sqleng/resample_test.go @@ -7,8 +7,8 @@ import ( "github.com/google/go-cmp/cmp" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/data" + "github.com/grafana/grafana/pkg/util" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" ) func TestResampleWide(t *testing.T) { @@ -35,14 +35,14 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 24, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(15), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(15.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(15.0), })), output: data.NewFrame("wide_test", data.NewField("Time", nil, []time.Time{ @@ -58,23 +58,23 @@ func TestResampleWide(t *testing.T) { }), data.NewField("Values Ints", nil, []*int64{ nil, - pointer.Int64(10), - pointer.Int64(12), + util.Pointer(int64(10)), + util.Pointer(int64(12)), nil, nil, nil, - pointer.Int64(15), + util.Pointer(int64(15)), nil, nil, }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ nil, - pointer.Float64(10.5), - pointer.Float64(12.5), + util.Pointer(10.5), + util.Pointer(12.5), nil, nil, nil, - pointer.Float64(15.0), + util.Pointer(15.0), nil, nil, })), @@ -94,14 +94,14 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 24, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(15), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(15.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(15.0), })), output: data.NewFrame("wide_test", data.NewField("Time", nil, []time.Time{ @@ -116,26 +116,26 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 26, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(-1), - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(-1), - pointer.Int64(-1), - pointer.Int64(-1), - pointer.Int64(15), - pointer.Int64(-1), - pointer.Int64(-1), + util.Pointer(int64(-1)), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(-1)), + util.Pointer(int64(-1)), + util.Pointer(int64(-1)), + util.Pointer(int64(15)), + util.Pointer(int64(-1)), + util.Pointer(int64(-1)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(-1), - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(-1), - pointer.Float64(-1), - pointer.Float64(-1), - pointer.Float64(15.0), - pointer.Float64(-1), - pointer.Float64(-1), + util.Pointer(-1.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(-1.0), + util.Pointer(-1.0), + util.Pointer(-1.0), + util.Pointer(15.0), + util.Pointer(-1.0), + util.Pointer(-1.0), })), }, { @@ -153,14 +153,14 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 24, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(15), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(15.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(15.0), })), output: data.NewFrame("wide_test", data.NewField("Time", nil, []time.Time{ @@ -176,25 +176,25 @@ func TestResampleWide(t *testing.T) { }), data.NewField("Values Ints", nil, []*int64{ nil, - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(12), - pointer.Int64(12), - pointer.Int64(12), - pointer.Int64(15), - pointer.Int64(15), - pointer.Int64(15), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(12)), + util.Pointer(int64(12)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), + util.Pointer(int64(15)), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ nil, - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(12.5), - pointer.Float64(12.5), - pointer.Float64(12.5), - pointer.Float64(15.0), - pointer.Float64(15.0), - pointer.Float64(15.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(12.5), + util.Pointer(12.5), + util.Pointer(12.5), + util.Pointer(15.0), + util.Pointer(15.0), + util.Pointer(15.0), })), }, { @@ -212,14 +212,14 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 24, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(15), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(15.0), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(15.0), })), output: data.NewFrame("wide_test", data.NewField("Time", nil, []time.Time{ @@ -230,17 +230,17 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 26, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), + util.Pointer(int64(10)), + util.Pointer(int64(12)), nil, - pointer.Int64(15), + util.Pointer(int64(15)), nil, }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), + util.Pointer(10.5), + util.Pointer(12.5), nil, - pointer.Float64(15.0), + util.Pointer(15.0), nil, })), }, @@ -260,16 +260,16 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 27, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(10), - pointer.Int64(12), - pointer.Int64(15), - pointer.Int64(18), + util.Pointer(int64(10)), + util.Pointer(int64(12)), + util.Pointer(int64(15)), + util.Pointer(int64(18)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(10.5), - pointer.Float64(12.5), - pointer.Float64(15.0), - pointer.Float64(17.5), + util.Pointer(10.5), + util.Pointer(12.5), + util.Pointer(15.0), + util.Pointer(17.5), })), output: data.NewFrame("wide_test", data.NewField("Time", nil, []time.Time{ @@ -280,18 +280,18 @@ func TestResampleWide(t *testing.T) { time.Date(2020, 1, 2, 3, 4, 24, 0, time.UTC), }), data.NewField("Values Ints", nil, []*int64{ - pointer.Int64(12), + util.Pointer(int64(12)), nil, nil, nil, - pointer.Int64(15), + util.Pointer(int64(15)), }), data.NewField(`Values Floats`, data.Labels{"Animal Factor": "sloth"}, []*float64{ - pointer.Float64(12.5), + util.Pointer(12.5), nil, nil, nil, - pointer.Float64(15.0), + util.Pointer(15.0), })), }, } diff --git a/pkg/tsdb/sqleng/sql_engine_test.go b/pkg/tsdb/sqleng/sql_engine_test.go index 81c4db1706b..307284684e3 100644 --- a/pkg/tsdb/sqleng/sql_engine_test.go +++ b/pkg/tsdb/sqleng/sql_engine_test.go @@ -11,9 +11,9 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data/sqlutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/infra/log" + "github.com/grafana/grafana/pkg/util" ) func TestSQLEngine(t *testing.T) { @@ -67,19 +67,19 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*int64{ - pointer.Int64(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time3", nil, []int64{ tMilliseconds, }), data.NewField("time4", nil, []*int64{ - pointer.Int64(tMilliseconds), + util.Pointer(tMilliseconds), }), data.NewField("time5", nil, []int64{ tNanoSeconds, }), data.NewField("time6", nil, []*int64{ - pointer.Int64(tNanoSeconds), + util.Pointer(tNanoSeconds), }), data.NewField("time7", nil, []*int64{ nilPointer, @@ -111,19 +111,19 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*uint64{ - pointer.Uint64(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time3", nil, []uint64{ tMilliseconds, }), data.NewField("time4", nil, []*uint64{ - pointer.Uint64(tMilliseconds), + util.Pointer(tMilliseconds), }), data.NewField("time5", nil, []uint64{ tNanoSeconds, }), data.NewField("time6", nil, []*uint64{ - pointer.Uint64(tNanoSeconds), + util.Pointer(tNanoSeconds), }), data.NewField("time7", nil, []*uint64{ nilPointer, @@ -153,7 +153,7 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*int32{ - pointer.Int32(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time7", nil, []*int32{ nilInt, @@ -178,7 +178,7 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*uint32{ - pointer.Uint32(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time7", nil, []*uint32{ nilInt, @@ -204,19 +204,19 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*float64{ - pointer.Float64(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time3", nil, []float64{ tMilliseconds, }), data.NewField("time4", nil, []*float64{ - pointer.Float64(tMilliseconds), + util.Pointer(tMilliseconds), }), data.NewField("time5", nil, []float64{ tNanoSeconds, }), data.NewField("time6", nil, []*float64{ - pointer.Float64(tNanoSeconds), + util.Pointer(tNanoSeconds), }), data.NewField("time7", nil, []*float64{ nilPointer, @@ -246,7 +246,7 @@ func TestSQLEngine(t *testing.T) { tSeconds, }), data.NewField("time2", nil, []*float32{ - pointer.Float32(tSeconds), + util.Pointer(tSeconds), }), data.NewField("time7", nil, []*float32{ nilInt, @@ -267,61 +267,61 @@ func TestSQLEngine(t *testing.T) { int64(1), }), data.NewField("value2", nil, []*int64{ - pointer.Int64(1), + util.Pointer(int64(1)), }), data.NewField("value3", nil, []int32{ int32(1), }), data.NewField("value4", nil, []*int32{ - pointer.Int32(1), + util.Pointer(int32(1)), }), data.NewField("value5", nil, []int16{ int16(1), }), data.NewField("value6", nil, []*int16{ - pointer.Int16(1), + util.Pointer(int16(1)), }), data.NewField("value7", nil, []int8{ int8(1), }), data.NewField("value8", nil, []*int8{ - pointer.Int8(1), + util.Pointer(int8(1)), }), data.NewField("value9", nil, []float64{ float64(1), }), data.NewField("value10", nil, []*float64{ - pointer.Float64(1), + util.Pointer(1.0), }), data.NewField("value11", nil, []float32{ float32(1), }), data.NewField("value12", nil, []*float32{ - pointer.Float32(1), + util.Pointer(float32(1)), }), data.NewField("value13", nil, []uint64{ uint64(1), }), data.NewField("value14", nil, []*uint64{ - pointer.Uint64(1), + util.Pointer(uint64(1)), }), data.NewField("value15", nil, []uint32{ uint32(1), }), data.NewField("value16", nil, []*uint32{ - pointer.Uint32(1), + util.Pointer(uint32(1)), }), data.NewField("value17", nil, []uint16{ uint16(1), }), data.NewField("value18", nil, []*uint16{ - pointer.Uint16(1), + util.Pointer(uint16(1)), }), data.NewField("value19", nil, []uint8{ uint8(1), }), data.NewField("value20", nil, []*uint8{ - pointer.Uint8(1), + util.Pointer(uint8(1)), }), ) for i := 0; i < len(originFrame.Fields); i++ { diff --git a/pkg/util/cmputil/reporter_test.go b/pkg/util/cmputil/reporter_test.go index 7aee4cd1532..b8c6e9b82d6 100644 --- a/pkg/util/cmputil/reporter_test.go +++ b/pkg/util/cmputil/reporter_test.go @@ -7,7 +7,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - ptr "github.com/xorcare/pointer" "github.com/grafana/grafana/pkg/util" ) @@ -111,11 +110,11 @@ func TestIsAddedDeleted_Collections(t *testing.T) { left := testStruct{} right := testStruct{ Number: rand.Float64(), - NumberPtr: ptr.Float64(rand.Float64()), + NumberPtr: util.Pointer(rand.Float64()), Text: util.GenerateShortUID(), - TextPtr: ptr.String(util.GenerateShortUID()), + TextPtr: util.Pointer(util.GenerateShortUID()), Flag: true, - FlagPtr: ptr.Bool(true), + FlagPtr: util.Pointer(true), SubStruct: subStruct{ Data: rand.Float64(), }, diff --git a/pkg/util/pointer.go b/pkg/util/pointer.go new file mode 100644 index 00000000000..f6b5d330c17 --- /dev/null +++ b/pkg/util/pointer.go @@ -0,0 +1,3 @@ +package util + +func Pointer[T any](v T) *T { return &v }