Adds a simple healthcheck every 2s (#1814)
* Adds a simple healthcheck every 5s * Fixes bugs for healthcheck
This commit is contained in:
@@ -61,6 +61,7 @@ func createRouter(h *handler) *mux.Router {
|
||||
s.HandleFunc("/api/validateCredentials", h.validateCredentials)
|
||||
s.Handle("/logout", authorizationRequired(h.clearSession))
|
||||
s.Handle("/version", authorizationRequired(h.version))
|
||||
s.HandleFunc("/healthcheck", h.healthcheck)
|
||||
|
||||
if log.IsLevelEnabled(log.DebugLevel) {
|
||||
s.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
|
||||
@@ -131,3 +132,14 @@ func (h *handler) version(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
fmt.Fprintf(w, "<pre>%v</pre>", h.config.Version)
|
||||
}
|
||||
|
||||
func (h *handler) healthcheck(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace("Executing healthcheck request")
|
||||
|
||||
if ping, err := h.client.Ping(r.Context()); err != nil {
|
||||
log.Error(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
fmt.Fprintf(w, "OK API Version %v", ping.APIVersion)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user