mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graphite: Handle invalid annotations (#32437)
* Handle invalid annotations * Add a test for handling invalid tags response * Unify test descriptions
This commit is contained in:
@@ -233,15 +233,14 @@ describe('graphiteDatasource', () => {
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
fetchMock.mockImplementation((options: any) => {
|
||||
return of(createFetchResponse(response));
|
||||
});
|
||||
|
||||
ctx.ds.annotationQuery(options).then((data: any) => {
|
||||
await ctx.ds.annotationQuery(options).then((data: any) => {
|
||||
results = data;
|
||||
});
|
||||
// ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it('should parse the tags string into an array', () => {
|
||||
@@ -251,6 +250,16 @@ describe('graphiteDatasource', () => {
|
||||
expect(results[0].tags[1]).toEqual('tag2');
|
||||
});
|
||||
});
|
||||
|
||||
it('and tags response is invalid', async () => {
|
||||
fetchMock.mockImplementation((options: any) => {
|
||||
return of(createFetchResponse('zzzzzzz'));
|
||||
});
|
||||
await ctx.ds.annotationQuery(options).then((data: any) => {
|
||||
results = data;
|
||||
});
|
||||
expect(results).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when fetching Graphite function descriptions', () => {
|
||||
|
||||
@@ -261,6 +261,10 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt
|
||||
const tags = this.templateSrv.replace(options.annotation.tags);
|
||||
return this.events({ range: options.range, tags: tags }).then((results: any) => {
|
||||
const list = [];
|
||||
if (!_.isArray(results.data)) {
|
||||
console.error(`Unable to get annotations from ${results.url}.`);
|
||||
return [];
|
||||
}
|
||||
for (let i = 0; i < results.data.length; i++) {
|
||||
const e = results.data[i];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user