...
1 package http
2
3 import (
4 "fmt"
5 "net/http"
6
7 "edge-infra.dev/pkg/lib/fog"
8
9 dsHTTP "edge-infra.dev/pkg/edge/datasync/http"
10 "edge-infra.dev/pkg/edge/datasync/internal/config"
11 )
12
13 var logger = fog.New()
14
15 func NewLivenessServer(shouldRun chan bool, cfg *config.Config) *dsHTTP.Server {
16 serverMux := http.NewServeMux()
17 serverMux.HandleFunc("/healthz", healthz)
18
19 return dsHTTP.NewServer(cfg.LivenessPort, serverMux, shouldRun)
20 }
21
22 func healthz(w http.ResponseWriter, _ *http.Request) {
23 isAlive := isServerAlive()
24 if isAlive {
25 fmt.Fprintf(w, "up")
26 return
27 }
28 w.WriteHeader(http.StatusInternalServerError)
29 fmt.Fprintf(w, "down")
30 }
31
32
33 func isServerAlive() bool {
34
35
36 err := config.ValidateConfiguration()
37 if err != nil {
38 logger.Error(err, "Liveness check failed")
39 }
40 return err == nil
41 }
42
View as plain text