mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Handle annotation query with empty fields (#63560)
Handle annotation query with empty fields
This commit is contained in:
parent
f925a989d3
commit
3d75dbc31e
@ -191,6 +191,7 @@ describe('PrometheusDatasource', () => {
|
||||
|
||||
describe('customQueryParams', () => {
|
||||
const target = { expr: 'test{job="testjob"}', format: 'time_series', refId: '' };
|
||||
|
||||
function makeQuery(target: PromQuery) {
|
||||
return {
|
||||
range: { from: time({ seconds: 63 }), to: time({ seconds: 183 }) },
|
||||
@ -975,6 +976,19 @@ describe('PrometheusDatasource2', () => {
|
||||
} as unknown as AnnotationQueryRequest<PromQuery>;
|
||||
|
||||
const response = createAnnotationResponse();
|
||||
const emptyResponse = createEmptyAnnotationResponse();
|
||||
|
||||
describe('handle result with empty fields', () => {
|
||||
it('should return empty results', async () => {
|
||||
fetchMock.mockImplementation(() => of(emptyResponse));
|
||||
|
||||
await ds.annotationQuery(options).then((data) => {
|
||||
results = data;
|
||||
});
|
||||
|
||||
expect(results.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when time series query is cancelled', () => {
|
||||
it('should return empty results', async () => {
|
||||
@ -2399,3 +2413,28 @@ function createAnnotationResponse() {
|
||||
|
||||
return { ...response };
|
||||
}
|
||||
|
||||
function createEmptyAnnotationResponse() {
|
||||
const response = {
|
||||
data: {
|
||||
results: {
|
||||
X: {
|
||||
frames: [
|
||||
{
|
||||
schema: {
|
||||
name: 'bar',
|
||||
refId: 'X',
|
||||
fields: [],
|
||||
},
|
||||
data: {
|
||||
values: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return { ...response };
|
||||
}
|
||||
|
@ -830,6 +830,9 @@ export class PrometheusDatasource
|
||||
const eventList: AnnotationEvent[] = [];
|
||||
|
||||
for (const frame of frames) {
|
||||
if (frame.fields.length === 0) {
|
||||
continue;
|
||||
}
|
||||
const timeField = frame.fields[0];
|
||||
const valueField = frame.fields[1];
|
||||
const labels = valueField?.labels || {};
|
||||
|
Loading…
Reference in New Issue
Block a user