Skip to content

Commit

Permalink
Fix generation of rules for SLOs without latency
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Dec 26, 2019
1 parent 148e0b7 commit 307b12d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (slo *SLO) GenerateAlertRules(sloClass *Class) []rulefmt.Rule {
}

latencyMethod := methods.Get(slo.LatencyRecord.AlertMethod)
if latencyMethod != nil {
if latencyMethod != nil && objectives.Latency != nil {
latencyRules := latencyMethod.AlertForLatency(slo.Name, objectives.Latency)
alertRules = append(alertRules, latencyRules...)
}
Expand Down
9 changes: 9 additions & 0 deletions slo/slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,12 @@ func TestSLOGenerateAlertRulesWithSLOCLass(t *testing.T) {
},
},
}
noLatencyClass := &Class{
Name: "LOW",
Objectives: Objectives{
Availability: 99,
},
}
slo := &SLO{
Name: "my-team.my-service.payment",
Class: "HIGH",
Expand Down Expand Up @@ -997,4 +1003,7 @@ func TestSLOGenerateAlertRulesWithSLOCLass(t *testing.T) {
},
Annotations: slo.Annotations,
})

alertRules = slo.GenerateAlertRules(noLatencyClass)
assert.Len(t, alertRules, 2)
}

0 comments on commit 307b12d

Please sign in to comment.