2016-06-06 03:31:21 -05:00
|
|
|
package alerting
|
|
|
|
|
2019-09-03 08:14:28 -05:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/null"
|
|
|
|
)
|
2017-01-13 05:32:30 -06:00
|
|
|
|
2019-06-06 09:39:35 -05:00
|
|
|
// Job holds state about when the alert rule should be evaluated.
|
2016-07-27 09:29:28 -05:00
|
|
|
type Job struct {
|
2019-09-03 08:14:28 -05:00
|
|
|
Offset int64
|
|
|
|
OffsetWait bool
|
|
|
|
Delay bool
|
|
|
|
running bool
|
|
|
|
Rule *Rule
|
|
|
|
runningLock sync.Mutex // Lock for running property which is used in the Scheduler and AlertEngine execution
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRunning returns true if the job is running. A lock is taken and released on the Job to ensure atomicity.
|
|
|
|
func (j *Job) GetRunning() bool {
|
|
|
|
defer j.runningLock.Unlock()
|
|
|
|
j.runningLock.Lock()
|
|
|
|
return j.running
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRunning sets the running property on the Job. A lock is taken and released on the Job to ensure atomicity.
|
|
|
|
func (j *Job) SetRunning(b bool) {
|
|
|
|
j.runningLock.Lock()
|
|
|
|
j.running = b
|
|
|
|
j.runningLock.Unlock()
|
2016-06-13 07:01:57 -05:00
|
|
|
}
|
|
|
|
|
2019-05-20 05:13:32 -05:00
|
|
|
// ResultLogEntry represents log data for the alert evaluation.
|
2016-07-27 09:29:28 -05:00
|
|
|
type ResultLogEntry struct {
|
2016-07-21 06:09:12 -05:00
|
|
|
Message string
|
|
|
|
Data interface{}
|
|
|
|
}
|
|
|
|
|
2020-06-01 10:11:25 -05:00
|
|
|
// EvalMatch represents the series violating the threshold.
|
2016-08-15 08:12:43 -05:00
|
|
|
type EvalMatch struct {
|
2017-01-13 05:32:30 -06:00
|
|
|
Value null.Float `json:"value"`
|
2016-11-08 07:53:13 -06:00
|
|
|
Metric string `json:"metric"`
|
|
|
|
Tags map[string]string `json:"tags"`
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|