From fb5ff6a70f1c4e28c43bcf89c97e8257a875640e Mon Sep 17 00:00:00 2001 From: Kyle Brandt Date: Tue, 21 Jul 2020 10:24:55 -0400 Subject: [PATCH] Azure: Insights metrics - do not sort if no data (#26486) fixes #26473 --- pkg/tsdb/azuremonitor/applicationinsights-metrics.go | 4 ++++ .../azuremonitor/applicationinsights-metrics_test.go | 10 ++++++++++ .../5-application-insights-empty-response.json | 1 + 3 files changed, 15 insertions(+) create mode 100644 pkg/tsdb/azuremonitor/testdata/applicationinsights/5-application-insights-empty-response.json diff --git a/pkg/tsdb/azuremonitor/applicationinsights-metrics.go b/pkg/tsdb/azuremonitor/applicationinsights-metrics.go index 0573f7d5e69..f6f547f3eb4 100644 --- a/pkg/tsdb/azuremonitor/applicationinsights-metrics.go +++ b/pkg/tsdb/azuremonitor/applicationinsights-metrics.go @@ -107,6 +107,10 @@ func InsightsMetricsResultToFrame(mr MetricsResult, metric, agg string, dimensio rowCounter++ } + if len(frame.Fields) == 1 { // No data, only a time column, no sort + return frame, nil + } + if err := data.SortWideFrameFields(frame, dimensions...); err != nil { return nil, err } diff --git a/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go b/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go index 079e73f939a..20c205a5182 100644 --- a/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go +++ b/pkg/tsdb/azuremonitor/applicationinsights-metrics_test.go @@ -42,6 +42,16 @@ func TestInsightsMetricsResultToFrame(t *testing.T) { return frame }, }, + { + name: "empty response", + testFile: "applicationinsights/5-application-insights-empty-response.json", + metric: "value", + agg: "avg", + expectedFrame: func() *data.Frame { + frame := data.NewFrame("", data.NewField("StartTime", nil, []time.Time{})) + return frame + }, + }, { name: "segmented series", testFile: "applicationinsights/4-application-insights-response-metrics-segmented.json", diff --git a/pkg/tsdb/azuremonitor/testdata/applicationinsights/5-application-insights-empty-response.json b/pkg/tsdb/azuremonitor/testdata/applicationinsights/5-application-insights-empty-response.json new file mode 100644 index 00000000000..38d46c42b8f --- /dev/null +++ b/pkg/tsdb/azuremonitor/testdata/applicationinsights/5-application-insights-empty-response.json @@ -0,0 +1 @@ +{"value":{"start":"2020-07-21T11:55:15.000Z","end":"2020-07-21T11:56:15.000Z","interval":"PT1M","segments":[]}} \ No newline at end of file