From 4123270235540f3c8ffc5012d44a1be70c210e60 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" Date: Sun, 20 May 2018 19:06:41 +0100 Subject: [PATCH] Add health and info endpoints Fixes issue 689 by enabling /healthz and /system/info, see swagger for more details. Signed-off-by: Alex Ellis (VMware) --- api-docs/swagger.yml | 25 ++++++++++++++++++++++++- gateway/server.go | 6 +++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api-docs/swagger.yml b/api-docs/swagger.yml index 4f361c82..0bbdd8f2 100644 --- a/api-docs/swagger.yml +++ b/api-docs/swagger.yml @@ -1,7 +1,7 @@ swagger: '2.0' info: description: OpenFaaS API documentation - version: 0.8.0 + version: 0.8.1 title: OpenFaaS API Gateway license: name: MIT @@ -213,6 +213,29 @@ paths: description: Function not found '500': description: Error querying function + '/system/info': + get: + summary: Get info such as provider version number and provider orchestrator + produces: + - application/json + responses: + '200': + description: Info result + examples: + application/json: |- + {"provider":"faas-swarm","version":{"sha":"7108418d9dd6b329ddff40e7393b3166f8160a88","release":"0.2.6"},"orchestration":"swarm"} + '404': + description: Provider does not support info endpoint + '500': + description: Error finding info + '/healthz': + get: + summary: Healthcheck + responses: + '200': + description: Healthy + '500': + description: Not healthy definitions: DeleteFunctionRequest: type: object diff --git a/gateway/server.go b/gateway/server.go index 9c0d166b..a86e929a 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -28,7 +28,7 @@ func main() { log.Printf("HTTP Write Timeout: %s", config.WriteTimeout) if !config.UseExternalProvider() { - log.Fatalln("As of this version of OpenFaaS, you must use external provider even for Docker Swarm.") + log.Fatalln("You must provide an external provider via 'functions_provider_url' env-var.") } log.Printf("Binding to external function provider: %s", config.FunctionsProviderURL) @@ -92,6 +92,8 @@ func main() { r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", faasHandlers.Proxy) r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.Proxy) + r.HandleFunc("/system/info", handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver)).Methods(http.MethodGet) + r.HandleFunc("/system/alert", faasHandlers.Alert) r.HandleFunc("/system/function/{name:[-a-zA-Z_0-9]+}", queryFunction).Methods(http.MethodGet) @@ -117,6 +119,8 @@ func main() { metricsHandler := metrics.PrometheusHandler() r.Handle("/metrics", metricsHandler) + r.HandleFunc("/healthz", handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver)).Methods(http.MethodGet) + r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods(http.MethodGet) tcpPort := 8080