Files
grafana/apps/alerting/rules/kinds/v0alpha1/rule_spec.cue
T
Moustafa Baiou cb7abbaa0f Alerting: Rename expression elements of Rules APIs (#110914)
This renames `data` to `expressions` for clarity in the rules apis.

Also makes certain fields that are redundant optional in the case of pure expressions, so that users don't have to specify them when they are not needed (e.g. not datasource queries).
2025-09-12 22:15:55 +00:00

54 lines
1.7 KiB
CUE

// TODO: many strings need to be validated as having the appropriate minimum length using strings.minRunes(n)
package v0alpha1
import "time"
#PromDurationWMillis: time.Duration & =~"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$"
#PromDuration: time.Duration & =~"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$" & !~"hmuµn"
TemplateString: string
#DatasourceUID: string & =~"^[a-zA-Z0-9_-]+$"
#RuleSpec: {
title: string
paused?: bool
trigger: #IntervalTrigger
labels?: {
[string]: TemplateString
}
expressions: #ExpressionMap
...
}
// TODO(@moustafab): when we support other trigger types ensure that none of the fields conflict
// #TriggerType: #IntervalTrigger
#IntervalTrigger: {
interval: #PromDuration
}
#RelativeTimeRange: {
from: #PromDurationWMillis
to: #PromDurationWMillis
}
// TODO: validate that only one can specify source=true
#ExpressionMap: {
[string]: #Expression
} // & struct.MinFields(1) This doesn't work in Cue <v0.12.0 as per
#Expression: {
// The type of query if this is a query expression
queryType?: string
relativeTimeRange?: #RelativeTimeRange
// The UID of the datasource to run this expression against. If omitted, the expression will be run against the `__expr__` datasource
datasourceUID?: #DatasourceUID
model: _
// Used to mark the expression to be used as the final source for the rule evaluation
// Only one expression in a rule can be marked as the source
// For AlertRules, this is the expression that will be evaluated against the alerting condition
// For RecordingRules, this is the expression that will be recorded
source?: bool
}