Skip to content

Commit

Permalink
rule: fix panic when calling API /api/v1/rules?type=alert
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 committed Mar 7, 2023
1 parent 7313a2c commit cadc99f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/rules/manager.go
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 cadc99f

Please sign in to comment.