AzureMonitor: Fix missing top parameter when dimensions are set (#47010) (#47017)

(cherry picked from commit 48113beeeb)

Co-authored-by: Andres Martinez Gotor <andres.mgotor@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-03-29 17:43:59 +02:00
committed by GitHub
co-authored by Andres Martinez Gotor
parent 5ed397b8d2
commit 3bcf117344
2 changed files with 14 additions and 1 deletions
@@ -126,7 +126,9 @@ func (e *AzureMonitorDatasource) buildQueries(queries []backend.DataQuery, dsInf
if dimSB.String() != "" {
params.Add("$filter", dimSB.String())
params.Add("top", azJSONModel.Top)
if azJSONModel.Top != "" {
params.Add("top", azJSONModel.Top)
}
}
target = params.Encode()
@@ -114,6 +114,17 @@ func TestAzureMonitorBuildQueries(t *testing.T) {
expectedInterval: "PT1M",
azureMonitorQueryTarget: "%24filter=blob+eq+%27%2A%27+and+tier+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute-virtualMachines&timespan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z&top=30",
},
{
name: "has a dimension filter without specifying a top",
azureMonitorVariedProperties: map[string]interface{}{
"timeGrain": "PT1M",
"dimension": "blob",
"dimensionFilter": "*",
},
queryInterval: duration,
expectedInterval: "PT1M",
azureMonitorQueryTarget: "%24filter=blob+eq+%27%2A%27&aggregation=Average&api-version=2018-01-01&interval=PT1M&metricnames=Percentage+CPU&metricnamespace=Microsoft.Compute-virtualMachines&timespan=2018-03-15T13%3A00%3A00Z%2F2018-03-15T13%3A34%3A00Z",
},
}
commonAzureModelProps := map[string]interface{}{