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'; ...@@ -5,6 +5,7 @@ import kbn from 'app/core/utils/kbn';
import * as dateMath from 'app/core/utils/datemath'; import * as dateMath from 'app/core/utils/datemath';
import PrometheusMetricFindQuery from './metric_find_query'; import PrometheusMetricFindQuery from './metric_find_query';
import { ResultTransformer } from './result_transformer'; import { ResultTransformer } from './result_transformer';
import { BackendSrv } from 'app/core/services/backend_srv';
export function prometheusRegularEscape(value) { export function prometheusRegularEscape(value) {
return value.replace(/'/g, "\\\\'"); return value.replace(/'/g, "\\\\'");
...@@ -29,7 +30,7 @@ export class PrometheusDatasource { ...@@ -29,7 +30,7 @@ export class PrometheusDatasource {
resultTransformer: ResultTransformer; resultTransformer: ResultTransformer;
/** @ngInject */ /** @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.type = 'prometheus';
this.editorSrc = 'app/features/prometheus/partials/query.editor.html'; this.editorSrc = 'app/features/prometheus/partials/query.editor.html';
this.name = instanceSettings.name; this.name = instanceSettings.name;
...@@ -43,13 +44,13 @@ export class PrometheusDatasource { ...@@ -43,13 +44,13 @@ export class PrometheusDatasource {
this.resultTransformer = new ResultTransformer(templateSrv); this.resultTransformer = new ResultTransformer(templateSrv);
} }
_request(method, url, data?, requestId?) { _request(url, data?, options?: any) {
var options: any = { var options: any = {
url: this.url + url, url: this.url + url,
method: method, method: this.httpMethod,
requestId: requestId, ...options,
}; };
if (method === 'GET') { if (options.method === 'GET') {
if (!_.isEmpty(data)) { if (!_.isEmpty(data)) {
options.url = options.url =
options.url + options.url +
...@@ -82,17 +83,8 @@ export class PrometheusDatasource { ...@@ -82,17 +83,8 @@ export class PrometheusDatasource {
} }
// Use this for tab completion features, wont publish response to other components // Use this for tab completion features, wont publish response to other components
helperRequest(url) { metadataRequest(url) {
const options: any = { return this._request(url, null, { silent: true });
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) {
...@@ -220,7 +212,7 @@ export class PrometheusDatasource { ...@@ -220,7 +212,7 @@ export class PrometheusDatasource {
end: end, end: end,
step: query.step, step: query.step,
}; };
return this._request(this.httpMethod, url, data, query.requestId); return this._request(url, data, { requestId: query.requestId });
} }
performInstantQuery(query, time) { performInstantQuery(query, time) {
...@@ -229,7 +221,7 @@ export class PrometheusDatasource { ...@@ -229,7 +221,7 @@ export class PrometheusDatasource {
query: query.expr, query: query.expr,
time: time, time: time,
}; };
return this._request(this.httpMethod, url, data, query.requestId); return this._request(url, data, { requestId: query.requestId });
} }
performSuggestQuery(query, cache = false) { performSuggestQuery(query, cache = false) {
...@@ -243,7 +235,7 @@ export class PrometheusDatasource { ...@@ -243,7 +235,7 @@ export class PrometheusDatasource {
); );
} }
return this.helperRequest(url).then(result => { return this.metadataRequest(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 { ...@@ -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.helperRequest(url).then(function(result) { return this.datasource.metadataRequest(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 { ...@@ -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.helperRequest(url).then(function(result) { return this.datasource.metadataRequest(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 { ...@@ -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.helperRequest(url).then(function(result) { return this.datasource.metadataRequest(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 { ...@@ -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.helperRequest(url).then(function(result) { return this.datasource.metadataRequest(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),
......
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