From 03b49ffb3fa9c4a97d43609645290a50aa076b9d Mon Sep 17 00:00:00 2001 From: Dzyanis Kuzmenka Date: Fri, 18 Mar 2022 23:13:33 +0300 Subject: [PATCH] fixed alert text random order --- Makefile | 14 ++++++++++++++ cmd/sachet/handlers.go | 2 ++ cmd/sachet/handlers_test.go | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f4221c --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +linter: + ./bin/golangci-lint run ./... --timeout=5m +.PHONY: linter + +linter.download: + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh +.PHONY: linter.download + +test: + env CGO_ENABLED=1 go test -race ./... +.PHONY: test + +alltest: linter test +.PHONY: alltest diff --git a/cmd/sachet/handlers.go b/cmd/sachet/handlers.go index 8ffc256..cafe170 100644 --- a/cmd/sachet/handlers.go +++ b/cmd/sachet/handlers.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "sort" "strings" "github.com/prometheus/alertmanager/template" @@ -42,6 +43,7 @@ func newAlertText(data template.Data) string { for k, v := range alert.Labels { tuples = append(tuples, k+"= "+v) } + sort.Strings(tuples) return strings.ToUpper(data.Status) + " \n" + strings.Join(tuples, "\n") } diff --git a/cmd/sachet/handlers_test.go b/cmd/sachet/handlers_test.go index 5c61fcc..5fe3dfd 100644 --- a/cmd/sachet/handlers_test.go +++ b/cmd/sachet/handlers_test.go @@ -30,7 +30,7 @@ func Test_newAlertText(t *testing.T) { exp: " \n", }, { - name: "alerts labels", + name: "alert labels", data: template.Data{ Alerts: template.Alerts{ template.Alert{ @@ -42,7 +42,7 @@ func Test_newAlertText(t *testing.T) { }, }, }, - exp: " \nalertname= a\ninstance= a\nexported_instance= a", + exp: " \nalertname= a\nexported_instance= a\ninstance= a", }, { name: "common labels",