mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
fix(style): check of WriteString error return
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/cnf/structhash"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// AlertList is flat list of UnseeAlert objects
|
||||
@@ -46,8 +48,17 @@ type AlertGroup struct {
|
||||
// it should be unique for each AlertGroup
|
||||
func (ag AlertGroup) LabelsFingerprint() string {
|
||||
agIDHasher := sha1.New()
|
||||
io.WriteString(agIDHasher, ag.Receiver)
|
||||
io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1)))
|
||||
|
||||
_, err := io.WriteString(agIDHasher, ag.Receiver)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write receiver value to alertgroup '%s' fingerprint: %s", ag.ID, err)
|
||||
}
|
||||
|
||||
_, err = io.WriteString(agIDHasher, fmt.Sprintf("%x", structhash.Sha1(ag.Labels, 1)))
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write labels sha1 value to alertgroup '%s' fingerprint: %s", ag.ID, err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%x", agIDHasher.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -55,7 +66,10 @@ func (ag AlertGroup) LabelsFingerprint() string {
|
||||
func (ag AlertGroup) ContentFingerprint() string {
|
||||
h := sha1.New()
|
||||
for _, alert := range ag.Alerts {
|
||||
io.WriteString(h, alert.ContentFingerprint())
|
||||
_, err := io.WriteString(h, alert.ContentFingerprint())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write alert fingerprint value to alertgroup '%s' fingerprint: %s", ag.ID, err)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -10,12 +10,23 @@ import (
|
||||
"github.com/prymitive/unsee/internal/slices"
|
||||
|
||||
"github.com/hansrodtang/randomcolor"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func labelToSeed(key string, val string) int64 {
|
||||
h := sha1.New()
|
||||
io.WriteString(h, key)
|
||||
io.WriteString(h, val)
|
||||
|
||||
_, err := io.WriteString(h, key)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write label key '%s' to the seed sha1: %s", key, err)
|
||||
}
|
||||
|
||||
_, err = io.WriteString(h, val)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to write label value '%s' to the seed sha1: %s", val, err)
|
||||
}
|
||||
|
||||
var seed int64
|
||||
for _, i := range h.Sum(nil) {
|
||||
seed += int64(i)
|
||||
|
||||
Reference in New Issue
Block a user