Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

fix: Deployment Type in remediation.triggered incompatible with Keptn cloud events #366

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions eventhandling/alertEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ type remediationTriggeredEventData struct {
// Problem contains details about the problem
Problem keptncommons.ProblemEventData `json:"problem"`
// Deployment contains the current deployment, that is inferred from the alert event
Deployment string `json:"deployment"`

Deployment keptnv2.DeploymentFinishedData `json:"deployment"`
}

// ProcessAndForwardAlertEvent reads the payload from the request and sends a valid Cloud event to the keptn event broker
Expand Down Expand Up @@ -109,8 +110,12 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log
"Problem URL": event.Alerts[0].GeneratorURL,
},
},
Problem: problemData,
Deployment: event.Alerts[0].Labels.Deployment,
Problem: problemData,
Deployment: keptnv2.DeploymentFinishedData{
DeploymentNames: []string{
event.Alerts[0].Labels.Deployment,
},
},
}

if event.Alerts[0].Fingerprint != "" {
Expand Down
2 changes: 2 additions & 0 deletions eventhandling/get_sli_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (eh GetSliEventHandler) Execute(k sdk.IKeptn, event sdk.KeptnEvent) (interf
return nil, &sdk.Error{Err: err, StatusType: keptnv2.StatusErrored, ResultType: keptnv2.ResultFailed, Message: "failed to get Prometheus API URL: " + err.Error()}
}

// determine deployment type based on what lighthouse-service is providing
deployment := eventData.Deployment // "canary", "primary" or "" (or "direct" or "user_managed")
// fallback: get deployment type from labels
if deploymentLabel, ok := eventData.Labels["deployment"]; deployment == "" && !ok {
log.Println("Warning: no deployment type specified in event, defaulting to \"primary\"")
deployment = "primary"
Expand Down
7 changes: 4 additions & 3 deletions prometheus_alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
"project": "sockshop",
"service": "carts",
"severity": "webhook",
"stage": "production"
"stage": "production",
"deployment": "primary"
},
"annotations": {
"descriptions": "Pod name ",
"summary": "response_time_p90"
},
"startsAt": "2021-11-26T10:57:14.057345112Z",
"startsAt": "2022-11-26T10:57:14.057345112Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://prometheus-server-6776d8bb7d-pqkln:9090/graph?g0.expr=histogram_quantile%280.9%2C+sum+by%28le%29+%28rate%28http_response_time_milliseconds_bucket%7Bhandler%3D%22ItemsController.addToCart%22%2Cjob%3D%22carts-sockshop-production-primary%22%7D%5B3m%5D%29%29%29+%3E+1000\\u0026g0.tab=1",
"fingerprint": "8dd2c31a47cf2e78"
"fingerprint": "add2c31a47cf2e78"
}
],
"groupLabels": {},
Expand Down
39 changes: 39 additions & 0 deletions test/e2e/podtatohead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func TestPodtatoheadEvaluation(t *testing.T) {
// Check if the following event are in the project:
// - remediation.triggered (making sure prometheus-service actually sends a message to Keptn)
// - get-action.finished (The message format is compatible with remediation-service)
// - evaluation.triggered (making sure Keptn emits an evaluation.triggered)
// - get-sli.finished (making sure prometheus-service responds with data)
requireWaitForFilteredEvent(t,
testEnv.API,
1*time.Minute,
Expand Down Expand Up @@ -307,5 +309,42 @@ func TestPodtatoheadEvaluation(t *testing.T) {
},
"remediation-service",
)

// wait roughly 60 seconds for evaluation.triggered
requireWaitForFilteredEvent(t,
testEnv.API,
2*time.Minute,
1*time.Second,
&api.EventFilter{
Project: testEnv.EventData.Project,
Stage: testEnv.EventData.Stage,
Service: testEnv.EventData.Service,
EventType: "sh.keptn.event.evaluation.triggered",
},
func(event *models.KeptnContextExtendedCE) bool {
return true
},
"shipyard-controller",
)

// wait for prometheus-service returning a get-sli.finished
requireWaitForFilteredEvent(t,
testEnv.API,
1*time.Minute,
1*time.Second,
&api.EventFilter{
Project: testEnv.EventData.Project,
Stage: testEnv.EventData.Stage,
Service: testEnv.EventData.Service,
EventType: "sh.keptn.event.get-sli.finished",
},
func(event *models.KeptnContextExtendedCE) bool {
responseEventData, err := parseKeptnEventData(event)
require.NoError(t, err)

return responseEventData.Result == "pass" && responseEventData.Status == "succeeded"
},
"prometheus-service",
)
})
}
2 changes: 2 additions & 0 deletions test/shipyard/podtatohead.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ spec:
tasks:
- name: "get-action"
- name: "action"
- name: "evaluation"
triggeredAfter: "1m"