mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
[Alerting]: some fixes (#33538)
* Fix fialure when adding state annotations * Fix get org rules API Do not fail response if user has no access to view a namespace. Do not include the namespace in the response instead. * lint
This commit is contained in:
committed by
GitHub
parent
adc68a310e
commit
1e380e869e
@@ -36,6 +36,14 @@ func resultNormal(alertState *State, result eval.Result) *State {
|
||||
return newState
|
||||
}
|
||||
|
||||
// addAnnotation adds an annotation to the state.
|
||||
func (a *State) addAnnotation(key, value string) {
|
||||
if a.Annotations == nil {
|
||||
a.Annotations = make(map[string]string)
|
||||
}
|
||||
a.Annotations[key] = value
|
||||
}
|
||||
|
||||
func (a *State) resultAlerting(alertRule *ngModels.AlertRule, result eval.Result) *State {
|
||||
switch a.State {
|
||||
case eval.Alerting:
|
||||
@@ -51,19 +59,19 @@ func (a *State) resultAlerting(alertRule *ngModels.AlertRule, result eval.Result
|
||||
a.State = eval.Alerting
|
||||
a.StartsAt = result.EvaluatedAt
|
||||
a.EndsAt = result.EvaluatedAt.Add(alertRule.For)
|
||||
a.Annotations["alerting_at"] = result.EvaluatedAt.String()
|
||||
a.addAnnotation("alerting_at", result.EvaluatedAt.String())
|
||||
}
|
||||
default:
|
||||
a.StartsAt = result.EvaluatedAt
|
||||
if !(alertRule.For > 0) {
|
||||
a.EndsAt = result.EvaluatedAt.Add(time.Duration(alertRule.IntervalSeconds*2) * time.Second)
|
||||
a.State = eval.Alerting
|
||||
a.Annotations["alerting_at"] = result.EvaluatedAt.String()
|
||||
a.addAnnotation("alerting_at", result.EvaluatedAt.String())
|
||||
} else {
|
||||
a.EndsAt = result.EvaluatedAt.Add(alertRule.For)
|
||||
if result.EvaluatedAt.Sub(a.StartsAt) > alertRule.For {
|
||||
a.State = eval.Alerting
|
||||
a.Annotations["alerting_at"] = result.EvaluatedAt.String()
|
||||
a.addAnnotation("alerting_at", result.EvaluatedAt.String())
|
||||
} else {
|
||||
a.State = eval.Pending
|
||||
}
|
||||
@@ -82,7 +90,7 @@ func (a *State) resultError(alertRule *ngModels.AlertRule, result eval.Result) *
|
||||
a.EndsAt = result.EvaluatedAt.Add(alertRule.For)
|
||||
}
|
||||
if a.State != eval.Error {
|
||||
a.Annotations["last_error"] = result.EvaluatedAt.String()
|
||||
a.addAnnotation("last_error", result.EvaluatedAt.String())
|
||||
}
|
||||
|
||||
switch alertRule.ExecErrState {
|
||||
@@ -103,7 +111,7 @@ func (a *State) resultNoData(alertRule *ngModels.AlertRule, result eval.Result)
|
||||
a.EndsAt = result.EvaluatedAt.Add(alertRule.For)
|
||||
}
|
||||
if a.State != eval.NoData {
|
||||
a.Annotations["no_data"] = result.EvaluatedAt.String()
|
||||
a.addAnnotation("no_data", result.EvaluatedAt.String())
|
||||
}
|
||||
|
||||
switch alertRule.NoDataState {
|
||||
|
||||
Reference in New Issue
Block a user