Skip to content

Commit

Permalink
Show a popup with an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ifrost committed Mar 5, 2021
1 parent 9e3993d commit b578683
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions public/app/plugins/datasource/graphite/datasource.ts
Expand Up @@ -10,6 +10,9 @@ import {
toDataFrame,
TimeRange,
} from '@grafana/data';
import { store } from 'app/store/store';
import { notifyApp } from 'app/core/actions';
import { createErrorNotification } from 'app/core/copy/appNotification';
import { isVersionGtOrEq, SemVersion } from 'app/core/utils/version';
import gfunc from './gfunc';
import { getBackendSrv } from '@grafana/runtime';
Expand All @@ -32,6 +35,8 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt
funcDefs: any = null;
funcDefsPromise: Promise<any> | null = null;
_seriesRefLetters: string;
// to avoid error flooding, it's shown only once per session
private _autoCompleteErrorShown = false;

constructor(instanceSettings: any, private readonly templateSrv: TemplateSrv = getTemplateSrv()) {
super(instanceSettings);
Expand Down Expand Up @@ -454,9 +459,10 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt
getTagsAutoComplete(expressions: any[], tagPrefix: any, optionalOptions: any) {
const options = optionalOptions || {};

const url = '/tags/autoComplete/tags';
const httpOptions: any = {
method: 'GET',
url: '/tags/autoComplete/tags',
url,
params: {
expr: _.map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
},
Expand Down Expand Up @@ -487,16 +493,18 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt
})
.catch((error) => {
console.error(error);
this.displayTagsAutocompleteAlert(error, url);
return [];
});
}

getTagValuesAutoComplete(expressions: any[], tag: any, valuePrefix: any, optionalOptions: any) {
const options = optionalOptions || {};

const url = '/tags/autoComplete/values';
const httpOptions: any = {
method: 'GET',
url: '/tags/autoComplete/values',
url,
params: {
expr: _.map(expressions, (expression) => this.templateSrv.replace((expression || '').trim())),
tag: this.templateSrv.replace((tag || '').trim()),
Expand Down Expand Up @@ -528,6 +536,7 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt
})
.catch((error) => {
console.error(error);
this.displayTagsAutocompleteAlert(error, url);
return [];
});
}
Expand Down Expand Up @@ -702,6 +711,13 @@ export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOpt

return cleanOptions;
}

private displayTagsAutocompleteAlert(error: Error, url: string): void {
if (!this._autoCompleteErrorShown) {
this._autoCompleteErrorShown = true;
store.dispatch(notifyApp(createErrorNotification(`${url} failed with: ${error.message}`)));
}
}
}

function supportsTags(version: string): boolean {
Expand Down

0 comments on commit b578683

Please sign in to comment.