Skip to content

Commit

Permalink
fixed alert text random order
Browse files Browse the repository at this point in the history
  • Loading branch information
dzyanis committed Mar 18, 2022
1 parent c51ff90 commit 03b49ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions cmd/sachet/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"sort"
"strings"

"github.com/prometheus/alertmanager/template"
Expand Down Expand Up @@ -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")
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/sachet/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand Down

0 comments on commit 03b49ff

Please sign in to comment.