influxdata / influxdata/kapacitor
alert + influxDBOut with different names are not working
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
I'm trying to make template script for metrics generation,but cannot use one value with different names (same for alert and influxDBOut)
```
var apiName = 'MobileApi'
var errorRateName = 'MobileApi_errorrate'
var resultDb = 'test'
var period = 5s
var total = stream
|from()
.database('metrics')
.retentionPolicy('autogen')
.measurement('metrics')
|default()
.tag('is-test', '')
|where(lambda: "is-test" != '1i')
|window()
.period(period)
.every(period)
.align()
|count(apiName)
var errors = stream
|from()
.database('metrics')
.retentionPolicy('autogen')
.measurement('metrics')
|default()
.tag('is-test', '')
.tag('is-error', '')
|where(lambda: "is-test" != '1i' AND "is-error" == 'True')
|window()
.period(period)
.every(period)
.align()
|count(apiName)
var errorRate = errors
|join(total)
.as('err', 'tot')
|eval(lambda: float("err.count") / float("tot.count") * 100.0)
var errorRateForDb = errorRate
.as(errorRateName)
var errorRateForAlert = errorRate
.as('errorrate_value')
// Alert
errorRateForAlert
|alert()
.id(errorRateName)
.crit(lambda: "errorrate_value" >= 50)
.critReset(lambda: "errorrate_value" < 50)
.warn(lambda: "errorrate_value" >= 10)
.warnReset(lambda: "errorrate_value" < 10)
.stateChangesOnly()
.message('{{ .ID }} value: {{index .Fields "errorrate_value"}}')
.slack()
errorRateForDb
|influxDBOut()
.database(resultDb)
.retentionPolicy('autogen')
.measurement('mainmetrics')
```
This script is working, but influxDBOut write value name as 'errorrate_value' not 'MobileApi'
this is strange, because 'errorrate_value' is set for errorRateForAlert and it is not linked with influxDBOut
If I don't use 'as' construction - all will work as expected, but I need to define 'MobileApi' also in
```
.crit(lambda: "errorrate_value" >= 50)
.critReset(lambda: "errorrate_value" < 50)
.warn(lambda: "errorrate_value" >= 10)
.warnReset(lambda: "errorrate_value" < 10)
```
block, and it will be not good template
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied TICKscript and start by tracing how the `as()` calls affect the shared `errorRate` stream before it reaches `alert()` and `influxDBOut()`. Done means the alert can use `errorrate_value` while the database output preserves `MobileApi`; the payload names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Domain
- databases, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100