diff --git a/algorithms/register.go b/algorithms/register.go deleted file mode 100644 index fee0395..0000000 --- a/algorithms/register.go +++ /dev/null @@ -1 +0,0 @@ -package algoritms diff --git a/algorithms/algorithm.go b/methods/method.go similarity index 57% rename from algorithms/algorithm.go rename to methods/method.go index d98ae3a..3c88d9d 100644 --- a/algorithms/algorithm.go +++ b/methods/method.go @@ -1,21 +1,21 @@ -package algoritms +package methods import "github.com/prometheus/prometheus/pkg/rulefmt" -type AlertAlgorithm interface { +type AlertMethod interface { AlertForError(serviceName string, availabilityTarget float64, annotations map[string]string) []rulefmt.Rule AlertForLatency(serviceName string, targets []LatencyTarget, annotations map[string]string) []rulefmt.Rule } -var algorithms = map[string]AlertAlgorithm{} +var methods = map[string]AlertMethod{} -func register(algorithm AlertAlgorithm, name string) AlertAlgorithm { - algorithms[name] = algorithm - return algorithm +func register(method AlertMethod, name string) AlertMethod { + methods[name] = method + return method } -func Get(name string) AlertAlgorithm { - return algorithms[name] +func Get(name string) AlertMethod { + return methods[name] } type LatencyTarget struct { diff --git a/algorithms/multi-window.go b/methods/multi-window.go similarity index 99% rename from algorithms/multi-window.go rename to methods/multi-window.go index 49b46d3..196d88a 100644 --- a/algorithms/multi-window.go +++ b/methods/multi-window.go @@ -1,4 +1,4 @@ -package algoritms +package methods import ( "fmt" diff --git a/slo/slo.go b/slo/slo.go index fd6ab99..aee7f82 100644 --- a/slo/slo.go +++ b/slo/slo.go @@ -4,7 +4,7 @@ import ( "log" "strings" - algorithms "github.com/globocom/slo-generator/algorithms" + methods "github.com/globocom/slo-generator/methods" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/rulefmt" ) @@ -14,8 +14,8 @@ type SLOSpec struct { } type ExprBlock struct { - AlertAlgorithm string `yaml:"alertAlgorithm"` - Expr string `yaml:"expr"` + AlertMethod string `yaml:"alertMethod"` + Expr string `yaml:"expr"` } func (block *ExprBlock) ComputeExpr(window, le string) string { @@ -24,26 +24,26 @@ func (block *ExprBlock) ComputeExpr(window, le string) string { } type SLO struct { - Name string `yaml:"name"` - AvailabilityObjectivePercent float64 `yaml:"availabilityObjectivePercent"` - LatencyObjectiveBuckets []algorithms.LatencyTarget `yaml:"latencyObjectiveBuckets"` - ErrorRateRecord ExprBlock `yaml:"errorRateRecord"` - LatencyRecord ExprBlock `yaml:"latencyRecord"` - Annotations map[string]string `yaml:"annotations"` + Name string `yaml:"name"` + AvailabilityObjectivePercent float64 `yaml:"availabilityObjectivePercent"` + LatencyObjectiveBuckets []methods.LatencyTarget `yaml:"latencyObjectiveBuckets"` + ErrorRateRecord ExprBlock `yaml:"errorRateRecord"` + LatencyRecord ExprBlock `yaml:"latencyRecord"` + Annotations map[string]string `yaml:"annotations"` } func (slo SLO) GenerateAlertRules() []rulefmt.Rule { alertRules := []rulefmt.Rule{} - errorAlgorithm := algorithms.Get(slo.ErrorRateRecord.AlertAlgorithm) - if errorAlgorithm != nil { - errorRules := errorAlgorithm.AlertForError(slo.Name, slo.AvailabilityObjectivePercent, slo.Annotations) + errorMethod := methods.Get(slo.ErrorRateRecord.AlertMethod) + if errorMethod != nil { + errorRules := errorMethod.AlertForError(slo.Name, slo.AvailabilityObjectivePercent, slo.Annotations) alertRules = append(alertRules, errorRules...) } - latencyAlgorithm := algorithms.Get(slo.LatencyRecord.AlertAlgorithm) - if latencyAlgorithm != nil { - latencyRules := errorAlgorithm.AlertForLatency(slo.Name, slo.LatencyObjectiveBuckets, slo.Annotations) + latencyMethod := methods.Get(slo.LatencyRecord.AlertMethod) + if latencyMethod != nil { + latencyRules := latencyMethod.AlertForLatency(slo.Name, slo.LatencyObjectiveBuckets, slo.Annotations) alertRules = append(alertRules, latencyRules...) } diff --git a/slo/slo_test.go b/slo/slo_test.go index cbb7094..e247ffb 100644 --- a/slo/slo_test.go +++ b/slo/slo_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - algorithms "github.com/globocom/slo-generator/algorithms" + methods "github.com/globocom/slo-generator/methods" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/rulefmt" "github.com/stretchr/testify/assert" @@ -14,7 +14,7 @@ func TestSLOGenerateGroupRules(t *testing.T) { slo := &SLO{ Name: "my-team.my-service.payment", AvailabilityObjectivePercent: 99.9, - LatencyObjectiveBuckets: []algorithms.LatencyTarget{ + LatencyObjectiveBuckets: []methods.LatencyTarget{ { LE: "0.1", Target: 90, @@ -25,12 +25,12 @@ func TestSLOGenerateGroupRules(t *testing.T) { }, }, ErrorRateRecord: ExprBlock{ - AlertAlgorithm: "multi-window", - Expr: "sum(rate(http_errors[$window]))/sum(rate(http_total[$window]))", + AlertMethod: "multi-window", + Expr: "sum(rate(http_errors[$window]))/sum(rate(http_total[$window]))", }, LatencyRecord: ExprBlock{ - AlertAlgorithm: "multi-window", - Expr: "sum(rate(http_bucket{le=\"$le\"}[$window]))/sum(rate(http_total[$window]))", + AlertMethod: "multi-window", + Expr: "sum(rate(http_bucket{le=\"$le\"}[$window]))/sum(rate(http_total[$window]))", }, Annotations: map[string]string{ "message": "Service A has lower SLI", @@ -240,7 +240,7 @@ func TestSLOGenerateAlertRules(t *testing.T) { slo := &SLO{ Name: "my-team.my-service.payment", AvailabilityObjectivePercent: 99.9, - LatencyObjectiveBuckets: []algorithms.LatencyTarget{ + LatencyObjectiveBuckets: []methods.LatencyTarget{ { LE: "0.1", Target: 95, @@ -251,12 +251,12 @@ func TestSLOGenerateAlertRules(t *testing.T) { }, }, ErrorRateRecord: ExprBlock{ - AlertAlgorithm: "multi-window", - Expr: "kk", + AlertMethod: "multi-window", + Expr: "kk", }, LatencyRecord: ExprBlock{ - AlertAlgorithm: "multi-window", - Expr: "kk", + AlertMethod: "multi-window", + Expr: "kk", }, Annotations: map[string]string{ "message": "Service A has lower SLI", diff --git a/slo_example.yml b/slo_example.yml index aa5132c..a99d4eb 100644 --- a/slo_example.yml +++ b/slo_example.yml @@ -14,13 +14,13 @@ slos: slack_channel: '_team_a' errorRateRecord: - algorithm: multi-window + alertMethod: multi-window expr: | sum (rate(http_requests_total{job="service-a", status="5xx"}[$window])) / sum (rate(http_requests_total{job="service-a"}[$window])) latencyRecord: - algorithm: multi-window + alertMethod: multi-window expr: | sum (rate(http_request_duration_seconds_bucket{job="service-a", le="$le"}[$window])) / sum (rate(http_requests_total{job="service-a"}[$window])) @@ -41,13 +41,13 @@ slos: slack_channel: '_team_b' errorRateRecord: - algorithm: multi-window + alertMethod: multi-window expr: | sum (rate(http_requests_total{job="service-b", status="5xx"}[$window])) / sum (rate(http_requests_total{job="service-b"}[$window])) latencyRecord: - algorithm: multi-window + alertMethod: multi-window expr: | sum (rate(http_request_duration_seconds_bucket{job="service-b", le="$le"}[$window])) / sum (rate(http_requests_total{job="service-b"}[$window]))