Skip to content

Commit

Permalink
feat: Simple health check endpoint for webhooks (#823)
Browse files Browse the repository at this point in the history
* feat: Simple health check endpoint for webhooks

* doc

* doc update

* dock change

* re-run codegen

* fix
  • Loading branch information
whynowy authored Aug 9, 2020
1 parent 6471850 commit 757dbe7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/sensor.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/sensor.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions docs/webhook-health-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Webhook Health Check

![alpha](assets/alpha.svg)

> v1.0 and after
For `webhook` or `webhook` extended event sources such as `github`, `gitlab`,
`sns`, `slack`, `Storage GRID` and `stripe`, besides the endpint configured in
the spec, an endpoint `:${port}/health` will be created by default, this is
useful for LB or Ingress configuration for the event source, where usually a
health check endpoint is required.

For example, besides `:12000/example1` and `:13000/example2`, the EventSource
object below also creates 2 extra endpoints, `:12000/health` and
`:13000/health`. A HTTP GET request to the health endpoint returns a text `OK`
with HTTP response code `200`.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
name: webhook
spec:
webhook:
example:
port: "12000"
endpoint: /example1
method: POST
example-foo:
port: "13000"
endpoint: /example2
method: POST
```
13 changes: 11 additions & 2 deletions eventsources/common/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/gorilla/mux"
"go.uber.org/zap"

"github.com/argoproj/argo-events/common"
"github.com/argoproj/argo-events/common/logging"
"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
)
Expand Down Expand Up @@ -99,14 +100,22 @@ func startServer(router Router, controller *Controller) {
handler := controller.ActiveServerHandlers[route.Context.Port]

routeName := route.Context.Port + route.Context.Endpoint

r := handler.GetRoute(routeName)
if r == nil {
r = handler.NewRoute().Name(routeName)
r = r.Path(route.Context.Endpoint)
r.HandlerFunc(router.HandleRoute)
}

r.HandlerFunc(router.HandleRoute)
healthCheckRouteName := route.Context.Port + "/health"
healthCheckRoute := handler.GetRoute(healthCheckRouteName)
if healthCheckRoute == nil {
healthCheckRoute = handler.NewRoute().Name(healthCheckRouteName)
healthCheckRoute = healthCheckRoute.Path("/health")
healthCheckRoute.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
common.SendSuccessResponse(writer, "OK")
})
}

Lock.Unlock()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/sensor/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/sensor/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 757dbe7

Please sign in to comment.