Skip to content

Commit

Permalink
use JIRALERT{hash...} issue label to make the origin clear
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Gwosdz <jgwosdz@redhat.com>
  • Loading branch information
erdii committed Mar 5, 2021
1 parent 97c6057 commit f6dce05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func deepCopyWithTemplate(value interface{}, tmpl *template.Template, data inter
// toGroupTicketLabel returns the group labels as a single string.
// This is used to reference each ticket groups.
// (old) default behavior: String is the form of an ALERT Prometheus metric name, with all spaces removed.
// new opt-in behavior: String is the form of ALERT{sha512hash(groupLabels)}
// new opt-in behavior: String is the form of JIRALERT{sha512hash(groupLabels)}
// hashing ensures that JIRA validation still accepts the output even
// if the combined length of all groupLabel key-value pairs would be
// longer than 255 chars
Expand All @@ -239,7 +239,7 @@ func toGroupTicketLabel(groupLabels alertmanager.KV, hashJiraLabel bool) string
kvString := fmt.Sprintf("%s=%q,", p.Name, p.Value)
_, _ = hash.Write([]byte(kvString)) // hash.Write can never return an error
}
return fmt.Sprintf("ALERT{%x}", hash.Sum(nil))
return fmt.Sprintf("JIRALERT{%x}", hash.Sum(nil))
}

// old default behavior
Expand Down
22 changes: 11 additions & 11 deletions pkg/notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestToGroupTicketLabel(t *testing.T) {
require.Equal(t, `ALERT{9897cb21a3d1ba47d2aab501ce9bc60b74bf65e26658f8e34a7fc81705e6b6eadfe6ad8edfe7c68142b3fe10f2c89127bd85e5f3687fe6b9ff1eff4b3f71dd49}`, toGroupTicketLabel(alertmanager.KV{"a": "B", "C": "d"}, true))
require.Equal(t, `JIRALERT{9897cb21a3d1ba47d2aab501ce9bc60b74bf65e26658f8e34a7fc81705e6b6eadfe6ad8edfe7c68142b3fe10f2c89127bd85e5f3687fe6b9ff1eff4b3f71dd49}`, toGroupTicketLabel(alertmanager.KV{"a": "B", "C": "d"}, true))
require.Equal(t, `ALERT{C="d",a="B"}`, toGroupTicketLabel(alertmanager.KV{"a": "B", "C": "d"}, false))
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: "NotDone"},
},
Expand All @@ -204,7 +204,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Unknowns: tcontainer.MarshalMap{},
Summary: "[FIRING:2] b d ",
},
Expand All @@ -226,7 +226,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: "NotDone"},
},
Expand All @@ -246,7 +246,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Unknowns: tcontainer.MarshalMap{},
Summary: "[FIRING:2] b d ",
Resolution: &jira.Resolution{
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: testReceiverConfig1().ReopenState}, // Status reopened
},
Expand All @@ -301,7 +301,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Unknowns: tcontainer.MarshalMap{},
Summary: "[FIRING:2] b d ",
Resolution: &jira.Resolution{
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: "done"},
},
Expand All @@ -356,7 +356,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Unknowns: tcontainer.MarshalMap{},
Summary: "[FIRING:2] b d ",
Resolution: &jira.Resolution{
Expand Down Expand Up @@ -387,7 +387,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "1",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: "done"},
},
Expand All @@ -406,7 +406,7 @@ func TestNotify_JIRAInteraction(t *testing.T) {
Key: "2",
Fields: &jira.IssueFields{
Project: jira.Project{Key: testReceiverConfig1().Project},
Labels: []string{"ALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"},
Status: &jira.Status{
StatusCategory: jira.StatusCategory{Key: "NotDone"}, // Created
},
Expand Down

0 comments on commit f6dce05

Please sign in to comment.