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

Commit

Permalink
fix: Deployment Type in remediation.triggered incompatible with Keptn…
Browse files Browse the repository at this point in the history
… cloud events (#367)

Signed-off-by: Christian Kreuzberger <christian.kreuzberger@dynatrace.com>

Signed-off-by: Christian Kreuzberger <christian.kreuzberger@dynatrace.com>
  • Loading branch information
christian-kreuzberger-dtx authored Aug 30, 2022
1 parent cf7e32d commit 6d69b5d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
11 changes: 8 additions & 3 deletions eventhandling/alertEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 @@ -104,8 +105,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/getSliEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (eh GetSliEventHandler) HandleEvent() error {
return sendFinishedErrorEvent(fmt.Errorf("unable to get prometheus api URL: %w", err))
}

// 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"

0 comments on commit 6d69b5d

Please sign in to comment.