|
@@ -59,6 +59,15 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
return query.expr;
|
|
return query.expr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ _addTracingHeaders(httpOptions: any, options: any) {
|
|
|
|
|
+ httpOptions.headers = options.headers || {};
|
|
|
|
|
+ const proxyMode = !this.url.match(/^http/);
|
|
|
|
|
+ if (proxyMode) {
|
|
|
|
|
+ httpOptions.headers['X-Dashboard-Id'] = options.dashboardId;
|
|
|
|
|
+ httpOptions.headers['X-Panel-Id'] = options.panelId;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
_request(url, data?, options?: any) {
|
|
_request(url, data?, options?: any) {
|
|
|
options = _.defaults(options || {}, {
|
|
options = _.defaults(options || {}, {
|
|
|
url: this.url + url,
|
|
url: this.url + url,
|
|
@@ -75,9 +84,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
}).join('&');
|
|
}).join('&');
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- options.headers = {
|
|
|
|
|
- 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
options.transformRequest = data => {
|
|
options.transformRequest = data => {
|
|
|
return $.param(data);
|
|
return $.param(data);
|
|
|
};
|
|
};
|
|
@@ -89,9 +96,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (this.basicAuth) {
|
|
if (this.basicAuth) {
|
|
|
- options.headers = {
|
|
|
|
|
- Authorization: this.basicAuth,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ options.headers.Authorization = this.basicAuth;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return this.backendSrv.datasourceRequest(options);
|
|
return this.backendSrv.datasourceRequest(options);
|
|
@@ -233,6 +238,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
const adjusted = alignRange(start, end, query.step);
|
|
const adjusted = alignRange(start, end, query.step);
|
|
|
query.start = adjusted.start;
|
|
query.start = adjusted.start;
|
|
|
query.end = adjusted.end;
|
|
query.end = adjusted.end;
|
|
|
|
|
+ this._addTracingHeaders(query, options);
|
|
|
|
|
|
|
|
return query;
|
|
return query;
|
|
|
}
|
|
}
|
|
@@ -261,7 +267,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
if (this.queryTimeout) {
|
|
if (this.queryTimeout) {
|
|
|
data['timeout'] = this.queryTimeout;
|
|
data['timeout'] = this.queryTimeout;
|
|
|
}
|
|
}
|
|
|
- return this._request(url, data, { requestId: query.requestId });
|
|
|
|
|
|
|
+ return this._request(url, data, { requestId: query.requestId, headers: query.headers });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
performInstantQuery(query, time) {
|
|
performInstantQuery(query, time) {
|
|
@@ -273,7 +279,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
|
|
|
if (this.queryTimeout) {
|
|
if (this.queryTimeout) {
|
|
|
data['timeout'] = this.queryTimeout;
|
|
data['timeout'] = this.queryTimeout;
|
|
|
}
|
|
}
|
|
|
- return this._request(url, data, { requestId: query.requestId });
|
|
|
|
|
|
|
+ return this._request(url, data, { requestId: query.requestId, headers: query.headers });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
performSuggestQuery(query, cache = false) {
|
|
performSuggestQuery(query, cache = false) {
|