-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better grouping alert & pagerduty receiver fix (#172)
* fix(alert): better grouping when sending notification * fix(pagerduty): proper incident key to resolve and silent when acked
- Loading branch information
Showing
16 changed files
with
359 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package notification | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"github.com/mitchellh/hashstructure/v2" | ||
"github.com/odpf/siren/core/alert" | ||
) | ||
|
||
func removeDuplicateStringValues(strSlice []string) []string { | ||
keys := make(map[string]bool) | ||
list := []string{} | ||
|
||
for _, v := range strSlice { | ||
if _, value := keys[v]; !value { | ||
keys[v] = true | ||
list = append(list, v) | ||
} | ||
} | ||
return list | ||
} | ||
|
||
func groupByLabels(alerts []alert.Alert) (map[uint64][]alert.Alert, error) { | ||
var alertsMap = map[uint64][]alert.Alert{} | ||
|
||
for _, a := range alerts { | ||
hash, err := hashstructure.Hash(a.Labels, hashstructure.FormatV2, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get hash from alert %v", a) | ||
} | ||
alertsMap[hash] = append(alertsMap[hash], a) | ||
} | ||
|
||
return alertsMap, nil | ||
} | ||
|
||
// hashGroupKey hash groupKey from alert and hashKey from labels | ||
func hashGroupKey(groupKey string, hashKey uint64) string { | ||
h := sha256.New() | ||
// hash.Hash.Write never returns an error. | ||
//nolint: errcheck | ||
h.Write([]byte(fmt.Sprintf("%s%d", groupKey, hashKey))) | ||
return fmt.Sprintf("%x", h.Sum(nil)) | ||
} |
Oops, something went wrong.