mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +00:00
vmalert-989: return non-empty result in template func query
stub to pass validation (#1002)
On templates validation stage vmalert does not acutally send queries, so for complex chained expression validation may fail. To avoid this, we add a blank sample in response so validation can pass successfully. Later, during the rule execution, stub will be replaced with real `query` function. https://github.com/VictoriaMetrics/VictoriaMetrics/issues/989
This commit is contained in:
parent
4ee53c3961
commit
304512b668
2 changed files with 4 additions and 1 deletions
|
@ -17,6 +17,7 @@ groups:
|
||||||
(up == 1)
|
(up == 1)
|
||||||
labels:
|
labels:
|
||||||
job: '{{ $labels.job }}'
|
job: '{{ $labels.job }}'
|
||||||
|
dynamic: '{{ $x := query "up" | first | value }}{{ if eq 1.0 $x }}one{{ else }}unknown{{ end }}'
|
||||||
annotations:
|
annotations:
|
||||||
description: Job {{ $labels.job }} is up!
|
description: Job {{ $labels.job }} is up!
|
||||||
summary: All instances up {{ range query "up" }}
|
summary: All instances up {{ range query "up" }}
|
||||||
|
|
|
@ -178,7 +178,9 @@ func InitTemplateFunc(externalURL *url.URL) {
|
||||||
// it is present here only for validation purposes, when there is no
|
// it is present here only for validation purposes, when there is no
|
||||||
// provided datasource.
|
// provided datasource.
|
||||||
"query": func(q string) ([]datasource.Metric, error) {
|
"query": func(q string) ([]datasource.Metric, error) {
|
||||||
return nil, nil
|
// return non-empty slice to pass validation with chained functions in template
|
||||||
|
// see issue #989 for details
|
||||||
|
return []datasource.Metric{{}}, nil
|
||||||
},
|
},
|
||||||
"first": func(metrics []datasource.Metric) (datasource.Metric, error) {
|
"first": func(metrics []datasource.Metric) (datasource.Metric, error) {
|
||||||
if len(metrics) > 0 {
|
if len(metrics) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue