mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-25 09:43:05 +00:00
feat: add separate health probe listener
This adds an optional health probe listener, mostly for use in rutime environments where you want separate public and private listeners. The existing /oauth2/ping endpoint on the main listener is kept for backwards compatibility.
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
_ "github.com/KimMachineGun/automemlimit"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -80,12 +81,32 @@ func run() error {
|
||||
|
||||
r := router.New(src, cfg)
|
||||
|
||||
go func() {
|
||||
err := metrics.Handle(cfg.MetricsBindAddress, cfg.OpenID.Provider)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: metrics server error: %s", err)
|
||||
}
|
||||
}()
|
||||
if cfg.MetricsBindAddress != "" {
|
||||
go func() {
|
||||
log.Infof("metrics: listening on %s", cfg.MetricsBindAddress)
|
||||
err := metrics.Handle(cfg.MetricsBindAddress, cfg.OpenID.Provider)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: metrics server error: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if cfg.ProbeBindAddress != "" {
|
||||
go func() {
|
||||
mux := http.NewServeMux()
|
||||
healthz := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("ok"))
|
||||
})
|
||||
mux.HandleFunc("/", healthz)
|
||||
mux.HandleFunc("/healthz", healthz)
|
||||
log.Infof("probe: listening on %s", cfg.ProbeBindAddress)
|
||||
err := http.ListenAndServe(cfg.ProbeBindAddress, mux)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: probe server error: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return server.Start(cfg, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user