mirror of
https://github.com/prymitive/karma
synced 2026-02-13 20:59:53 +00:00
fix(api): expose alert fingerprint in the API
This commit is contained in:
committed by
Łukasz Mierzwa
parent
6d5b6b1b7a
commit
c74479d435
@@ -44,21 +44,21 @@ type Alert struct {
|
||||
Alertmanager []AlertmanagerInstance `json:"alertmanager"`
|
||||
Receiver string `json:"receiver"`
|
||||
// fingerprints are precomputed for speed
|
||||
labelsFP string `hash:"-"`
|
||||
LabelsFP string `json:"id" hash:"-"`
|
||||
contentFP string `hash:"-"`
|
||||
}
|
||||
|
||||
// UpdateFingerprints will generate a new set of fingerprints for this alert
|
||||
// it should be called after modifying any field that isn't tagged with hash:"-"
|
||||
func (a *Alert) UpdateFingerprints() {
|
||||
a.labelsFP = fmt.Sprintf("%x", structhash.Sha1(a.Labels, 1))
|
||||
a.LabelsFP = fmt.Sprintf("%x", structhash.Sha1(a.Labels, 1))
|
||||
a.contentFP = fmt.Sprintf("%x", structhash.Sha1(a, 1))
|
||||
}
|
||||
|
||||
// LabelsFingerprint is a checksum computed only from labels which should be
|
||||
// unique for every alert
|
||||
func (a *Alert) LabelsFingerprint() string {
|
||||
return a.labelsFP
|
||||
return a.LabelsFP
|
||||
}
|
||||
|
||||
// ContentFingerprint is a checksum computed from entire alert object
|
||||
|
||||
@@ -122,7 +122,8 @@ func TestDedupSharedMaps(t *testing.T) {
|
||||
"inhibitedBy": null
|
||||
}
|
||||
],
|
||||
"receiver": ""
|
||||
"receiver": "",
|
||||
"id": ""
|
||||
},
|
||||
{
|
||||
"annotations": [],
|
||||
@@ -158,7 +159,8 @@ func TestDedupSharedMaps(t *testing.T) {
|
||||
"inhibitedBy": null
|
||||
}
|
||||
],
|
||||
"receiver": ""
|
||||
"receiver": "",
|
||||
"id": ""
|
||||
},
|
||||
{
|
||||
"annotations": [],
|
||||
@@ -194,7 +196,8 @@ func TestDedupSharedMaps(t *testing.T) {
|
||||
"inhibitedBy": null
|
||||
}
|
||||
],
|
||||
"receiver": ""
|
||||
"receiver": "",
|
||||
"id": ""
|
||||
}
|
||||
],
|
||||
"id": "",
|
||||
|
||||
Reference in New Issue
Block a user