diff --git a/public/app/plugins/datasource/cloudwatch/datasource.test.ts b/public/app/plugins/datasource/cloudwatch/datasource.test.ts index 02dc92d1aaa..e10995a616d 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.test.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.test.ts @@ -132,21 +132,26 @@ describe('datasource', () => { }; }); - it('should not allow queries that dont have `matchExact` or dimensions', async () => { - const valid = datasource.filterMetricQuery(baseQuery); - expect(valid).toBeFalsy(); + it('should not allow builder queries that dont have namespace, metric or statistic', async () => { + expect(datasource.filterMetricQuery({ ...baseQuery, statistic: undefined })).toBeFalsy(); + expect(datasource.filterMetricQuery({ ...baseQuery, metricName: undefined })).toBeFalsy(); + expect(datasource.filterMetricQuery({ ...baseQuery, namespace: '' })).toBeFalsy(); }); - it('should allow queries that have `matchExact`', async () => { - baseQuery.matchExact = false; - const valid = datasource.filterMetricQuery(baseQuery); - expect(valid).toBeTruthy(); + it('should allow builder queries that have namespace, metric or statistic', async () => { + expect(datasource.filterMetricQuery(baseQuery)).toBeTruthy(); }); - it('should allow queries that have dimensions', async () => { - baseQuery.dimensions = { instanceId: ['xyz'] }; - const valid = datasource.filterMetricQuery(baseQuery); - expect(valid).toBeTruthy(); + it('should not allow code queries that dont have an expression', async () => { + expect( + datasource.filterMetricQuery({ ...baseQuery, expression: undefined, metricEditorMode: MetricEditorMode.Code }) + ).toBeFalsy(); + }); + + it('should allow code queries that have an expression', async () => { + expect( + datasource.filterMetricQuery({ ...baseQuery, expression: 'x * 2', metricEditorMode: MetricEditorMode.Code }) + ).toBeTruthy(); }); }); diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index 3701c9a9df1..e30e77c081e 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -243,12 +243,7 @@ export class CloudWatchDatasource } if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Builder) { - return ( - !!namespace && - !!metricName && - !!statistic && - (('matchExact' in rest && !rest.matchExact) || !isEmpty(dimensions)) - ); + return !!namespace && !!metricName && !!statistic; } else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) { return !!expression; } else if (metricQueryType === MetricQueryType.Query) {