osbase/net/dns/forward: add DNS forward handler
This adds a DNS server handler for forwarding queries to upstream DNS
resolvers, with a built-in cache. The implementation is partially based
on CoreDNS. The proxy, cache and up packages are only lightly modified.
The forward package itself however is mostly new code. Unlike CoreDNS,
it supports changing upstreams at runtime, and has integrated caching
and answer order randomization.
Some improvements over CoreDNS:
- Concurrent identical queries only result in one upstream query.
- In case of errors, Extended DNS Errors are added to replies.
- Very large replies are not stored in the cache to avoid using too much
memory.
Change-Id: I42294ae4997d621a6e55c98e46a04874eab75c99
Reviewed-on: https://review.monogon.dev/c/monogon/+/3258
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/osbase/net/dns/forward/proxy/metrics.go b/osbase/net/dns/forward/proxy/metrics.go
new file mode 100644
index 0000000..c08f1d8
--- /dev/null
+++ b/osbase/net/dns/forward/proxy/metrics.go
@@ -0,0 +1,19 @@
+package proxy
+
+// Taken and modified from CoreDNS, under Apache 2.0.
+
+import (
+ "github.com/prometheus/client_golang/prometheus"
+
+ "source.monogon.dev/osbase/net/dns"
+)
+
+// Variables declared for monitoring.
+var (
+ healthcheckFailureCount = dns.MetricsFactory.NewCounterVec(prometheus.CounterOpts{
+ Namespace: "dnsserver",
+ Subsystem: "forward",
+ Name: "healthcheck_failures_total",
+ Help: "Counter of the number of failed healthchecks.",
+ }, []string{"to"})
+)