From 680bd5b9c0eca43ad81f541a4aba889ac070a688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 10 May 2017 18:10:51 +0100 Subject: [PATCH 1/4] Expose alert fingerprint in the API Alert fingerprint is already provided as the value of status.inhibitedBy[] attribute that inhibited alerts have, but there's no way to get back to the alert that's inhibiting it as the fingerprint is not exposed. --- dispatch/dispatch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index b6681e68ec..be1b629e56 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -82,6 +82,7 @@ type APIAlert struct { *model.Alert Status types.AlertStatus `json:"status"` Receivers []string `json:"receivers"` + ID string `json:"id"` } // AlertGroup is a list of alert blocks grouped by the same label set. @@ -138,6 +139,7 @@ func (d *Dispatcher) Groups(matchers []*labels.Matcher) AlertOverview { aa := &APIAlert{ Alert: a, Status: status, + ID: fmt.Sprintf("%d", a.Fingerprint()), } if !matchesFilterLabels(aa, matchers) { From d714dcf47aa962c7de14941b62131d93813984b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 7 Jun 2017 20:42:18 -0700 Subject: [PATCH 2/4] Expose alert fingerprint as ID in the list endpoint --- api/api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/api.go b/api/api.go index 51828c89dc..53442e7b8f 100644 --- a/api/api.go +++ b/api/api.go @@ -346,6 +346,7 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { Alert: &a.Alert, Status: status, Receivers: receivers, + ID: fmt.Sprintf("%x", a.Fingerprint()), } res = append(res, apiAlert) From 8ab0ea849d3d5564561fd14175aaba66898d6c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 14 Aug 2017 10:18:06 -0700 Subject: [PATCH 3/4] Rename ID to Fingerprint --- api/api.go | 8 ++++---- dispatch/dispatch.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/api.go b/api/api.go index 53442e7b8f..c8fc5cdc81 100644 --- a/api/api.go +++ b/api/api.go @@ -343,10 +343,10 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { } apiAlert := &dispatch.APIAlert{ - Alert: &a.Alert, - Status: status, - Receivers: receivers, - ID: fmt.Sprintf("%x", a.Fingerprint()), + Alert: &a.Alert, + Status: status, + Receivers: receivers, + Fingerprint: fmt.Sprintf("%x", a.Fingerprint()), } res = append(res, apiAlert) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index be1b629e56..1121fd4f06 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -80,9 +80,9 @@ type AlertBlock struct { // annotated with silencing and inhibition info. type APIAlert struct { *model.Alert - Status types.AlertStatus `json:"status"` - Receivers []string `json:"receivers"` - ID string `json:"id"` + Status types.AlertStatus `json:"status"` + Receivers []string `json:"receivers"` + Fingerprint string `json:"fingerprint"` } // AlertGroup is a list of alert blocks grouped by the same label set. @@ -137,9 +137,9 @@ func (d *Dispatcher) Groups(matchers []*labels.Matcher) AlertOverview { } status := d.marker.Status(a.Fingerprint()) aa := &APIAlert{ - Alert: a, - Status: status, - ID: fmt.Sprintf("%d", a.Fingerprint()), + Alert: a, + Status: status, + Fingerprint: fmt.Sprintf("%x", a.Fingerprint()), } if !matchesFilterLabels(aa, matchers) { From 14f6ce86f120b9071018bb9331a08eeb35cfb088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 17 Aug 2017 15:10:20 -0700 Subject: [PATCH 4/4] Use Fingerprint().String() in the API --- api/api.go | 2 +- dispatch/dispatch.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api.go b/api/api.go index c8fc5cdc81..0848a240e3 100644 --- a/api/api.go +++ b/api/api.go @@ -346,7 +346,7 @@ func (api *API) listAlerts(w http.ResponseWriter, r *http.Request) { Alert: &a.Alert, Status: status, Receivers: receivers, - Fingerprint: fmt.Sprintf("%x", a.Fingerprint()), + Fingerprint: a.Fingerprint().String(), } res = append(res, apiAlert) diff --git a/dispatch/dispatch.go b/dispatch/dispatch.go index 1121fd4f06..76a42a0499 100644 --- a/dispatch/dispatch.go +++ b/dispatch/dispatch.go @@ -139,7 +139,7 @@ func (d *Dispatcher) Groups(matchers []*labels.Matcher) AlertOverview { aa := &APIAlert{ Alert: a, Status: status, - Fingerprint: fmt.Sprintf("%x", a.Fingerprint()), + Fingerprint: a.Fingerprint().String(), } if !matchesFilterLabels(aa, matchers) {