mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
style(alerting): improve naming
This commit is contained in:
parent
04436c8a52
commit
3ad90c389c
@ -108,11 +108,10 @@ func (e *Engine) resultHandler() {
|
||||
|
||||
result.AlertJob.Running = false
|
||||
|
||||
// handle result error
|
||||
if result.Error != nil {
|
||||
result.AlertJob.RetryCount++
|
||||
result.AlertJob.IncRetry()
|
||||
|
||||
if result.AlertJob.RetryCount < maxRetries {
|
||||
if result.AlertJob.Retryable() {
|
||||
e.log.Error("Alert Rule Result Error", "ruleId", result.AlertJob.Rule.Id, "error", result.Error, "retry", result.AlertJob.RetryCount)
|
||||
e.execQueue <- result.AlertJob
|
||||
} else {
|
||||
@ -123,7 +122,7 @@ func (e *Engine) resultHandler() {
|
||||
e.saveState(result)
|
||||
}
|
||||
} else {
|
||||
result.AlertJob.RetryCount = 0
|
||||
result.AlertJob.ResetRetry()
|
||||
e.saveState(result)
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,18 @@ type AlertJob struct {
|
||||
Rule *AlertRule
|
||||
}
|
||||
|
||||
func (aj *AlertJob) Retryable() bool {
|
||||
return aj.RetryCount < maxRetries
|
||||
}
|
||||
|
||||
func (aj *AlertJob) ResetRetry() {
|
||||
aj.RetryCount = 0
|
||||
}
|
||||
|
||||
func (aj *AlertJob) IncRetry() {
|
||||
aj.RetryCount++
|
||||
}
|
||||
|
||||
type AlertResult struct {
|
||||
State string
|
||||
ActualValue float64
|
||||
|
@ -31,13 +31,14 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
||||
}
|
||||
|
||||
if alert.State == cmd.NewState {
|
||||
cmd.Result = &m.Alert{}
|
||||
return nil
|
||||
}
|
||||
|
||||
alert.State = cmd.NewState
|
||||
sess.Id(alert.Id).Update(&alert)
|
||||
|
||||
log := m.AlertState{
|
||||
alertState := m.AlertState{
|
||||
AlertId: cmd.AlertId,
|
||||
OrgId: cmd.AlertId,
|
||||
NewState: cmd.NewState,
|
||||
@ -45,7 +46,7 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
||||
Created: time.Now(),
|
||||
}
|
||||
|
||||
sess.Insert(&log)
|
||||
sess.Insert(&alertState)
|
||||
|
||||
cmd.Result = &alert
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user