@ -18,15 +18,18 @@ import { GraphTresholdsStyleMode, Icon, InlineFormLabel, Input, Tooltip, useStyl
import { QueryEditorRow } from 'app/features/query/components/QueryEditorRow' ;
import { AlertQuery } from 'app/types/unified-alerting-dto' ;
import { msToSingleUnitDuration } from '../../utils/time' ;
import { AlertConditionIndicator } from '../expressions/AlertConditionIndicator' ;
import { QueryOptions } from './QueryOptions' ;
import { VizWrapper } from './VizWrapper' ;
export const DEFAULT_MAX_DATA_POINTS = 43200 ;
export const DEFAULT_MIN_INTERVAL = '1s' ;
export interface AlertQueryOptions {
maxDataPoints? : number | undefined ;
minInterval? : string | undefined ;
}
interface Props {
@ -107,9 +110,13 @@ export const QueryWrapper = ({
// TODO add a warning label here too when the data looks like time series data and is used as an alert condition
function HeaderExtras ( { query , error , index } : { query : AlertQuery ; error? : Error ; index : number } ) {
const queryOptions : AlertQueryOptions = { maxDataPoints : query.model.maxDataPoints } ;
const queryOptions : AlertQueryOptions = {
maxDataPoints : query.model.maxDataPoints ,
minInterval : query.model.intervalMs ? msToSingleUnitDuration ( query . model . intervalMs ) : undefined ,
} ;
const alertQueryOptions : AlertQueryOptions = {
maxDataPoints : queryOptions.maxDataPoints ,
minInterval : queryOptions.minInterval ,
} ;
return (
@ -222,6 +229,50 @@ export function MaxDataPointsOption({
) ;
}
export function MinIntervalOption ( {
options ,
onChange ,
} : {
options : AlertQueryOptions ;
onChange : ( options : AlertQueryOptions ) = > void ;
} ) {
const value = options . minInterval ? ? '' ;
const onMinIntervalBlur = ( event : ChangeEvent < HTMLInputElement > ) = > {
const minInterval = event . target . value ;
if ( minInterval !== value ) {
onChange ( {
. . . options ,
minInterval ,
} ) ;
}
} ;
return (
< Stack direction = "row" alignItems = "baseline" gap = { 1 } >
< InlineFormLabel
width = { 8 }
tooltip = {
< >
A lower limit for the interval . Recommended to be set to write frequency , for example < code > 1 m < / code > if
your data is written every minute .
< / >
}
>
Min interval
< / InlineFormLabel >
< Input
type = "text"
className = "width-6"
placeholder = { DEFAULT_MIN_INTERVAL }
spellCheck = { false }
onBlur = { onMinIntervalBlur }
defaultValue = { value }
/ >
< / Stack >
) ;
}
const getStyles = ( theme : GrafanaTheme2 ) = > ( {
wrapper : css `
label : AlertingQueryWrapper ;