healthcheck: answer 503 when the last round of DNS checks reached no root server (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 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 builds the watcher first: its first round starts before the HTTP server listens, and the server tests' fx graph includes it. NewWithRootServers lets tests start a resolver's walks at real servers that are not root servers. Model: opus-5-5
This commit is contained in:
1 parent
b23cf43abf
commit
a364e9e824
14 files changed
+532
-45
No files matched your search
@@ -11,6 +11,13 @@ import (
|
||||
"sneak.berlin/go/dnswatcher/internal/config"
|
||||
"sneak.berlin/go/dnswatcher/internal/globals"
|
||||
"sneak.berlin/go/dnswatcher/internal/logger"
|
||||
"sneak.berlin/go/dnswatcher/internal/watcher"
|
||||
)
|
||||
|
||||
// Values of Response.Status.
|
||||
const (
|
||||
StatusOK = "ok"
|
||||
StatusError = "error"
|
||||
)
|
||||
|
||||
// Params contains dependencies for Healthcheck.
|
||||
@@ -20,6 +27,7 @@ type Params struct {
|
||||
Globals *globals.Globals
|
||||
Config *config.Config
|
||||
Logger *logger.Logger
|
||||
Watcher *watcher.Watcher
|
||||
}
|
||||
|
||||
// Healthcheck provides health status information.
|
||||
@@ -61,10 +69,17 @@ func New(
|
||||
return healthcheck, nil
|
||||
}
|
||||
|
||||
// Check returns the current health status.
|
||||
// Check returns the current health status. Status is StatusError when
|
||||
// the watcher's most recent round of DNS checks could not reach the DNS
|
||||
// (see watcher.Watcher.DNSUnreachable), and StatusOK otherwise.
|
||||
func (h *Healthcheck) Check() *Response {
|
||||
status := StatusOK
|
||||
if h.params.Watcher.DNSUnreachable() {
|
||||
status = StatusError
|
||||
}
|
||||
|
||||
return &Response{
|
||||
Status: "ok",
|
||||
Status: status,
|
||||
Now: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
UptimeSeconds: int64(h.uptime().Seconds()),
|
||||
UptimeHuman: h.uptime().String(),
|
||||
|
||||
Reference in new issue
Block a user