mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
feat(cmd): add healthy and ready check url. #1000296298
Signed-off-by: Victor1319 <zengxuewei@oppo.com>
(cherry picked from commit 2802e5e486)
This commit is contained in:
parent
6283610ad4
commit
99e41928dd
34
cmd/cmd.go
34
cmd/cmd.go
@ -15,6 +15,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
syslog "log"
|
syslog "log"
|
||||||
@ -404,6 +405,10 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.HandleFunc("/healthyz", liveCheck)
|
||||||
|
http.HandleFunc("/livez", liveCheck)
|
||||||
|
http.HandleFunc("/readyz", readyCheck)
|
||||||
|
|
||||||
daemonize.SignalOutcome(nil)
|
daemonize.SignalOutcome(nil)
|
||||||
|
|
||||||
// Block main goroutine until server shutdown.
|
// Block main goroutine until server shutdown.
|
||||||
@ -438,3 +443,32 @@ func startDaemon() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeJSONResponse(w http.ResponseWriter, status string, message string) {
|
||||||
|
resp := map[string]interface{}{
|
||||||
|
"status": status,
|
||||||
|
"message": message,
|
||||||
|
"time": time.Now().Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||||
|
log.LogErrorf("failed to encode response, err %s", err.Error())
|
||||||
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func liveCheck(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.LogInfof("livez check request received")
|
||||||
|
writeJSONResponse(w, "livez", "service is running")
|
||||||
|
log.LogInfo("livez check response sent successfully")
|
||||||
|
}
|
||||||
|
|
||||||
|
func readyCheck(w http.ResponseWriter, r *http.Request) {
|
||||||
|
log.LogInfof("ready check request received")
|
||||||
|
writeJSONResponse(w, "ready", "service is ready")
|
||||||
|
log.LogInfo("ready check response sent successfully")
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user