feat: add health check to telemetry server

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar
2021-02-11 00:13:07 +01:00
parent 10597cf09f
commit 024f69b2c7
4 changed files with 61 additions and 0 deletions

View File

@@ -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}