influxdata / influxdata/kapacitor
Tick parse issue with eval node
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
kapacitor version: 1.4.0
When I use kapacitor to deal with tag values converting before really checking the alert rule, I found it really useful to use eval node. But I encountered some problems.
The problem is eval support a list of lambda as params. But I don't know how to do this right.
I tried `tag_mapping = [lambda: strToUpper("tag1"), lambda: strToUpper("tag2")]`. And the tick can't be compiled. The error message is
```
invalid TICKscript: parser: unexpected unknown state, last char: '{' line 24 char 20 in "apping = [{{lambda: ". expected: "identifier","string","*"
```
So I have to use a really ugly script to support this default value issue. My tick script is like below. Could you please tell me whether it is the only way to use a default value for list of lambda.
```
var measurement = 'measurement'
var metrics = ['metric1', 'metric2']
var filter = lambda: TRUE
var groups = [*]
var info = lambda: FALSE
var warn = lambda: FALSE
var crit = lambda: float("metric1") > 30
var mail_to = []
var title = '[{{ .Level }}][{{ index .Tags "environment"}}][{{ index .Tags "host" }}][{{ index .Tags "group" }}] Alert for {{ .TaskName }}'
var message = '''
{{ if eq .Level "OK" }}
The alert is recovered.
{{else}}
- {{ $key }}: {{ $value }}
{{ range $key, $value := .Fields}}
{{ end }}
{{end}}
'''
var host_convert = lambda: strToUpper("host")
var group_convert= lambda: strToUpper("group")
var env_convert = lambda: if("environment" == 'prod', 'PRD', strToUpper("environment"))
var tag_mapping = [host_convert, group_convert, env_convert]
var tag_list = ['host', 'group', 'environment']
var data = stream
|from()
.measurement(measurement)
.where(filter)
|eval(tag_mapping)
.as(tag_list)
.tags(tag_list)
.keep(metrics)
|groupBy(groups)
|log()
.prefix('level-1')
data
|alert()
.id('{{ .TaskName }}')
.message(title)
.details(message)
.info(info)
.warn(warn)
.crit(crit)
.stateChangesOnly()
.post('http://127.0.0.1:8089/api/events')
.email(mail_to)
```
Contributor guide
Research direction
Start with the TICKscript parser and the eval node entry point, using the reported list of lambda expressions as the reproduction. Determine whether list-valued lambda parameters can be parsed with the requested defaults, then verify that the documented or supported form compiles without the reported parser error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- observability-sre, stream-processing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100