diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index 8b7ca518e8b..d582b6a3b18 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -170,7 +170,9 @@ export class BackendSrv { return this.$http(options) .then(response => { - appEvents.emit('ds-request-response', response); + if (!options.silent) { + appEvents.emit('ds-request-response', response); + } return response; }) .catch(err => { @@ -201,8 +203,9 @@ export class BackendSrv { if (err.data && !err.data.message && _.isString(err.data.error)) { err.data.message = err.data.error; } - - appEvents.emit('ds-request-error', err); + if (!options.silent) { + appEvents.emit('ds-request-error', err); + } throw err; }) .finally(() => { diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 6cf6c713a90..3eceaf6c622 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -81,6 +81,20 @@ export class PrometheusDatasource { return this.backendSrv.datasourceRequest(options); } + // Use this for tab completion features, wont publish response to other components + helperRequest(url) { + const options: any = { + url: this.url + url, + silent: true, + }; + + if (this.basicAuth || this.withCredentials) { + options.withCredentials = true; + } + + return this.backendSrv.datasourceRequest(options); + } + interpolateQueryExpr(value, variable, defaultFormatFn) { // if no multi or include all do not regexEscape if (!variable.multi && !variable.includeAll) { @@ -229,7 +243,7 @@ export class PrometheusDatasource { ); } - return this._request('GET', url).then(result => { + return this.helperRequest(url).then(result => { this.metricsNameCache = { data: result.data.data, expire: Date.now() + 60 * 1000, diff --git a/public/app/plugins/datasource/prometheus/metric_find_query.ts b/public/app/plugins/datasource/prometheus/metric_find_query.ts index b27f1cd50af..c58f5c097b9 100644 --- a/public/app/plugins/datasource/prometheus/metric_find_query.ts +++ b/public/app/plugins/datasource/prometheus/metric_find_query.ts @@ -46,7 +46,7 @@ export default class PrometheusMetricFindQuery { // return label values globally url = '/api/v1/label/' + label + '/values'; - return this.datasource._request('GET', url).then(function(result) { + return this.datasource.helperRequest(url).then(function(result) { return _.map(result.data.data, function(value) { return { text: value }; }); @@ -56,7 +56,7 @@ export default class PrometheusMetricFindQuery { var end = this.datasource.getPrometheusTime(this.range.to, true); url = '/api/v1/series?match[]=' + encodeURIComponent(metric) + '&start=' + start + '&end=' + end; - return this.datasource._request('GET', url).then(function(result) { + return this.datasource.helperRequest(url).then(function(result) { var _labels = _.map(result.data.data, function(metric) { return metric[label] || ''; }).filter(function(label) { @@ -76,7 +76,7 @@ export default class PrometheusMetricFindQuery { metricNameQuery(metricFilterPattern) { var url = '/api/v1/label/__name__/values'; - return this.datasource._request('GET', url).then(function(result) { + return this.datasource.helperRequest(url).then(function(result) { return _.chain(result.data.data) .filter(function(metricName) { var r = new RegExp(metricFilterPattern); @@ -120,7 +120,7 @@ export default class PrometheusMetricFindQuery { var url = '/api/v1/series?match[]=' + encodeURIComponent(query) + '&start=' + start + '&end=' + end; var self = this; - return this.datasource._request('GET', url).then(function(result) { + return this.datasource.helperRequest(url).then(function(result) { return _.map(result.data.data, function(metric) { return { text: self.datasource.getOriginalMetricName(metric),