// Core Grafana history https://github.com/grafana/grafana/blob/v11.0.0-preview/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx import React, { SyntheticEvent, useState } from 'react'; import { DataSourcePluginOptionsEditorProps, onUpdateDatasourceJsonDataOptionChecked, SelectableValue, updateDatasourcePluginJsonDataOption, } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { ConfigSubSection } from '@grafana/experimental'; import { config } from '@grafana/runtime'; import { InlineField, Input, Select, Switch, useTheme2 } from '@grafana/ui'; import { SUGGESTIONS_LIMIT } from '../language_provider'; import { QueryEditorMode } from '../querybuilder/shared/types'; import { defaultPrometheusQueryOverlapWindow } from '../querycache/QueryCache'; import { PromApplication, PrometheusCacheLevel, PromOptions } from '../types'; import { docsTip, overhaulStyles, PROM_CONFIG_LABEL_WIDTH, validateInput } from './ConfigEditor'; import { ExemplarsSettings } from './ExemplarsSettings'; import { PromFlavorVersions } from './PromFlavorVersions'; const httpOptions = [ { value: 'POST', label: 'POST' }, { value: 'GET', label: 'GET' }, ]; const editorOptions = [ { value: QueryEditorMode.Builder, label: 'Builder' }, { value: QueryEditorMode.Code, label: 'Code' }, ]; const cacheValueOptions = [ { value: PrometheusCacheLevel.Low, label: 'Low' }, { value: PrometheusCacheLevel.Medium, label: 'Medium' }, { value: PrometheusCacheLevel.High, label: 'High' }, { value: PrometheusCacheLevel.None, label: 'None' }, ]; type PrometheusSelectItemsType = Array<{ value: PromApplication; label: PromApplication }>; const prometheusFlavorSelectItems: PrometheusSelectItemsType = [ { value: PromApplication.Prometheus, label: PromApplication.Prometheus }, { value: PromApplication.Cortex, label: PromApplication.Cortex }, { value: PromApplication.Mimir, label: PromApplication.Mimir }, { value: PromApplication.Thanos, label: PromApplication.Thanos }, ]; type Props = Pick, 'options' | 'onOptionsChange'>; // single duration input export const DURATION_REGEX = /^$|^\d+(ms|[Mwdhmsy])$/; // multiple duration input export const MULTIPLE_DURATION_REGEX = /(\d+)(.+)/; export const NON_NEGATIVE_INTEGER_REGEX = /^(0|[1-9]\d*)(\.\d+)?(e\+?\d+)?$/; // non-negative integers, including scientific notation const durationError = 'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s'; export const countError = 'Value is not valid, you can use non-negative integers, including scientific notation'; export const PromSettings = (props: Props) => { const { options, onOptionsChange } = props; // We are explicitly adding httpMethod so, it is correctly displayed in dropdown. // This way, it is more predictable for users. if (!options.jsonData.httpMethod) { options.jsonData.httpMethod = 'POST'; } const theme = useTheme2(); const styles = overhaulStyles(theme); type ValidDuration = { timeInterval: string; queryTimeout: string; incrementalQueryOverlapWindow: string; }; const [validDuration, updateValidDuration] = useState({ timeInterval: '', queryTimeout: '', incrementalQueryOverlapWindow: '', }); type ValidCount = { codeModeMetricNamesSuggestionLimit: string; }; const [validCount, updateValidCount] = useState({ codeModeMetricNamesSuggestionLimit: '', }); return ( <>
{/* Scrape interval */}
This interval is how frequently Prometheus scrapes targets. Set this to the typical scrape and evaluation interval configured in your Prometheus config file. If you set this to a greater value than your Prometheus config file interval, Grafana will evaluate the data according to this interval and you will see less data points. Defaults to 15s. {docsTip()} } interactive={true} disabled={options.readOnly} > <> updateValidDuration({ ...validDuration, timeInterval: e.currentTarget.value, }) } data-testid={selectors.components.DataSource.Prometheus.configPage.scrapeInterval} /> {validateInput(validDuration.timeInterval, DURATION_REGEX, durationError)}
{/* Query Timeout */}
Set the Prometheus query timeout. {docsTip()}} interactive={true} disabled={options.readOnly} > <> updateValidDuration({ ...validDuration, queryTimeout: e.currentTarget.value, }) } data-testid={selectors.components.DataSource.Prometheus.configPage.queryTimeout} /> {validateInput(validDuration.queryTimeout, DURATION_REGEX, durationError)}
Set default editor option for all users of this data source. {docsTip()}} interactive={true} disabled={options.readOnly} > o.value === options.jsonData.prometheusType)} onChange={onChangeHandler('prometheusType', options, onOptionsChange)} width={40} data-testid={selectors.components.DataSource.Prometheus.configPage.prometheusType} />
{options.jsonData.prometheusType && (
Use this to set the version of your {options.jsonData.prometheusType} instance if it is not automatically configured. {docsTip()} } interactive={true} disabled={options.readOnly} > o.value === options.jsonData.cacheLevel) ?? PrometheusCacheLevel.Low } data-testid={selectors.components.DataSource.Prometheus.configPage.cacheLevel} />
{config.featureToggles.prometheusCodeModeMetricNamesSearch && (
The maximum number of metric names that may appear as autocomplete suggestions in the query editor's Code mode. } interactive={true} disabled={options.readOnly} > <> updateValidCount({ ...validCount, codeModeMetricNamesSuggestionLimit: e.currentTarget.value, }) } data-testid={ selectors.components.DataSource.Prometheus.configPage.codeModeMetricNamesSuggestionLimit } /> {validateInput( validCount.codeModeMetricNamesSuggestionLimit, NON_NEGATIVE_INTEGER_REGEX, countError )}
)}
This feature will change the default behavior of relative queries to always request fresh data from the prometheus instance, instead query results will be cached, and only new records are requested. Turn this on to decrease database and network load. } interactive={true} className={styles.switchField} disabled={options.readOnly} >
{options.jsonData.incrementalQuerying && ( Set a duration like 10m or 120s or 0s. Default of 10 minutes. This duration will be added to the duration of each incremental request. } interactive={true} disabled={options.readOnly} > <> updateValidDuration({ ...validDuration, incrementalQueryOverlapWindow: e.currentTarget.value, }) } className="width-20" value={options.jsonData.incrementalQueryOverlapWindow ?? defaultPrometheusQueryOverlapWindow} onChange={onChangeHandler('incrementalQueryOverlapWindow', options, onOptionsChange)} spellCheck={false} data-testid={selectors.components.DataSource.Prometheus.configPage.queryOverlapWindow} /> {validateInput(validDuration.incrementalQueryOverlapWindow, MULTIPLE_DURATION_REGEX, durationError)} )}
This feature will disable recording rules Turn this on to improve dashboard performance} interactive={true} className={styles.switchField} disabled={options.readOnly} >
Add custom parameters to the Prometheus query URL. For example timeout, partial_response, dedup, or max_source_resolution. Multiple parameters should be concatenated together with an ‘&’. {docsTip()} } interactive={true} disabled={options.readOnly} >
{/* HTTP Method */}
You can use either POST or GET HTTP method to query your Prometheus data source. POST is the recommended method as it allows bigger queries. Change this to GET if you have a Prometheus version older than 2.1 or if POST requests are restricted in your network. {docsTip()} } interactive={true} label="HTTP method" disabled={options.readOnly} >