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