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:
@@ -43,10 +43,12 @@ type NameserverResponse struct {
|
||||
}
|
||||
|
||||
// Resolver performs iterative DNS resolution from root servers.
|
||||
// rootServers are the addresses every walk from the root starts at.
|
||||
type Resolver struct {
|
||||
log *slog.Logger
|
||||
client DNSClient
|
||||
tcp DNSClient
|
||||
log *slog.Logger
|
||||
client DNSClient
|
||||
tcp DNSClient
|
||||
rootServers []string
|
||||
}
|
||||
|
||||
// New creates a new Resolver instance for use with uber/fx.
|
||||
@@ -55,9 +57,10 @@ func New(
|
||||
params Params,
|
||||
) (*Resolver, error) {
|
||||
return &Resolver{
|
||||
log: params.Logger.Get(),
|
||||
client: &udpClient{timeout: queryTimeoutDuration},
|
||||
tcp: &tcpClient{timeout: queryTimeoutDuration},
|
||||
log: params.Logger.Get(),
|
||||
client: &udpClient{timeout: queryTimeoutDuration},
|
||||
tcp: &tcpClient{timeout: queryTimeoutDuration},
|
||||
rootServers: rootServerList(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -65,10 +68,22 @@ func New(
|
||||
// useful for testing without the fx lifecycle.
|
||||
func NewFromLogger(log *slog.Logger) *Resolver {
|
||||
return &Resolver{
|
||||
log: log,
|
||||
client: &udpClient{timeout: queryTimeoutDuration},
|
||||
tcp: &tcpClient{timeout: queryTimeoutDuration},
|
||||
log: log,
|
||||
client: &udpClient{timeout: queryTimeoutDuration},
|
||||
tcp: &tcpClient{timeout: queryTimeoutDuration},
|
||||
rootServers: rootServerList(),
|
||||
}
|
||||
}
|
||||
|
||||
// NewWithRootServers creates a Resolver as NewFromLogger does, except
|
||||
// that every walk from the root starts at servers instead of at the root
|
||||
// servers. Tests use it to show what dnswatcher does when no root server
|
||||
// answers, or when something on the network answers in their place.
|
||||
func NewWithRootServers(log *slog.Logger, servers []string) *Resolver {
|
||||
r := NewFromLogger(log)
|
||||
r.rootServers = servers
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Method implementations are in iterative.go.
|
||||
|
||||
Reference in New Issue
Block a user