allow search queries without dimensions (#42800)

pull/42829/head
Erik Sundell 4 years ago committed by GitHub
parent 39ac11d300
commit c3208c1850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      public/app/plugins/datasource/cloudwatch/datasource.test.ts
  2. 7
      public/app/plugins/datasource/cloudwatch/datasource.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();
});
});

@ -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) {

Loading…
Cancel
Save