Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphite: Display an error message when finding metrics fails #32639

Merged
merged 5 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions public/app/plugins/datasource/graphite/query_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -110,7 +111,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
}
})
.catch((err: any) => {
dispatch(notifyApp(createErrorNotification('Error', err)));
this.handleMetricsAutoCompleteError(err);
});
}

Expand Down Expand Up @@ -183,6 +184,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
}
})
.catch((err: any): any[] => {
this.handleMetricsAutoCompleteError(err);
return [];
});
}
Expand Down Expand Up @@ -437,6 +439,14 @@ export class GraphiteQueryCtrl extends QueryCtrl {
dispatch(notifyApp(createErrorNotification(`Fetching tags failed: ${error.message}.`)));
}
}

private handleMetricsAutoCompleteError(error: Error): void {
console.log(error);
ifrost marked this conversation as resolved.
Show resolved Hide resolved
if (!this._metricAutoCompleteErrorShown) {
this._metricAutoCompleteErrorShown = true;
dispatch(notifyApp(createErrorNotification(`Fetching metrics failed: ${error.message}.`)));
}
}
}

function mapToDropdownOptions(results: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
Expand Down