mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
Explore: add functionality for supporting different step modes in prometheus (#37829)
This commit is contained in:
@ -3,16 +3,20 @@ import React, { memo } from 'react';
|
|||||||
import { css, cx } from '@emotion/css';
|
import { css, cx } from '@emotion/css';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { InlineFormLabel, RadioButtonGroup } from '@grafana/ui';
|
import { InlineFormLabel, RadioButtonGroup, Select } from '@grafana/ui';
|
||||||
import { PromQuery } from '../types';
|
import { PromQuery, StepMode } from '../types';
|
||||||
import { PromExemplarField } from './PromExemplarField';
|
import { PromExemplarField } from './PromExemplarField';
|
||||||
import { PrometheusDatasource } from '../datasource';
|
import { PrometheusDatasource } from '../datasource';
|
||||||
|
import { STEP_MODES } from './PromQueryEditor';
|
||||||
|
import { SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
export interface PromExploreExtraFieldProps {
|
export interface PromExploreExtraFieldProps {
|
||||||
queryType: string;
|
queryType: string;
|
||||||
stepValue: string;
|
stepValue: string;
|
||||||
|
stepMode: StepMode;
|
||||||
query: PromQuery;
|
query: PromQuery;
|
||||||
onStepChange: (e: React.SyntheticEvent<HTMLInputElement>) => void;
|
onStepModeChange: (option: SelectableValue<StepMode>) => void;
|
||||||
|
onStepIntervalChange: (e: React.SyntheticEvent<HTMLInputElement>) => void;
|
||||||
onKeyDownFunc: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
onKeyDownFunc: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
||||||
onQueryTypeChange: (value: string) => void;
|
onQueryTypeChange: (value: string) => void;
|
||||||
onChange: (value: PromQuery) => void;
|
onChange: (value: PromQuery) => void;
|
||||||
@ -20,7 +24,18 @@ export interface PromExploreExtraFieldProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const PromExploreExtraField: React.FC<PromExploreExtraFieldProps> = memo(
|
export const PromExploreExtraField: React.FC<PromExploreExtraFieldProps> = memo(
|
||||||
({ queryType, stepValue, query, onChange, onStepChange, onQueryTypeChange, onKeyDownFunc, datasource }) => {
|
({
|
||||||
|
queryType,
|
||||||
|
stepValue,
|
||||||
|
stepMode,
|
||||||
|
query,
|
||||||
|
onChange,
|
||||||
|
onStepModeChange,
|
||||||
|
onStepIntervalChange,
|
||||||
|
onQueryTypeChange,
|
||||||
|
onKeyDownFunc,
|
||||||
|
datasource,
|
||||||
|
}) => {
|
||||||
const rangeOptions = [
|
const rangeOptions = [
|
||||||
{ value: 'range', label: 'Range', description: 'Run query over a range of time.' },
|
{ value: 'range', label: 'Range', description: 'Run query over a range of time.' },
|
||||||
{
|
{
|
||||||
@ -67,11 +82,20 @@ export const PromExploreExtraField: React.FC<PromExploreExtraFieldProps> = memo(
|
|||||||
>
|
>
|
||||||
Step
|
Step
|
||||||
</InlineFormLabel>
|
</InlineFormLabel>
|
||||||
|
<Select
|
||||||
|
menuShouldPortal
|
||||||
|
className={'select-container'}
|
||||||
|
width={16}
|
||||||
|
isSearchable={false}
|
||||||
|
options={STEP_MODES}
|
||||||
|
onChange={onStepModeChange}
|
||||||
|
value={stepMode}
|
||||||
|
/>
|
||||||
<input
|
<input
|
||||||
type={'text'}
|
type={'text'}
|
||||||
className="gf-form-input width-4"
|
className="gf-form-input width-4"
|
||||||
placeholder={'auto'}
|
placeholder={'auto'}
|
||||||
onChange={onStepChange}
|
onChange={onStepIntervalChange}
|
||||||
onKeyDown={onKeyDownFunc}
|
onKeyDown={onKeyDownFunc}
|
||||||
value={stepValue}
|
value={stepValue}
|
||||||
/>
|
/>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import React, { memo, FC, useEffect } from 'react';
|
import React, { memo, FC, useEffect } from 'react';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { ExploreQueryFieldProps } from '@grafana/data';
|
import { ExploreQueryFieldProps, SelectableValue } from '@grafana/data';
|
||||||
|
|
||||||
import { PrometheusDatasource } from '../datasource';
|
import { PrometheusDatasource } from '../datasource';
|
||||||
import { PromQuery, PromOptions } from '../types';
|
import { PromQuery, PromOptions, StepMode } from '../types';
|
||||||
|
|
||||||
import PromQueryField from './PromQueryField';
|
import PromQueryField from './PromQueryField';
|
||||||
import { PromExploreExtraField } from './PromExploreExtraField';
|
import { PromExploreExtraField } from './PromExploreExtraField';
|
||||||
@ -26,7 +26,19 @@ export const PromExploreQueryEditor: FC<Props> = (props: Props) => {
|
|||||||
onChange(nextQuery);
|
onChange(nextQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onStepChange(e: React.SyntheticEvent<HTMLInputElement>) {
|
function onChangeStepMode(mode: StepMode) {
|
||||||
|
const { query, onChange } = props;
|
||||||
|
const nextQuery = { ...query, stepMode: mode };
|
||||||
|
onChange(nextQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStepModeChange(option: SelectableValue<StepMode>) {
|
||||||
|
if (option.value) {
|
||||||
|
onChangeStepMode(option.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStepIntervalChange(e: React.SyntheticEvent<HTMLInputElement>) {
|
||||||
if (e.currentTarget.value !== query.interval) {
|
if (e.currentTarget.value !== query.interval) {
|
||||||
onChangeQueryStep(e.currentTarget.value);
|
onChangeQueryStep(e.currentTarget.value);
|
||||||
}
|
}
|
||||||
@ -66,8 +78,10 @@ export const PromExploreQueryEditor: FC<Props> = (props: Props) => {
|
|||||||
// Select "both" as default option when Explore is opened. In legacy requests, range and instant can be undefined. In this case, we want to run queries with "both".
|
// Select "both" as default option when Explore is opened. In legacy requests, range and instant can be undefined. In this case, we want to run queries with "both".
|
||||||
queryType={query.range === query.instant ? 'both' : query.instant ? 'instant' : 'range'}
|
queryType={query.range === query.instant ? 'both' : query.instant ? 'instant' : 'range'}
|
||||||
stepValue={query.interval || ''}
|
stepValue={query.interval || ''}
|
||||||
|
stepMode={query.stepMode || 'min'}
|
||||||
onQueryTypeChange={onQueryTypeChange}
|
onQueryTypeChange={onQueryTypeChange}
|
||||||
onStepChange={onStepChange}
|
onStepModeChange={onStepModeChange}
|
||||||
|
onStepIntervalChange={onStepIntervalChange}
|
||||||
onKeyDownFunc={onReturnKeyDown}
|
onKeyDownFunc={onReturnKeyDown}
|
||||||
query={query}
|
query={query}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
@ -29,7 +29,7 @@ export const DEFAULT_STEP_MODE: SelectableValue<StepMode> = {
|
|||||||
label: 'Minimum',
|
label: 'Minimum',
|
||||||
};
|
};
|
||||||
|
|
||||||
const STEP_MODES: Array<SelectableValue<StepMode>> = [
|
export const STEP_MODES: Array<SelectableValue<StepMode>> = [
|
||||||
DEFAULT_STEP_MODE,
|
DEFAULT_STEP_MODE,
|
||||||
{
|
{
|
||||||
value: 'max',
|
value: 'max',
|
||||||
|
@ -16,7 +16,8 @@ exports[`PromExploreQueryEditor should render component 1`] = `
|
|||||||
onChange={[MockFunction]}
|
onChange={[MockFunction]}
|
||||||
onKeyDownFunc={[Function]}
|
onKeyDownFunc={[Function]}
|
||||||
onQueryTypeChange={[Function]}
|
onQueryTypeChange={[Function]}
|
||||||
onStepChange={[Function]}
|
onStepIntervalChange={[Function]}
|
||||||
|
onStepModeChange={[Function]}
|
||||||
query={
|
query={
|
||||||
Object {
|
Object {
|
||||||
"expr": "",
|
"expr": "",
|
||||||
@ -25,6 +26,7 @@ exports[`PromExploreQueryEditor should render component 1`] = `
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
queryType="both"
|
queryType="both"
|
||||||
|
stepMode="min"
|
||||||
stepValue="1s"
|
stepValue="1s"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user