Commit c9a5d1ad by Kyle Brandt Committed by GitHub

AzureMonitor: pass through null values instead of 0 (#28126)

fixes #28001
parent 7e18ca7e
...@@ -288,7 +288,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A ...@@ -288,7 +288,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A
labels[md.Name.LocalizedValue] = md.Value labels[md.Name.LocalizedValue] = md.Value
} }
frame := data.NewFrameOfFieldTypes("", len(series.Data), data.FieldTypeTime, data.FieldTypeFloat64) frame := data.NewFrameOfFieldTypes("", len(series.Data), data.FieldTypeTime, data.FieldTypeNullableFloat64)
frame.RefID = query.RefID frame.RefID = query.RefID
dataField := frame.Fields[1] dataField := frame.Fields[1]
dataField.Name = amr.Value[0].Name.LocalizedValue dataField.Name = amr.Value[0].Name.LocalizedValue
...@@ -314,7 +314,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A ...@@ -314,7 +314,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A
requestedAgg := query.Params.Get("aggregation") requestedAgg := query.Params.Get("aggregation")
for i, point := range series.Data { for i, point := range series.Data {
var value float64 var value *float64
switch requestedAgg { switch requestedAgg {
case "Average": case "Average":
value = point.Average value = point.Average
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/tsdb" "github.com/grafana/grafana/pkg/tsdb"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ptr "github.com/xorcare/pointer"
) )
func TestAzureMonitorBuildQueries(t *testing.T) { func TestAzureMonitorBuildQueries(t *testing.T) {
...@@ -199,8 +200,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -199,8 +200,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
2.0875, 2.1525, 2.155, 3.6925, 2.44, ptr.Float64(2.0875), ptr.Float64(2.1525), ptr.Float64(2.155), ptr.Float64(3.6925), ptr.Float64(2.44),
}).SetConfig(&data.FieldConfig{Unit: "percent"})), }).SetConfig(&data.FieldConfig{Unit: "percent"})),
}, },
}, },
...@@ -219,8 +220,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -219,8 +220,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
8.26, 8.7, 14.82, 10.07, 8.52, ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52),
}).SetConfig(&data.FieldConfig{Unit: "percent"})), }).SetConfig(&data.FieldConfig{Unit: "percent"})),
}, },
}, },
...@@ -239,8 +240,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -239,8 +240,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 14, 26, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 9, 14, 26, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
3.07, 2.92, 2.87, 2.27, 2.52, ptr.Float64(3.07), ptr.Float64(2.92), ptr.Float64(2.87), ptr.Float64(2.27), ptr.Float64(2.52),
}).SetConfig(&data.FieldConfig{Unit: "percent"})), }).SetConfig(&data.FieldConfig{Unit: "percent"})),
}, },
}, },
...@@ -259,8 +260,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -259,8 +260,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 14, 43, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 9, 14, 43, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
1.51, 2.38, 1.69, 2.27, 1.96, ptr.Float64(1.51), ptr.Float64(2.38), ptr.Float64(1.69), ptr.Float64(2.27), ptr.Float64(1.96),
}).SetConfig(&data.FieldConfig{Unit: "percent"})), }).SetConfig(&data.FieldConfig{Unit: "percent"})),
}, },
}, },
...@@ -279,8 +280,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -279,8 +280,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 14, 44, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 9, 14, 44, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
4, 4, 4, 4, 4, ptr.Float64(4), ptr.Float64(4), ptr.Float64(4), ptr.Float64(4), ptr.Float64(4),
}).SetConfig(&data.FieldConfig{Unit: "percent"})), }).SetConfig(&data.FieldConfig{Unit: "percent"})),
}, },
}, },
...@@ -300,19 +301,19 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -300,19 +301,19 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"}, data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "short"})), []*float64{ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), ptr.Float64(3), nil}).SetConfig(&data.FieldConfig{Unit: "short"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"},
[]float64{1, 1, 1, 1, 1, 0}).SetConfig(&data.FieldConfig{Unit: "short"})), []*float64{ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), nil}).SetConfig(&data.FieldConfig{Unit: "short"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"},
[]float64{0, 0, 0, 0, 0, 0}).SetConfig(&data.FieldConfig{Unit: "short"})), []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), nil}).SetConfig(&data.FieldConfig{Unit: "short"})),
}, },
}, },
{ {
...@@ -331,8 +332,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -331,8 +332,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)), makeDates(time.Date(2019, 2, 9, 13, 29, 0, 0, time.UTC), 5, time.Minute)),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
8.26, 8.7, 14.82, 10.07, 8.52, ptr.Float64(8.26), ptr.Float64(8.7), ptr.Float64(14.82), ptr.Float64(10.07), ptr.Float64(8.52),
}).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"})), }).SetConfig(&data.FieldConfig{Unit: "percent", DisplayName: "custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"})),
}, },
}, },
...@@ -353,20 +354,20 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -353,20 +354,20 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"}, data.NewField("Blob Count", data.Labels{"blobtype": "PageBlob"},
[]float64{3, 3, 3, 3, 3, 0}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "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"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, []float64{ data.NewField("Blob Count", data.Labels{"blobtype": "BlockBlob"}, []*float64{
1, 1, 1, 1, 1, 0, ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), ptr.Float64(1), nil,
}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=BlockBlob"})), }).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=BlockBlob"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)), makeDates(time.Date(2019, 2, 9, 15, 21, 0, 0, time.UTC), 6, time.Hour)),
data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, []float64{ data.NewField("Blob Count", data.Labels{"blobtype": "Azure Data Lake Storage"}, []*float64{
0, 0, 0, 0, 0, 0, ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), ptr.Float64(0), nil,
}).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=Azure Data Lake Storage"})), }).SetConfig(&data.FieldConfig{Unit: "short", DisplayName: "blobtype=Azure Data Lake Storage"})),
}, },
}, },
...@@ -387,21 +388,21 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -387,21 +388,21 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)), makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
data.NewField("Blob Capacity", data.Labels{"blobtype": "PageBlob", "tier": "Standard"}, data.NewField("Blob Capacity", data.Labels{"blobtype": "PageBlob", "tier": "Standard"},
[]float64{675530, 675530, 675530}).SetConfig( []*float64{ptr.Float64(675530), ptr.Float64(675530), ptr.Float64(675530)}).SetConfig(
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=PageBlob, Tier=Standard}"})), &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=PageBlob, Tier=Standard}"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)), makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
data.NewField("Blob Capacity", data.Labels{"blobtype": "BlockBlob", "tier": "Hot"}, data.NewField("Blob Capacity", data.Labels{"blobtype": "BlockBlob", "tier": "Hot"},
[]float64{0, 0, 0}).SetConfig( []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0)}).SetConfig(
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=BlockBlob, Tier=Hot}"})), &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=BlockBlob, Tier=Hot}"})),
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)), makeDates(time.Date(2020, 06, 30, 9, 58, 0, 0, time.UTC), 3, time.Hour)),
data.NewField("Blob Capacity", data.Labels{"blobtype": "Azure Data Lake Storage", "tier": "Cool"}, data.NewField("Blob Capacity", data.Labels{"blobtype": "Azure Data Lake Storage", "tier": "Cool"},
[]float64{0, 0, 0}).SetConfig( []*float64{ptr.Float64(0), ptr.Float64(0), ptr.Float64(0)}).SetConfig(
&data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"})), &data.FieldConfig{Unit: "decbytes", DisplayName: "danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"})),
}, },
}, },
...@@ -421,8 +422,8 @@ func TestAzureMonitorParseResponse(t *testing.T) { ...@@ -421,8 +422,8 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data.NewFrame("", data.NewFrame("",
data.NewField("", nil, data.NewField("", nil,
[]time.Time{time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC)}), []time.Time{time.Date(2019, 2, 8, 10, 13, 0, 0, time.UTC)}),
data.NewField("Percentage CPU", nil, []float64{ data.NewField("Percentage CPU", nil, []*float64{
2.0875, ptr.Float64(2.0875),
}).SetConfig(&data.FieldConfig{DisplayName: "custom"})), }).SetConfig(&data.FieldConfig{DisplayName: "custom"})),
}, },
}, },
......
...@@ -42,11 +42,11 @@ type AzureMonitorResponse struct { ...@@ -42,11 +42,11 @@ type AzureMonitorResponse struct {
} `json:"metadatavalues"` } `json:"metadatavalues"`
Data []struct { Data []struct {
TimeStamp time.Time `json:"timeStamp"` TimeStamp time.Time `json:"timeStamp"`
Average float64 `json:"average,omitempty"` Average *float64 `json:"average,omitempty"`
Total float64 `json:"total,omitempty"` Total *float64 `json:"total,omitempty"`
Count float64 `json:"count,omitempty"` Count *float64 `json:"count,omitempty"`
Maximum float64 `json:"maximum,omitempty"` Maximum *float64 `json:"maximum,omitempty"`
Minimum float64 `json:"minimum,omitempty"` Minimum *float64 `json:"minimum,omitempty"`
} `json:"data"` } `json:"data"`
} `json:"timeseries"` } `json:"timeseries"`
} `json:"value"` } `json:"value"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment