mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
allow search queries without dimensions (#42800)
This commit is contained in:
parent
39ac11d300
commit
c3208c1850
@ -132,21 +132,26 @@ describe('datasource', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not allow queries that dont have `matchExact` or dimensions', async () => {
|
it('should not allow builder queries that dont have namespace, metric or statistic', async () => {
|
||||||
const valid = datasource.filterMetricQuery(baseQuery);
|
expect(datasource.filterMetricQuery({ ...baseQuery, statistic: undefined })).toBeFalsy();
|
||||||
expect(valid).toBeFalsy();
|
expect(datasource.filterMetricQuery({ ...baseQuery, metricName: undefined })).toBeFalsy();
|
||||||
|
expect(datasource.filterMetricQuery({ ...baseQuery, namespace: '' })).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow queries that have `matchExact`', async () => {
|
it('should allow builder queries that have namespace, metric or statistic', async () => {
|
||||||
baseQuery.matchExact = false;
|
expect(datasource.filterMetricQuery(baseQuery)).toBeTruthy();
|
||||||
const valid = datasource.filterMetricQuery(baseQuery);
|
|
||||||
expect(valid).toBeTruthy();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow queries that have dimensions', async () => {
|
it('should not allow code queries that dont have an expression', async () => {
|
||||||
baseQuery.dimensions = { instanceId: ['xyz'] };
|
expect(
|
||||||
const valid = datasource.filterMetricQuery(baseQuery);
|
datasource.filterMetricQuery({ ...baseQuery, expression: undefined, metricEditorMode: MetricEditorMode.Code })
|
||||||
expect(valid).toBeTruthy();
|
).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) {
|
if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Builder) {
|
||||||
return (
|
return !!namespace && !!metricName && !!statistic;
|
||||||
!!namespace &&
|
|
||||||
!!metricName &&
|
|
||||||
!!statistic &&
|
|
||||||
(('matchExact' in rest && !rest.matchExact) || !isEmpty(dimensions))
|
|
||||||
);
|
|
||||||
} else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) {
|
} else if (metricQueryType === MetricQueryType.Search && metricEditorMode === MetricEditorMode.Code) {
|
||||||
return !!expression;
|
return !!expression;
|
||||||
} else if (metricQueryType === MetricQueryType.Query) {
|
} else if (metricQueryType === MetricQueryType.Query) {
|
||||||
|
Loading…
Reference in New Issue
Block a user