diff --git a/slo/slo.go b/slo/slo.go index 80d6694..d1a12c9 100644 --- a/slo/slo.go +++ b/slo/slo.go @@ -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...) } diff --git a/slo/slo_test.go b/slo/slo_test.go index 9419763..d48a8f5 100644 --- a/slo/slo_test.go +++ b/slo/slo_test.go @@ -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", @@ -997,4 +1003,7 @@ func TestSLOGenerateAlertRulesWithSLOCLass(t *testing.T) { }, Annotations: slo.Annotations, }) + + alertRules = slo.GenerateAlertRules(noLatencyClass) + assert.Len(t, alertRules, 2) }