feat: add health check to telemetry server
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
@@ -14,6 +14,9 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
gosundheit "github.com/AppsFlyer/go-sundheit"
|
||||
"github.com/AppsFlyer/go-sundheit/checks"
|
||||
gosundheithttp "github.com/AppsFlyer/go-sundheit/http"
|
||||
"github.com/ghodss/yaml"
|
||||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/oklog/run"
|
||||
@@ -325,6 +328,28 @@ func runServe(options serveOptions) error {
|
||||
telemetryServ := http.NewServeMux()
|
||||
telemetryServ.Handle("/metrics", promhttp.HandlerFor(prometheusRegistry, promhttp.HandlerOpts{}))
|
||||
|
||||
// Configure health checker
|
||||
healthChecker := gosundheit.New()
|
||||
{
|
||||
handler := gosundheithttp.HandleHealthJSON(healthChecker)
|
||||
telemetryServ.Handle("/healthz", handler)
|
||||
|
||||
// Kubernetes style health checks
|
||||
telemetryServ.HandleFunc("/healthz/live", func(w http.ResponseWriter, _ *http.Request) {
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
})
|
||||
telemetryServ.Handle("/healthz/ready", handler)
|
||||
}
|
||||
|
||||
healthChecker.RegisterCheck(&gosundheit.Config{
|
||||
Check: &checks.CustomCheck{
|
||||
CheckName: "storage",
|
||||
CheckFunc: storage.NewCustomHealthCheckFunc(serverConfig.Storage, serverConfig.Now),
|
||||
},
|
||||
ExecutionPeriod: 15 * time.Second,
|
||||
InitiallyPassing: true,
|
||||
})
|
||||
|
||||
var gr run.Group
|
||||
if c.Telemetry.HTTP != "" {
|
||||
telemetrySrv := &http.Server{Addr: c.Telemetry.HTTP, Handler: telemetryServ}
|
||||
|
Reference in New Issue
Block a user