models.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package alerting
  2. import (
  3. "sync"
  4. "github.com/grafana/grafana/pkg/components/null"
  5. )
  6. // Job holds state about when the alert rule should be evaluated.
  7. type Job struct {
  8. Offset int64
  9. OffsetWait bool
  10. Delay bool
  11. running bool
  12. Rule *Rule
  13. runningLock sync.Mutex // Lock for running property which is used in the Scheduler and AlertEngine execution
  14. }
  15. // GetRunning returns true if the job is running. A lock is taken and released on the Job to ensure atomicity.
  16. func (j *Job) GetRunning() bool {
  17. defer j.runningLock.Unlock()
  18. j.runningLock.Lock()
  19. return j.running
  20. }
  21. // SetRunning sets the running property on the Job. A lock is taken and released on the Job to ensure atomicity.
  22. func (j *Job) SetRunning(b bool) {
  23. j.runningLock.Lock()
  24. j.running = b
  25. j.runningLock.Unlock()
  26. }
  27. // ResultLogEntry represents log data for the alert evaluation.
  28. type ResultLogEntry struct {
  29. Message string
  30. Data interface{}
  31. }
  32. // EvalMatch represents the serie violating the threshold.
  33. type EvalMatch struct {
  34. Value null.Float `json:"value"`
  35. Metric string `json:"metric"`
  36. Tags map[string]string `json:"tags"`
  37. }