Merge pull request #409 from weaveworks/event-webhook

Implement event dispatching webhook
This commit is contained in:
Stefan Prodan
2020-01-16 11:02:32 +02:00
committed by GitHub
7 changed files with 52 additions and 1 deletions

View File

@@ -245,6 +245,7 @@ spec:
- rollout
- confirm-promotion
- post-rollout
- event
url:
description: URL address of this webhook
type: string

View File

@@ -246,6 +246,7 @@ spec:
- rollout
- confirm-promotion
- post-rollout
- event
url:
description: URL address of this webhook
type: string

View File

@@ -547,6 +547,8 @@ The canary promotion is paused until the hooks return HTTP 200.
While the promotion is paused, Flagger will continue to run the metrics checks and rollout hooks.
* Post-rollout hooks are executed after the canary has been promoted or rolled back.
If a post rollout hook fails the error is logged.
* Event hooks are executed every time Flagger emits a Kubernetes event. When configured,
every action that Flagger takes during a canary deployment will be sent as JSON via an HTTP POST request.
Spec:
@@ -578,6 +580,9 @@ Spec:
timeout: 5s
metadata:
some: "message"
- name: "send to Slack"
type: event
url: http://event-recevier.notifications/slack
```
> **Note** that the sum of all rollout webhooks timeouts should be lower than the analysis interval.
@@ -603,6 +608,24 @@ Response status codes:
On a non-2xx response Flagger will include the response body (if any) in the failed checks log and Kubernetes events.
Event payload (HTTP POST):
```json
{
"name": "string (canary name)",
"namespace": "string (canary namespace)",
"phase": "string (canary phase)",
"metadata": {
"eventMessage": "string (canary event message)",
"eventType": "string (canary event type)",
"timestamp": "string (unix timestamp ms)"
}
}
```
The event receiver can create alerts based on the received phase
(possible values: ` Initialized`, `Waiting`, `Progressing`, `Promoting`, `Finalising`, `Succeeded` or `Failed`).
### Load Testing
For workloads that are not receiving constant traffic Flagger can be configured with a webhook,

View File

@@ -92,3 +92,13 @@ Example:
}
}
```
The event webhook can be overwritten at canary level with:
```yaml
canaryAnalysis:
webhooks:
- name: "send to Slack"
type: event
url: http://event-recevier.notifications/slack
```

View File

@@ -245,6 +245,7 @@ spec:
- rollout
- confirm-promotion
- post-rollout
- event
url:
description: URL address of this webhook
type: string

View File

@@ -149,6 +149,8 @@ const (
ConfirmRolloutHook HookType = "confirm-rollout"
// ConfirmPromotionHook halt canary promotion until webhook returns HTTP 200
ConfirmPromotionHook HookType = "confirm-promotion"
// EventHook dispatches Flagger events to the specified endpoint
EventHook HookType = "event"
)
// CanaryWebhook holds the reference to external checks used for canary analysis

View File

@@ -248,7 +248,20 @@ func checkCustomResourceType(obj interface{}, logger *zap.SugaredLogger) (flagge
}
func (c *Controller) sendEventToWebhook(r *flaggerv1.Canary, eventtype, template string, args []interface{}) {
if c.eventWebhook != "" {
webhookOverride := false
if len(r.Spec.CanaryAnalysis.Webhooks) > 0 {
for _, canaryWebhook := range r.Spec.CanaryAnalysis.Webhooks {
if canaryWebhook.Type == flaggerv1.EventHook {
webhookOverride = true
err := CallEventWebhook(r, canaryWebhook.URL, fmt.Sprintf(template, args...), eventtype)
if err != nil {
c.logger.With("canary", fmt.Sprintf("%s.%s", r.Name, r.Namespace)).Errorf("error sending event to webhook: %s", err)
}
}
}
}
if c.eventWebhook != "" && !webhookOverride {
err := CallEventWebhook(r, c.eventWebhook, fmt.Sprintf(template, args...), eventtype)
if err != nil {
c.logger.With("canary", fmt.Sprintf("%s.%s", r.Name, r.Namespace)).Errorf("error sending event to webhook: %s", err)