فهرست منبع

style(alerting): improve naming

bergquist 9 سال پیش
والد
کامیت
3ad90c389c

+ 3 - 4
pkg/services/alerting/engine.go

@@ -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)
 		}
 	}

+ 12 - 0
pkg/services/alerting/models.go

@@ -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

+ 0 - 0
pkg/services/alerting/alerting_test.go → pkg/services/alerting/reader_test.go


+ 3 - 2
pkg/services/sqlstore/alert_state.go

@@ -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