mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Prometheus data source: Update tooltip for _Scrape interval_ The old tool tip was plainly wrong. The globally configured scrape interval is not necessarily the most used scrape interval, so the new wording is describing what actually matters. The evaluation interval wasn't even mentioned before. And finally, the configured value is not strictly a lower limit for the step query parameter as it can be overridden by the panel option _Min time interval_. I plan to explain the overriding intricacies in the tool tip for _Min time interval_. Signed-off-by: beorn7 <beorn@grafana.com> * Improve tooltip for _Min step_ The previous tool tip was mostly addressing aspects that are not specific to _Min step_ (and might be more appropriate to be added to the _Min time interval_ tool tip as that setting has a wider scope). The new version emphasizes the important gotchas: that this is an _additional_ lower limit, and that it is _not_ multiplied by the resolution factor. Signed-off-by: beorn7 <beorn@grafana.com> * Fixed snapshot Co-authored-by: David <david.kaltschmidt@gmail.com>
132 lines
4.1 KiB
TypeScript
132 lines
4.1 KiB
TypeScript
import React, { SyntheticEvent } from 'react';
|
|
import { EventsWithValidation, FormField, FormLabel, Input, regexValidation, Select } from '@grafana/ui';
|
|
import { DataSourceSettings, SelectableValue } from '@grafana/data';
|
|
import { PromOptions } from '../types';
|
|
|
|
const httpOptions = [
|
|
{ value: 'GET', label: 'GET' },
|
|
{ value: 'POST', label: 'POST' },
|
|
];
|
|
|
|
type Props = {
|
|
value: DataSourceSettings<PromOptions>;
|
|
onChange: (value: DataSourceSettings<PromOptions>) => void;
|
|
};
|
|
|
|
export const PromSettings = (props: Props) => {
|
|
const { value, onChange } = props;
|
|
|
|
return (
|
|
<>
|
|
<div className="gf-form-group">
|
|
<div className="gf-form-inline">
|
|
<div className="gf-form">
|
|
<FormField
|
|
label="Scrape interval"
|
|
labelWidth={13}
|
|
placeholder="15s"
|
|
inputEl={
|
|
<Input
|
|
className="width-6"
|
|
value={value.jsonData.timeInterval}
|
|
spellCheck={false}
|
|
onChange={onChangeHandler('timeInterval', value, onChange)}
|
|
validationEvents={promSettingsValidationEvents}
|
|
/>
|
|
}
|
|
tooltip="Set this to the typical scrape and evaluation interval configured in Prometheus. Defaults to 15s."
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="gf-form-inline">
|
|
<div className="gf-form">
|
|
<FormField
|
|
label="Query timeout"
|
|
labelWidth={13}
|
|
inputEl={
|
|
<Input
|
|
className="width-6"
|
|
value={value.jsonData.queryTimeout}
|
|
onChange={onChangeHandler('queryTimeout', value, onChange)}
|
|
spellCheck={false}
|
|
placeholder="60s"
|
|
validationEvents={promSettingsValidationEvents}
|
|
/>
|
|
}
|
|
tooltip="Set the Prometheus query timeout."
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="gf-form">
|
|
<FormLabel
|
|
width={13}
|
|
tooltip="Specify the HTTP Method to query Prometheus. (POST is only available in Prometheus >= v2.1.0)"
|
|
>
|
|
HTTP Method
|
|
</FormLabel>
|
|
<Select
|
|
options={httpOptions}
|
|
value={httpOptions.find(o => o.value === value.jsonData.httpMethod)}
|
|
onChange={onChangeHandler('httpMethod', value, onChange)}
|
|
width={7}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<h3 className="page-heading">Misc</h3>
|
|
<div className="gf-form-group">
|
|
<div className="gf-form-inline">
|
|
<div className="gf-form max-width-30">
|
|
<FormField
|
|
label="Custom query parameters"
|
|
labelWidth={14}
|
|
tooltip="Add Custom parameters to Prometheus or Thanos queries."
|
|
inputEl={
|
|
<Input
|
|
className="width-25"
|
|
value={value.jsonData.customQueryParameters}
|
|
onChange={onChangeHandler('customQueryParameters', value, onChange)}
|
|
spellCheck={false}
|
|
placeholder="Example: max_source_resolution=5m&timeout=10"
|
|
/>
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export const promSettingsValidationEvents = {
|
|
[EventsWithValidation.onBlur]: [
|
|
regexValidation(
|
|
/^$|^\d+(ms|[Mwdhmsy])$/,
|
|
'Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s'
|
|
),
|
|
],
|
|
};
|
|
|
|
export const getValueFromEventItem = (eventItem: SyntheticEvent<HTMLInputElement> | SelectableValue<string>) => {
|
|
if (!eventItem) {
|
|
return '';
|
|
}
|
|
|
|
if (eventItem.hasOwnProperty('currentTarget')) {
|
|
return eventItem.currentTarget.value;
|
|
}
|
|
|
|
return (eventItem as SelectableValue<string>).value;
|
|
};
|
|
|
|
const onChangeHandler = (key: keyof PromOptions, value: Props['value'], onChange: Props['onChange']) => (
|
|
eventItem: SyntheticEvent<HTMLInputElement> | SelectableValue<string>
|
|
) => {
|
|
onChange({
|
|
...value,
|
|
jsonData: {
|
|
...value.jsonData,
|
|
[key]: getValueFromEventItem(eventItem),
|
|
},
|
|
});
|
|
};
|