mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Annotations: Fix failing annotation query when time series query is cancelled (#18532)
This commit is contained in:
@@ -41,6 +41,7 @@ export interface PromDataQueryResponse {
|
||||
result?: DataQueryResponseData[];
|
||||
};
|
||||
};
|
||||
cancelled?: boolean;
|
||||
}
|
||||
|
||||
export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions> {
|
||||
@@ -528,6 +529,9 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
||||
const eventList: AnnotationEvent[] = [];
|
||||
tagKeys = tagKeys.split(',');
|
||||
|
||||
if (results.cancelled) {
|
||||
return [];
|
||||
}
|
||||
_.each(results.data.data.result, series => {
|
||||
const tags = _.chain(series.metric)
|
||||
.filter((v, k) => {
|
||||
|
||||
@@ -667,6 +667,19 @@ describe('PrometheusDatasource', () => {
|
||||
},
|
||||
};
|
||||
|
||||
describe('when time series query is cancelled', () => {
|
||||
it('should return empty results', async () => {
|
||||
backendSrv.datasourceRequest = jest.fn(() => Promise.resolve({ cancelled: true }));
|
||||
ctx.ds = new PrometheusDatasource(instanceSettings, q, backendSrv as any, templateSrv as any, timeSrv as any);
|
||||
|
||||
await ctx.ds.annotationQuery(options).then((data: any) => {
|
||||
results = data;
|
||||
});
|
||||
|
||||
expect(results).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('not use useValueForTime', () => {
|
||||
beforeEach(async () => {
|
||||
options.annotation.useValueForTime = false;
|
||||
|
||||
Reference in New Issue
Block a user