Fix healtz for multiple remotes, as long as one remote is unhealthy all are flagged as unhealthy

This commit is contained in:
Pablu23
2025-05-19 09:36:32 +02:00
parent 55a2d2b708
commit 5f3b477adb

View File

@@ -66,24 +66,28 @@ func (router *Router) Healthz(w http.ResponseWriter, r *http.Request) {
} }
healthy := true healthy := true
for _, remote := range host.Remotes {
var url string var url string
if host.Secure { if host.Secure {
url = fmt.Sprintf("https://%s:%d/healthz", host.Remotes, host.Port) url = fmt.Sprintf("https://%s:%d/healthz", remote, host.Port)
} else { } else {
url = fmt.Sprintf("http://%s:%d/healthz", host.Remotes, host.Port) url = fmt.Sprintf("http://%s:%d/healthz", remote, host.Port)
} }
res, err := router.client.Get(url) res, err := router.client.Get(url)
if err != nil { if err != nil {
log.Warn().Err(err).Int("port", host.Port).Msg("Unhealthy") log.Warn().Err(err).Int("port", host.Port).Msg("Unhealthy")
healthy = false healthy = false
} else if res.StatusCode != 200 {
healthy = false
}
} }
for _, domain := range host.Domains { for _, domain := range host.Domains {
result = append(result, struct { result = append(result, struct {
Domain string Domain string
Healthy bool Healthy bool
}{domain, healthy && res.StatusCode == 200}) }{domain, healthy})
} }
} }