mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graphite: Fallback to hardcoded list of functions when no functions are returned (#46681)
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user