Skip to content

Commit

Permalink
Add /_/health endpoint to watchdog
Browse files Browse the repository at this point in the history
Introduce new endpoint `/_/health` to watchdog for health status of
functions which checks for `/tmp/.lock` file

Issues: openfaas/faas#547

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
  • Loading branch information
viveksyngh committed Mar 16, 2018
1 parent 6cc2eed commit cc63acc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func main() {
}

http.HandleFunc("/", requestHandler)
http.HandleFunc("/_/health", makeHealthHandler())
log.Fatal(s.ListenAndServe())
}

Expand Down Expand Up @@ -223,3 +224,29 @@ func makeHTTPRequestHandler(watchdogConfig config.WatchdogConfig) func(http.Resp

}
}

func lockFilePresent() bool {
path := filepath.Join(os.TempDir(), ".lock")
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}

func makeHealthHandler() func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
if lockFilePresent() == false {
w.WriteHeader(http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
break
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
}
}

0 comments on commit cc63acc

Please sign in to comment.