diff --git a/gateway/handlers/healthhandler.go b/gateway/handlers/healthhandler.go new file mode 100644 index 00000000..4b4f8bb2 --- /dev/null +++ b/gateway/handlers/healthhandler.go @@ -0,0 +1,20 @@ +// Copyright (c) OpenFaaS Author(s) 2019. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +package handlers + +import "net/http" + +//HealthzHandler healthz hanlder for mertics server +func HealthzHandler(w http.ResponseWriter, r *http.Request) { + + switch r.Method { + case http.MethodGet: + w.WriteHeader(http.StatusOK) + w.Write([]byte("OK")) + break + + default: + w.WriteHeader(http.StatusMethodNotAllowed) + } +} diff --git a/gateway/server.go b/gateway/server.go index d8f70950..dddda789 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -232,11 +232,11 @@ func runMetricsServer() { metricsHandler := metrics.PrometheusHandler() router := mux.NewRouter() router.Handle("/metrics", metricsHandler) - router.HandleFunc("/healthz", healthzHandler) + router.HandleFunc("/healthz", handlers.HealthzHandler) port := 8082 - readTimeout := time.Duration(5) * time.Second - writeTimeout := time.Duration(5) * time.Second + readTimeout := 5 * time.Second + writeTimeout := 5 * time.Second s := &http.Server{ Addr: fmt.Sprintf(":%d", port), @@ -248,16 +248,3 @@ func runMetricsServer() { log.Fatal(s.ListenAndServe()) } - -func healthzHandler(w http.ResponseWriter, r *http.Request) { - - switch r.Method { - case http.MethodGet: - w.WriteHeader(http.StatusOK) - w.Write([]byte("OK")) - break - - default: - w.WriteHeader(http.StatusMethodNotAllowed) - } -}