influxdata / influxdata/kapacitor

alert + influxDBOut with different names are not working

Open
#2,233 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.