From 55caac456f98314d1af1bda93ad552daee8419c5 Mon Sep 17 00:00:00 2001 From: TannerGabriel Date: Tue, 9 Aug 2022 16:04:22 +0200 Subject: [PATCH] fix: Alertmanager cloudevent payload (#353) * fix: Alertmanager cloudevent payload to be compatible with remediation-service Signed-off-by: TannerGabriel * Move problem event data into correct type Signed-off-by: TannerGabriel * Remove duplicated check Signed-off-by: TannerGabriel * Make remediation triggered data type private Signed-off-by: TannerGabriel * Remove pointer from variable Signed-off-by: TannerGabriel --- eventhandling/alertEvent.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/eventhandling/alertEvent.go b/eventhandling/alertEvent.go index f82bbbf..573c88e 100644 --- a/eventhandling/alertEvent.go +++ b/eventhandling/alertEvent.go @@ -4,12 +4,12 @@ import ( "crypto/sha256" "encoding/json" "fmt" + keptncommons "github.com/keptn/go-utils/pkg/lib" "net/http" "net/url" "strings" "time" - keptncommons "github.com/keptn/go-utils/pkg/lib" "github.com/keptn/go-utils/pkg/lib/keptn" keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0" @@ -51,6 +51,13 @@ type annotations struct { Description string `json:"descriptions,omitempty"` } +type remediationTriggeredEventData struct { + keptnv2.EventData + + // Problem contains details about the problem + Problem keptncommons.ProblemEventData `json:"problem"` +} + // ProcessAndForwardAlertEvent reads the payload from the request and sends a valid Cloud event to the keptn event broker func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, logger *keptn.Logger, shkeptncontext string) { var event alertManagerEvent @@ -70,7 +77,7 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log return } - newEventData := keptncommons.ProblemEventData{ + problemData := keptncommons.ProblemEventData{ State: problemState, ProblemID: "", ProblemTitle: event.Alerts[0].Annotations.Summary, @@ -82,6 +89,15 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log Service: event.Alerts[0].Labels.Service, } + newEventData := remediationTriggeredEventData{ + EventData: keptnv2.EventData{ + Project: event.Alerts[0].Labels.Project, + Stage: event.Alerts[0].Labels.Stage, + Service: event.Alerts[0].Labels.Service, + }, + Problem: problemData, + } + if event.Alerts[0].Fingerprint != "" { // Note: fingerprint is always the same, we will append the startdate to create a unique keptn context shkeptncontext = createOrApplyKeptnContext(event.Alerts[0].Fingerprint + event.Alerts[0].StartsAt) @@ -102,7 +118,7 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log } // createAndSendCE create a new problem.triggered event and send it to Keptn -func createAndSendCE(problemData keptncommons.ProblemEventData, shkeptncontext string) error { +func createAndSendCE(problemData remediationTriggeredEventData, shkeptncontext string) error { source, _ := url.Parse("prometheus") eventType := keptnv2.GetTriggeredEventType(problemData.Stage + "." + remediationTaskName)