mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graphite: Display an error message when finding metrics fails (#32639)
* Display an error when finding metrics fails * Update public/app/plugins/datasource/graphite/query_ctrl.ts Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * Make the level of the log message more accurate Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
parent
7749724194
commit
fa45fc1833
@ -24,8 +24,9 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
supportsTags: boolean;
|
||||
paused: boolean;
|
||||
|
||||
// to avoid error flooding, it's shown only once per session
|
||||
// to avoid error flooding, these errors are shown only once per session
|
||||
private _tagsAutoCompleteErrorShown = false;
|
||||
private _metricAutoCompleteErrorShown = false;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(
|
||||
@ -110,7 +111,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
})
|
||||
.catch((err: any) => {
|
||||
dispatch(notifyApp(createErrorNotification('Error', err)));
|
||||
this.handleMetricsAutoCompleteError(err);
|
||||
});
|
||||
}
|
||||
|
||||
@ -183,6 +184,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
})
|
||||
.catch((err: any): any[] => {
|
||||
this.handleMetricsAutoCompleteError(err);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
@ -431,12 +433,20 @@ export class GraphiteQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
private handleTagsAutoCompleteError(error: Error): void {
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
if (!this._tagsAutoCompleteErrorShown) {
|
||||
this._tagsAutoCompleteErrorShown = true;
|
||||
dispatch(notifyApp(createErrorNotification(`Fetching tags failed: ${error.message}.`)));
|
||||
}
|
||||
}
|
||||
|
||||
private handleMetricsAutoCompleteError(error: Error): void {
|
||||
console.error(error);
|
||||
if (!this._metricAutoCompleteErrorShown) {
|
||||
this._metricAutoCompleteErrorShown = true;
|
||||
dispatch(notifyApp(createErrorNotification(`Fetching metrics failed: ${error.message}.`)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mapToDropdownOptions(results: any[]) {
|
||||
|
@ -193,10 +193,61 @@ describe('GraphiteQueryCtrl', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when autocomplete for metric names is not available', () => {
|
||||
silenceConsoleOutput();
|
||||
beforeEach(() => {
|
||||
ctx.ctrl.datasource.getTagsAutoComplete = jest.fn().mockReturnValue(Promise.resolve([]));
|
||||
ctx.ctrl.datasource.metricFindQuery = jest.fn().mockReturnValue(
|
||||
new Promise(() => {
|
||||
throw new Error();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('getAltSegments should handle autocomplete errors', async () => {
|
||||
await expect(async () => {
|
||||
await ctx.ctrl.getAltSegments(0, 'any');
|
||||
expect(mockDispatch).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'appNotifications/notifyApp',
|
||||
})
|
||||
);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('getAltSegments should display the error message only once', async () => {
|
||||
await ctx.ctrl.getAltSegments(0, 'any');
|
||||
expect(mockDispatch.mock.calls.length).toBe(1);
|
||||
|
||||
await ctx.ctrl.getAltSegments(0, 'any');
|
||||
expect(mockDispatch.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('checkOtherSegments should handle autocomplete errors', async () => {
|
||||
await expect(async () => {
|
||||
await ctx.ctrl.checkOtherSegments(1, false);
|
||||
expect(mockDispatch).toBeCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'appNotifications/notifyApp',
|
||||
})
|
||||
);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('checkOtherSegments should display the error message only once', async () => {
|
||||
await ctx.ctrl.checkOtherSegments(1, false);
|
||||
expect(mockDispatch.mock.calls.length).toBe(1);
|
||||
|
||||
await ctx.ctrl.checkOtherSegments(1, false);
|
||||
expect(mockDispatch.mock.calls.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when autocomplete for tags is not available', () => {
|
||||
silenceConsoleOutput();
|
||||
beforeEach(() => {
|
||||
ctx.ctrl.datasource.getTagsAutoComplete.mockReturnValue(
|
||||
ctx.datasource.metricFindQuery = jest.fn().mockReturnValue(Promise.resolve([]));
|
||||
ctx.datasource.getTagsAutoComplete = jest.fn().mockReturnValue(
|
||||
new Promise(() => {
|
||||
throw new Error();
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user