From 05b1edb4a7a58d6d32ea8897363d606cb8a88f0f Mon Sep 17 00:00:00 2001 From: Isabella Siu Date: Wed, 6 Apr 2022 03:02:34 -0400 Subject: [PATCH] CloudWatch: re-add filter to handleMetricQueries (#47341) --- .../datasource/cloudwatch/datasource.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index 97f59886a0f..f1ae76f8aef 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -259,25 +259,27 @@ export class CloudWatchDatasource metricQueries: CloudWatchMetricsQuery[], options: DataQueryRequest ): Observable => { - const validMetricsQueries = metricQueries.map((item: CloudWatchMetricsQuery): MetricQuery => { - item.region = this.templateSrv.replace(this.getActualRegion(item.region), options.scopedVars); - item.namespace = this.replace(item.namespace, options.scopedVars, true, 'namespace'); - item.metricName = this.replace(item.metricName, options.scopedVars, true, 'metric name'); - item.dimensions = this.convertDimensionFormat(item.dimensions ?? {}, options.scopedVars); - item.statistic = this.templateSrv.replace(item.statistic, options.scopedVars); - item.period = String(this.getPeriod(item, options)); // use string format for period in graph query, and alerting - item.id = this.templateSrv.replace(item.id, options.scopedVars); - item.expression = this.templateSrv.replace(item.expression, options.scopedVars); - item.sqlExpression = this.templateSrv.replace(item.sqlExpression, options.scopedVars, 'raw'); - - return { - intervalMs: options.intervalMs, - maxDataPoints: options.maxDataPoints, - ...item, - type: 'timeSeriesQuery', - datasource: this.getRef(), - }; - }); + const validMetricsQueries = metricQueries + .filter(this.filterQuery) + .map((item: CloudWatchMetricsQuery): MetricQuery => { + item.region = this.templateSrv.replace(this.getActualRegion(item.region), options.scopedVars); + item.namespace = this.replace(item.namespace, options.scopedVars, true, 'namespace'); + item.metricName = this.replace(item.metricName, options.scopedVars, true, 'metric name'); + item.dimensions = this.convertDimensionFormat(item.dimensions ?? {}, options.scopedVars); + item.statistic = this.templateSrv.replace(item.statistic, options.scopedVars); + item.period = String(this.getPeriod(item, options)); // use string format for period in graph query, and alerting + item.id = this.templateSrv.replace(item.id, options.scopedVars); + item.expression = this.templateSrv.replace(item.expression, options.scopedVars); + item.sqlExpression = this.templateSrv.replace(item.sqlExpression, options.scopedVars, 'raw'); + + return { + intervalMs: options.intervalMs, + maxDataPoints: options.maxDataPoints, + ...item, + type: 'timeSeriesQuery', + datasource: this.getRef(), + }; + }); // No valid targets, return the empty result to save a round trip. if (isEmpty(validMetricsQueries)) {