From 307b12d7824d70e03d3f23ae18f02d5d190a04c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wilson=20J=C3=BAnior?= Date: Thu, 26 Dec 2019 17:05:54 -0300 Subject: [PATCH] Fix generation of rules for SLOs without latency --- slo/slo.go | 2 +- slo/slo_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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) }