health check
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s

This commit is contained in:
matst80
2024-11-10 23:20:52 +01:00
parent c5bc17c44d
commit 743849a131
3 changed files with 41 additions and 1 deletions

25
main.go
View File

@@ -125,7 +125,7 @@ func main() {
// if local
//syncedPool.AddRemote("localhost")
_, err = NewGrainHandler(app.pool, ":1337")
hg, err := NewGrainHandler(app.pool, ":1337")
if err != nil {
log.Fatalf("Error creating handler: %v\n", err)
}
@@ -155,6 +155,29 @@ func main() {
mux.HandleFunc("/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/pprof/trace", pprof.Trace)
mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
if !hg.IsHealthy() {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("handler not healthy"))
return
}
if !syncedPool.IsHealthy() {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("pool not healthy"))
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
mux.HandleFunc("/livez", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
})
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)