mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add silent option to backend requests
* When set to `true`, the `silent` option for backend_srv requests suppresses all event emitters that are triggered when the response is received. * Added `helperRequest()` to the Prometheus datasource to support requests that are not triggered by the user, e.g., for tab completion. `helperRequest()` sets the `silent` option. * Migrated all non-timeseries queries of the Prometheus datasource to use `helperRequest()`. Fixes #11673
This commit is contained in:
parent
e168bfe03e
commit
53817b7429
@ -170,7 +170,9 @@ export class BackendSrv {
|
|||||||
|
|
||||||
return this.$http(options)
|
return this.$http(options)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
appEvents.emit('ds-request-response', response);
|
if (!options.silent) {
|
||||||
|
appEvents.emit('ds-request-response', response);
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
@ -201,8 +203,9 @@ export class BackendSrv {
|
|||||||
if (err.data && !err.data.message && _.isString(err.data.error)) {
|
if (err.data && !err.data.message && _.isString(err.data.error)) {
|
||||||
err.data.message = err.data.error;
|
err.data.message = err.data.error;
|
||||||
}
|
}
|
||||||
|
if (!options.silent) {
|
||||||
appEvents.emit('ds-request-error', err);
|
appEvents.emit('ds-request-error', err);
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -81,6 +81,20 @@ export class PrometheusDatasource {
|
|||||||
return this.backendSrv.datasourceRequest(options);
|
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) {
|
interpolateQueryExpr(value, variable, defaultFormatFn) {
|
||||||
// if no multi or include all do not regexEscape
|
// if no multi or include all do not regexEscape
|
||||||
if (!variable.multi && !variable.includeAll) {
|
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 = {
|
this.metricsNameCache = {
|
||||||
data: result.data.data,
|
data: result.data.data,
|
||||||
expire: Date.now() + 60 * 1000,
|
expire: Date.now() + 60 * 1000,
|
||||||
|
@ -46,7 +46,7 @@ export default class PrometheusMetricFindQuery {
|
|||||||
// return label values globally
|
// return label values globally
|
||||||
url = '/api/v1/label/' + label + '/values';
|
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 _.map(result.data.data, function(value) {
|
||||||
return { text: value };
|
return { text: value };
|
||||||
});
|
});
|
||||||
@ -56,7 +56,7 @@ export default class PrometheusMetricFindQuery {
|
|||||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||||
url = '/api/v1/series?match[]=' + encodeURIComponent(metric) + '&start=' + start + '&end=' + end;
|
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) {
|
var _labels = _.map(result.data.data, function(metric) {
|
||||||
return metric[label] || '';
|
return metric[label] || '';
|
||||||
}).filter(function(label) {
|
}).filter(function(label) {
|
||||||
@ -76,7 +76,7 @@ export default class PrometheusMetricFindQuery {
|
|||||||
metricNameQuery(metricFilterPattern) {
|
metricNameQuery(metricFilterPattern) {
|
||||||
var url = '/api/v1/label/__name__/values';
|
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)
|
return _.chain(result.data.data)
|
||||||
.filter(function(metricName) {
|
.filter(function(metricName) {
|
||||||
var r = new RegExp(metricFilterPattern);
|
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 url = '/api/v1/series?match[]=' + encodeURIComponent(query) + '&start=' + start + '&end=' + end;
|
||||||
|
|
||||||
var self = this;
|
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 _.map(result.data.data, function(metric) {
|
||||||
return {
|
return {
|
||||||
text: self.datasource.getOriginalMetricName(metric),
|
text: self.datasource.getOriginalMetricName(metric),
|
||||||
|
Loading…
Reference in New Issue
Block a user