Commit 006286ac by David Kaltschmidt

Renamed helperRequest and removed positional args

From review feedback:

* s/helper/metadata
* combined positional args to _request into options dict
* metadataRequest reuses _request()
* moved consumption of this.httpMethod into _request, can be overwritten
 in options due to spread-after
parent 53817b74
......@@ -5,6 +5,7 @@ import kbn from 'app/core/utils/kbn';
import * as dateMath from 'app/core/utils/datemath';
import PrometheusMetricFindQuery from './metric_find_query';
import { ResultTransformer } from './result_transformer';
import { BackendSrv } from 'app/core/services/backend_srv';
export function prometheusRegularEscape(value) {
return value.replace(/'/g, "\\\\'");
......@@ -29,7 +30,7 @@ export class PrometheusDatasource {
resultTransformer: ResultTransformer;
/** @ngInject */
constructor(instanceSettings, private $q, private backendSrv, private templateSrv, private timeSrv) {
constructor(instanceSettings, private $q, private backendSrv: BackendSrv, private templateSrv, private timeSrv) {
this.type = 'prometheus';
this.editorSrc = 'app/features/prometheus/partials/query.editor.html';
this.name = instanceSettings.name;
......@@ -43,13 +44,13 @@ export class PrometheusDatasource {
this.resultTransformer = new ResultTransformer(templateSrv);
}
_request(method, url, data?, requestId?) {
_request(url, data?, options?: any) {
var options: any = {
url: this.url + url,
method: method,
requestId: requestId,
method: this.httpMethod,
...options,
};
if (method === 'GET') {
if (options.method === 'GET') {
if (!_.isEmpty(data)) {
options.url =
options.url +
......@@ -82,17 +83,8 @@ export class PrometheusDatasource {
}
// 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);
metadataRequest(url) {
return this._request(url, null, { silent: true });
}
interpolateQueryExpr(value, variable, defaultFormatFn) {
......@@ -220,7 +212,7 @@ export class PrometheusDatasource {
end: end,
step: query.step,
};
return this._request(this.httpMethod, url, data, query.requestId);
return this._request(url, data, { requestId: query.requestId });
}
performInstantQuery(query, time) {
......@@ -229,7 +221,7 @@ export class PrometheusDatasource {
query: query.expr,
time: time,
};
return this._request(this.httpMethod, url, data, query.requestId);
return this._request(url, data, { requestId: query.requestId });
}
performSuggestQuery(query, cache = false) {
......@@ -243,7 +235,7 @@ export class PrometheusDatasource {
);
}
return this.helperRequest(url).then(result => {
return this.metadataRequest(url).then(result => {
this.metricsNameCache = {
data: result.data.data,
expire: Date.now() + 60 * 1000,
......
......@@ -46,7 +46,7 @@ export default class PrometheusMetricFindQuery {
// return label values globally
url = '/api/v1/label/' + label + '/values';
return this.datasource.helperRequest(url).then(function(result) {
return this.datasource.metadataRequest(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.helperRequest(url).then(function(result) {
return this.datasource.metadataRequest(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.helperRequest(url).then(function(result) {
return this.datasource.metadataRequest(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.helperRequest(url).then(function(result) {
return this.datasource.metadataRequest(url).then(function(result) {
return _.map(result.data.data, function(metric) {
return {
text: self.datasource.getOriginalMetricName(metric),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment