fix(api): expose alert fingerprint in the API

This commit is contained in:
Łukasz Mierzwa
2020-05-30 16:11:03 +01:00
committed by Łukasz Mierzwa
parent 6d5b6b1b7a
commit c74479d435
2 changed files with 9 additions and 6 deletions

View File

@@ -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

View File

@@ -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": "",