Commit 50acb37a by Sriramajeyam Committed by Erik Sundell

Azure Monitor : Query more than 10 dimensions ( Fixes #17230 ) (#18693)

* Fixes #17230

* Resovled comments

* Resolved comments

* spell fix
parent a62dea47
......@@ -125,6 +125,7 @@ func (e *AzureMonitorDatasource) buildQueries(queries []*tsdb.Query, timeRange *
dimensionFilter := strings.TrimSpace(fmt.Sprintf("%v", azureMonitorTarget["dimensionFilter"]))
if azureMonitorTarget["dimension"] != nil && azureMonitorTarget["dimensionFilter"] != nil && len(dimension) > 0 && len(dimensionFilter) > 0 && dimension != "None" {
params.Add("$filter", fmt.Sprintf("%s eq '%s'", dimension, dimensionFilter))
params.Add("top", fmt.Sprintf("%v", azureMonitorTarget["top"]))
}
target = params.Encode()
......
......@@ -43,6 +43,7 @@ func TestAzureMonitorDatasource(t *testing.T) {
"metricDefinition": "Microsoft.Compute/virtualMachines",
"metricNamespace": "Microsoft.Compute-virtualMachines",
"metricName": "Percentage CPU",
"top": "10",
"alias": "testalias",
"queryType": "Azure Monitor",
},
......@@ -127,13 +128,14 @@ func TestAzureMonitorDatasource(t *testing.T) {
"queryType": "Azure Monitor",
"dimension": "blob",
"dimensionFilter": "*",
"top": "30",
},
})
queries, err := datasource.buildQueries(tsdbQuery.Queries, tsdbQuery.TimeRange)
So(err, ShouldBeNil)
So(queries[0].Target, ShouldEqual, "%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")
So(queries[0].Target, ShouldEqual, "%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&top=30")
})
......@@ -151,6 +153,7 @@ func TestAzureMonitorDatasource(t *testing.T) {
"queryType": "Azure Monitor",
"dimension": "None",
"dimensionFilter": "*",
"top": "10",
},
})
......
......@@ -75,6 +75,7 @@ export default class AzureMonitorDatasource {
const metricDefinition = this.templateSrv.replace(item.metricDefinition, options.scopedVars);
const timeGrain = this.templateSrv.replace((item.timeGrain || '').toString(), options.scopedVars);
const aggregation = this.templateSrv.replace(item.aggregation, options.scopedVars);
const top = this.templateSrv.replace(item.top || '', options.scopedVars);
return {
refId: target.refId,
......@@ -95,6 +96,7 @@ export default class AzureMonitorDatasource {
metricNamespace && metricNamespace !== this.defaultDropdownValue ? metricNamespace : metricDefinition,
aggregation: aggregation,
dimension: this.templateSrv.replace(item.dimension, options.scopedVars),
top: top || '10',
dimensionFilter: this.templateSrv.replace(item.dimensionFilter, options.scopedVars),
alias: item.alias,
format: target.format,
......
......@@ -91,6 +91,11 @@
<input type="text" class="gf-form-input width-17" ng-model="ctrl.target.azureMonitor.dimensionFilter"
spellcheck="false" placeholder="auto" ng-blur="ctrl.refresh()">
</div>
<div class="gf-form">
<label class="gf-form-label query-keyword width-9">Top</label>
<input type="text" class="gf-form-input width-3" ng-model="ctrl.target.azureMonitor.top"
spellcheck="false" placeholder="10" ng-blur="ctrl.refresh()">
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
......
......@@ -36,6 +36,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
allowedTimeGrainsMs: number[];
dimensions: any[];
dimension: any;
top: string;
aggregation: string;
aggOptions: string[];
};
......@@ -71,6 +72,7 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
metricName: this.defaultDropdownValue,
dimensionFilter: '*',
timeGrain: 'auto',
top: '10',
},
azureLogAnalytics: {
query: [
......
......@@ -41,6 +41,7 @@ export interface AzureMetricQuery {
dimension: string;
dimensionFilter: string;
alias: string;
top: string;
}
export interface AzureLogsQuery {
......
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