Skip to content

Commit

Permalink
rule: fix panic when calling API /api/v1/rules?type=alert (#6189)
Browse files Browse the repository at this point in the history
Signed-off-by: Thibaut Ackermann <thibaut.ackermann@al-enterprise.com>
  • Loading branch information
thib-ack authored Mar 7, 2023
1 parent 7313a2c commit dabbeda
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/rules/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ func ActiveAlertsToProto(s storepb.PartialResponseStrategy, a *rules.AlertingRul
active := a.ActiveAlerts()
ret := make([]*rulespb.AlertInstance, len(active))
for i, ruleAlert := range active {
// UTC needed due to https://github.com/gogo/protobuf/issues/519.
activeAt := ruleAlert.ActiveAt.UTC()
ret[i] = &rulespb.AlertInstance{
PartialResponseStrategy: s,
Labels: labelpb.ZLabelSet{Labels: labelpb.ZLabelsFromPromLabels(ruleAlert.Labels)},
Annotations: labelpb.ZLabelSet{Labels: labelpb.ZLabelsFromPromLabels(ruleAlert.Annotations)},
State: rulespb.AlertState(ruleAlert.State),
ActiveAt: &ruleAlert.ActiveAt, //nolint:exportloopref
ActiveAt: &activeAt,
Value: strconv.FormatFloat(ruleAlert.Value, 'e', -1, 64),
}
}
Expand Down Expand Up @@ -399,7 +401,7 @@ func (m *Manager) Rules(r *rulespb.RulesRequest, s rulespb.Rules_RulesServer) (e

pgs := make([]*rulespb.RuleGroup, 0, len(groups))
for _, g := range groups {
// https://github.com/gogo/protobuf/issues/519
// UTC needed due to https://github.com/gogo/protobuf/issues/519.
g.LastEvaluation = g.LastEvaluation.UTC()
if r.Type == rulespb.RulesRequest_ALL {
pgs = append(pgs, g)
Expand Down

0 comments on commit dabbeda

Please sign in to comment.