From 8c29046ab200ce1881955776b9dd0bcd56824c95 Mon Sep 17 00:00:00 2001 From: Levi Harrison Date: Fri, 20 Aug 2021 16:42:31 -0400 Subject: [PATCH] Remove unneeded state modifications Signed-off-by: Levi Harrison --- rules/alerting.go | 13 +------------ rules/manager.go | 2 ++ rules/recording.go | 7 +------ 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/rules/alerting.go b/rules/alerting.go index 122a83c06..15cd1cf60 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -300,8 +300,6 @@ const resolvedRetention = 15 * time.Minute func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, externalURL *url.URL) (promql.Vector, error) { res, err := query(ctx, r.vector.String(), ts) if err != nil { - r.SetHealth(HealthBad) - r.SetLastError(err) return nil, err } @@ -366,12 +364,7 @@ func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, resultFPs[h] = struct{}{} if _, ok := alerts[h]; ok { - err = fmt.Errorf("vector contains metrics with the same labelset after applying alert labels") - // We have already acquired the lock above hence using SetHealth and - // SetLastError will deadlock. - r.health = HealthBad - r.lastError = err - return nil, err + return nil, fmt.Errorf("vector contains metrics with the same labelset after applying alert labels") } alerts[h] = &Alert{ @@ -421,10 +414,6 @@ func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc, } } - // We have already acquired the lock above hence using SetHealth and - // SetLastError will deadlock. - r.health = HealthGood - r.lastError = err return vec, nil } diff --git a/rules/manager.go b/rules/manager.go index 837a0741f..63186d1d8 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -604,6 +604,8 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) { } return } + rule.SetHealth(HealthGood) + rule.SetLastError(nil) samplesTotal += float64(len(vector)) if ar, ok := rule.(*AlertingRule); ok { diff --git a/rules/recording.go b/rules/recording.go index 2665506af..1ffe98cbd 100644 --- a/rules/recording.go +++ b/rules/recording.go @@ -96,14 +96,9 @@ func (rule *RecordingRule) Eval(ctx context.Context, ts time.Time, query QueryFu // Check that the rule does not produce identical metrics after applying // labels. if vector.ContainsSameLabelset() { - err = fmt.Errorf("vector contains metrics with the same labelset after applying rule labels") - rule.SetHealth(HealthBad) - rule.SetLastError(err) - return nil, err + return nil, fmt.Errorf("vector contains metrics with the same labelset after applying rule labels") } - rule.SetHealth(HealthGood) - rule.SetLastError(err) return vector, nil }