From 94a7c1569e0e31d4289570bea4d3cf9a84ac6d54 Mon Sep 17 00:00:00 2001 From: Yury Molodov Date: Mon, 7 Oct 2024 16:46:15 +0200 Subject: [PATCH] feature: set default Type to instant for alert rules #205 --- CHANGELOG.md | 2 ++ src/querybuilder/state.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba5b15c..4e033241 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## tip +* FEATURE: set the default value of `Type` to `instant` when creating alerting rules. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/205). + ## [v0.9.1](https://github.com/VictoriaMetrics/victoriametrics-datasource/releases/tag/v0.9.1) * BUGFIX: fix parsing dots in the the `label_values` function in the query builder. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/198). diff --git a/src/querybuilder/state.ts b/src/querybuilder/state.ts index 1475e557..00812a6f 100755 --- a/src/querybuilder/state.ts +++ b/src/querybuilder/state.ts @@ -42,7 +42,7 @@ export function getQueryWithDefaults(query: PromQuery, app: CoreApp | undefined) result = { ...query, editorMode: getDefaultEditorMode(query.expr) }; } - if (query.expr == null) { + if (!query.expr) { result = { ...result, expr: '', legendFormat: LegendFormatMode.Auto }; } @@ -56,5 +56,10 @@ export function getQueryWithDefaults(query: PromQuery, app: CoreApp | undefined) } } + // Unified Alerting does not support "both" for query type – fall back to "range". + if (app === CoreApp.UnifiedAlerting) { + const isBothInstantAndRange = query.instant && query.range; + result = { ...result, range: isBothInstantAndRange, instant: !isBothInstantAndRange }; + } return result; }