Skip to content

Commit

Permalink
Prometheus: Add disableRecordingRules datasource config (#70903)
Browse files Browse the repository at this point in the history
* Add config to toggle recording rules for Prometheus

* Add documentation for Prometheus disableRecordingRules
  • Loading branch information
shantanualsi authored and harisrozajac committed Jun 30, 2023
1 parent 7fed7c1 commit 75aa4ba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/sources/administration/provisioning/index.md
Expand Up @@ -222,6 +222,7 @@ Data sources tagged with _HTTP\*_ communicate using the HTTP protocol, which inc
| cacheLevel | string | Prometheus | Determines the duration of the browser cache. Valid values include: `Low`, `Medium`, `High`, and `None`. This field is configurable when you enable the `prometheusResourceBrowserCache` feature flag. |
| incrementalQuerying | string | Prometheus | Experimental: Turn on incremental querying to enhance dashboard reload performance with slow data sources |
| incrementalQueryOverlapWindow | string | Prometheus | Experimental: Configure incremental query overlap window. Requires a valid duration string, i.e. `180s` or `15m` Default value is `10m` (10 minutes). |
| disableRecordingRules | boolean | Prometheus | Experimental: Turn off Prometheus recording rules |
| implementation | string | AlertManager | The implementation of the AlertManager data source, such as `prometheus`, `cortex` or `mimir` |
| handleGrafanaManagedAlerts | boolean | AlertManager | When enabled, Grafana-managed alerts are sent to this Alertmanager |

Expand Down
6 changes: 5 additions & 1 deletion docs/sources/datasources/prometheus/_index.md
Expand Up @@ -69,7 +69,7 @@ prometheusVersion: 2.44.0
incrementalQuerying: true
incrementalQueryOverlapWindow: 10m
cacheLevel: 'High'
incrementalQuerying: true
disableRecordingRules: false
incrementalQueryOverlapWindow: 10m
exemplarTraceIdDestinations:
# Field with internal link pointing to data source in Grafana.
Expand Down Expand Up @@ -141,3 +141,7 @@ This can be toggled on or off in the data source configuration or provisioning f
Additionally, the amount of overlap between incremental queries can be configured using the `incrementalQueryOverlapWindow` jsonData field, the default value is `10m` (10 minutes).

Increasing the duration of the `incrementalQueryOverlapWindow` will increase the size of every incremental query, but might be helpful for instances that have inconsistent results for recent data.

## Recording Rules (beta)

The Prometheus data source can be configured to disable recording rules under the data source configuration or provisioning file (under `disableRecordingRules` in jsonData).
Expand Up @@ -440,8 +440,25 @@ export const PromSettings = (props: Props) => {
</InlineField>
)}
</div>
</div>

<div className="gf-form-inline">
<div className="gf-form max-width-30">
<InlineField
label="Disable recording rules (beta)"
labelWidth={PROM_CONFIG_LABEL_WIDTH}
tooltip={<>This feature will disable recording rules Turn this on to improve dashboard performance</>}
interactive={true}
className={styles.switchField}
disabled={options.readOnly}
>
<Switch
value={options.jsonData.disableRecordingRules ?? false}
onChange={onUpdateDatasourceJsonDataOptionChecked(props, 'disableRecordingRules')}
/>
</InlineField>
</div>
</div>
</div>
<h3 className="page-heading">Other</h3>
<div className="gf-form-group">
<div className="gf-form-inline">
Expand Down
6 changes: 5 additions & 1 deletion public/app/plugins/datasource/prometheus/datasource.tsx
Expand Up @@ -102,6 +102,7 @@ export class PrometheusDatasource
customQueryParameters: any;
datasourceConfigurationPrometheusFlavor?: PromApplication;
datasourceConfigurationPrometheusVersion?: string;
disableRecordingRules: boolean;
defaultEditor?: QueryEditorMode;
exemplarsAvailable: boolean;
subType: PromApplication;
Expand Down Expand Up @@ -140,6 +141,7 @@ export class PrometheusDatasource
this.datasourceConfigurationPrometheusFlavor = instanceSettings.jsonData.prometheusType;
this.datasourceConfigurationPrometheusVersion = instanceSettings.jsonData.prometheusVersion;
this.defaultEditor = instanceSettings.jsonData.defaultEditor;
this.disableRecordingRules = instanceSettings.jsonData.disableRecordingRules ?? false;
this.variables = new PrometheusVariableSupport(this, this.templateSrv, this.timeSrv);
this.exemplarsAvailable = true;
this.cacheLevel = instanceSettings.jsonData.cacheLevel ?? PrometheusCacheLevel.Low;
Expand All @@ -160,7 +162,9 @@ export class PrometheusDatasource
}

init = async () => {
this.loadRules();
if (!this.disableRecordingRules) {
this.loadRules();
}
this.exemplarsAvailable = await this.areExemplarsAvailable();
};

Expand Down
1 change: 1 addition & 0 deletions public/app/plugins/datasource/prometheus/types.ts
Expand Up @@ -44,6 +44,7 @@ export interface PromOptions extends DataSourceJsonData {
defaultEditor?: QueryEditorMode;
incrementalQuerying?: boolean;
incrementalQueryOverlapWindow?: string;
disableRecordingRules?: boolean;
}

export type ExemplarTraceIdDestination = {
Expand Down

0 comments on commit 75aa4ba

Please sign in to comment.