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) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (VMware)
2018-05-20 19:06:41 +01:00
committed by Alex Ellis
parent fa3ae74f37
commit 4123270235
2 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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