Commit 993e5636 by Dominik Prokop Committed by GitHub

Annotations: Fix failing annotation query when time series query is cancelled (#18532)

parent f689b604
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment