Skip to content

Commit

Permalink
Set default Type to instant for alert rules (#207)
Browse files Browse the repository at this point in the history
* feature: set default Type to instant for alert rules #205

* Update CHANGELOG.md

---------

Co-authored-by: Roman Khavronenko <[email protected]>
  • Loading branch information
Loori-R and hagen1778 authored Oct 8, 2024
1 parent 3bbac17 commit f2ea5c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## tip

* FEATURE: set the default query 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).
Expand Down
7 changes: 6 additions & 1 deletion src/querybuilder/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand All @@ -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;
}

0 comments on commit f2ea5c5

Please sign in to comment.