mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 15:42:13 +08:00
Prometheus: datasource config with custom parameters string (#19121)
This commit is contained in:
@ -26,7 +26,7 @@ Grafana includes built-in support for Prometheus.
|
|||||||
## Data source options
|
## Data source options
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| _Name_ | The data source name. This is how you refer to the data source in panels & queries. |
|
| _Name_ | The data source name. This is how you refer to the data source in panels & queries. |
|
||||||
| _Default_ | Default data source means that it will be pre-selected for new panels. |
|
| _Default_ | Default data source means that it will be pre-selected for new panels. |
|
||||||
| _Url_ | The http protocol, ip and port of you Prometheus server (default port is usually 9090) |
|
| _Url_ | The http protocol, ip and port of you Prometheus server (default port is usually 9090) |
|
||||||
@ -35,6 +35,7 @@ Grafana includes built-in support for Prometheus.
|
|||||||
| _User_ | Name of your Prometheus user |
|
| _User_ | Name of your Prometheus user |
|
||||||
| _Password_ | Database user's password |
|
| _Password_ | Database user's password |
|
||||||
| _Scrape interval_ | This will be used as a lower limit for the Prometheus step query parameter. Default value is 15s. |
|
| _Scrape interval_ | This will be used as a lower limit for the Prometheus step query parameter. Default value is 15s. |
|
||||||
|
| _CustomQueryParameters_ | Add Custom parameters to Prometheus query url. For example `timeout`, `partial_response`, `dedup` or `max_source_resolution`. |
|
||||||
|
|
||||||
## Query editor
|
## Query editor
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
|||||||
httpMethod: string;
|
httpMethod: string;
|
||||||
languageProvider: PrometheusLanguageProvider;
|
languageProvider: PrometheusLanguageProvider;
|
||||||
resultTransformer: ResultTransformer;
|
resultTransformer: ResultTransformer;
|
||||||
|
customQueryParameters: any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
@ -78,6 +79,7 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
|||||||
this.resultTransformer = new ResultTransformer(templateSrv);
|
this.resultTransformer = new ResultTransformer(templateSrv);
|
||||||
this.ruleMappings = {};
|
this.ruleMappings = {};
|
||||||
this.languageProvider = new PrometheusLanguageProvider(this);
|
this.languageProvider = new PrometheusLanguageProvider(this);
|
||||||
|
this.customQueryParameters = new URLSearchParams(instanceSettings.jsonData.customQueryParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
init = () => {
|
init = () => {
|
||||||
@ -348,6 +350,12 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
|||||||
data['timeout'] = this.queryTimeout;
|
data['timeout'] = this.queryTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of this.customQueryParameters) {
|
||||||
|
if (data[key] == null) {
|
||||||
|
data[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this._request(url, data, { requestId: query.requestId, headers: query.headers }).catch((err: any) => {
|
return this._request(url, data, { requestId: query.requestId, headers: query.headers }).catch((err: any) => {
|
||||||
if (err.cancelled) {
|
if (err.cancelled) {
|
||||||
return err;
|
return err;
|
||||||
@ -368,6 +376,12 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
|||||||
data['timeout'] = this.queryTimeout;
|
data['timeout'] = this.queryTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of this.customQueryParameters) {
|
||||||
|
if (data[key] == null) {
|
||||||
|
data[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this._request(url, data, { requestId: query.requestId, headers: query.headers }).catch((err: any) => {
|
return this._request(url, data, { requestId: query.requestId, headers: query.headers }).catch((err: any) => {
|
||||||
if (err.cancelled) {
|
if (err.cancelled) {
|
||||||
return err;
|
return err;
|
||||||
|
@ -48,3 +48,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h3 class="page-heading">Misc</h3>
|
||||||
|
<div class="gf-form-group">
|
||||||
|
<div class="gf-form-inline">
|
||||||
|
<div class="gf-form max-width-30">
|
||||||
|
<span class="gf-form-label width-13">Custom query parameters</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="gf-form-input gf-form-input--has-help-icon"
|
||||||
|
ng-model="ctrl.current.jsonData.customQueryParameters"
|
||||||
|
spellcheck="false"
|
||||||
|
placeholder="Example: max_source_resolution=5m&timeout=10"
|
||||||
|
></input>
|
||||||
|
<info-popover mode="right-absolute">
|
||||||
|
Add Custom parameters to Prometheus or Thanos queries.
|
||||||
|
</info-popover>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ export interface PromOptions extends DataSourceJsonData {
|
|||||||
queryTimeout: string;
|
queryTimeout: string;
|
||||||
httpMethod: string;
|
httpMethod: string;
|
||||||
directUrl: string;
|
directUrl: string;
|
||||||
|
customQueryParameters?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PromQueryRequest extends PromQuery {
|
export interface PromQueryRequest extends PromQuery {
|
||||||
|
Reference in New Issue
Block a user