Graphite: Fallback to hardcoded list of functions when no functions are returned (#46681) (#46688)

(cherry picked from commit ed155e47c4)

Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-03-30 09:52:47 +02:00
committed by GitHub
co-authored by Piotr Jamróz
parent 3bcf117344
commit 703308f31a
2 changed files with 17 additions and 0 deletions
@@ -292,6 +292,14 @@ describe('graphiteDatasource', () => {
},
});
});
it('should use hardcoded list of functions when no functions are returned', async () => {
fetchMock.mockImplementation(() => {
return of(createFetchResponse('{}'));
});
const funcDefs = await ctx.ds.getFuncDefs();
expect(Object.keys(funcDefs)).not.toHaveLength(0);
});
});
describe('building graphite params', () => {
@@ -769,6 +769,15 @@ export class GraphiteDatasource
} else {
this.funcDefs = gfunc.parseFuncDefs(results.data);
}
// When /functions endpoint returns application/json response but containing invalid JSON the fix above
// wont' be triggered due to the changes in https://github.com/grafana/grafana/pull/45598 (parsing happens
// in fetch and Graphite receives an empty object and no error). In such cases, when the provided JSON
// seems empty we fallback to the hardcoded list of functions.
// See also: https://github.com/grafana/grafana/issues/45948
if (Object.keys(this.funcDefs).length === 0) {
this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
}
return this.funcDefs;
}),
catchError((error: any) => {