influxdata / influxdata/kapacitor
The start time of the relative alert is wrong
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
I want to compare the current data with the data from 5 minutes ago.
so,I create the alert rules, the rules are as follows:
```
var db = '_internal'
var rp = 'monitor'
var measurement = 'database'
var groupBy = []
var whereFilter = lambda: TRUE
var name = 'greateralert'
var idVar = name + ':{{.Group}}'
var message = ' {{.ID}} {{ index .Fields "value" }} {{.Time}}'
var idTag = 'alertID'
var levelTag = 'level'
var messageField = 'message'
var durationField = 'duration'
var outputDB = 'chronograf'
var outputRP = 'autogen'
var outputMeasurement = 'alerts'
var triggerType = 'relative'
var shift = 5m
var crit = 6
var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|eval(lambda: "numMeasurements")
.as('value')
var past = data
|shift(shift)
var current = data
var trigger = past
|join(current)
.as('past', 'current')
|eval(lambda: float("current.value" - "past.value"))
.keep()
.as('value')
|alert()
.crit(lambda: "value" > crit)
.stateChangesOnly()
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.post('http://xxxxxxxx')
trigger
|eval(lambda: float("value"))
.as('value')
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag('alertName', name)
.tag('triggerType', triggerType)
trigger
|httpOut('output')
```
But the result is not what I want,It can't be compared to the past, and it always starts when the rules are created.
For example,The current time is 10:15, and I create the alert rule,It can only compare 10:20 minutes with 10:15 minutes instead of 10:15 and 10:10.the result is not what I want!
do you understand what I mean?
Contributor guide
Research direction
Reproduce the supplied TICKscript with the stream, shift, join, and alert pipeline, focusing on how the relative shift behaves when the rule is created. Trace the timing used by the shifted and current streams. Done means a rule created at 10:15 compares the current data with data from 10:10 rather than starting a new comparison window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100