healthcheck: answer 503 when no root server gave a usable reply in the last round of DNS checks (closes #302)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
The health check answered ok while every DNS lookup failed, as on a network that intercepts DNS queries. A lookup whose root servers give no usable reply now fails with ErrNoRootServerAnswered. At the end of each round of DNS checks that shutdown did not cut short, the watcher records whether every lookup failed with it or with ErrIntercepted; the health check then gives status error, and /.well-known/healthcheck and /health answer 503. Until the first round finishes it stays ok. The health check now depends on the watcher, so fx starts the watcher before the HTTP server and stops the server first. NewWithRootServers lets tests start a resolver's walks at real servers that are not root servers. Model: opus-5-5
This commit was merged in pull request #304.
This commit is contained in:
@@ -2,16 +2,25 @@ package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/healthcheck"
|
||||
)
|
||||
|
||||
// HandleHealthCheck returns the health check handler.
|
||||
// HandleHealthCheck returns the health check handler. It answers 503
|
||||
// Service Unavailable when the health check's status is error, so that
|
||||
// a container health check fails, and 200 OK otherwise.
|
||||
func (h *Handlers) HandleHealthCheck() http.HandlerFunc {
|
||||
return func(
|
||||
writer http.ResponseWriter,
|
||||
request *http.Request,
|
||||
) {
|
||||
h.respondJSON(
|
||||
writer, request, h.hc.Check(), http.StatusOK,
|
||||
)
|
||||
resp := h.hc.Check()
|
||||
|
||||
code := http.StatusOK
|
||||
if resp.Status == healthcheck.StatusError {
|
||||
code = http.StatusServiceUnavailable
|
||||
}
|
||||
|
||||
h.respondJSON(writer, request, resp, code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user