influxdata / influxdata/kapacitor

Comparing with previous data if it none

Open
#2,313 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Hi!
I am trying to create a relative alert comparing with last data.
I wrote the script and it has worked fine still I needed comparing new data with none.
I have following script:
```
var current = batch
|query('select mean(total) as total_new from "Debug"."autogen"."debug" FILL(0)')
.period(1m)
.every(30s)
.align()
.groupBy('Message')
|log()

var past = batch
|query('select mean(total) as total_old from "Debug"."autogen"."debug" FILL(0)')
.period(1m)
.every(30s)
.align()
.offset(1m)
.groupBy('Message')
|shift(1m)
|log()

var trigger = past
|join(current)
.as('past', 'current')
|eval(lambda: float("current.total_new" - "past.total_old"))
.keep()
.as('value')
|alert()
.category('relative')
.crit(lambda: "value" > 0)
.message(message)
.stateChangesOnly()
.log('/var/log/alerts/batch_relative.log')
|log()
```
So the script is comparing current data with the data in previous 1 min interval then if value is greater than previous generates an alert.

**However, this script does not work if there is no data in previous interval, because Influx returns none while I need an alert in this case too (when in previous interval no data, but in current is).**

Is there any workaround for my case?

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files or tests; begin by reproducing the supplied Kapacitor script with an empty previous interval and inspect the query, shift, and join behavior. Done means establishing whether a current point can produce an alert when the previous interval has no data, with the resulting behavior or workaround documented.

Written by the indexing model from the issue text.

Assessment

Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.