Coalesce identical misses, refuse non-QUERY opcodes, refresh hot entries early, check the answered question
Concurrent cache misses for one name each went upstream. After a restart, a cache flush or a cluster-object change that is a burst of identical queries exactly when the cache is empty. Identical exchanges (same name, type, class, DO bit, pinned upstream set and forwarded client subnet) now share one: the first query runs it on its own goroutine and context, the rest wait and get private copies, and the leader alone writes the cache. If the leader's client leaves, waiters take over instead of failing with its cancellation. Shared answers are counted in fancydns_upstream_coalesced_total. validate() accepted OpcodeUpdate, so a dynamic update was forwarded upstream as an ordinary lookup, and every other opcode got FORMERR. A recursive resolver implements QUERY only: anything else is now NOTIMP (RFC 1035 4.1.1), checked before the question count since STATUS carries no question. Prefetch only fired when a stale entry was served, so the first client after a hot name expired got a TTL-1 stale answer. A fresh entry is now refreshed in the background when it has been served at least twice and under a tenth of its lifetime remains; the hit counter restarts with each stored entry, so a name nobody comes back for stops being refreshed. Counted in fancydns_cache_prefetch_total. miekg/dns matches only the message ID of an upstream reply, so a forged reply with the right ID for a different question was accepted and cached under the name that was asked. exchangeOne now requires the reply to carry the question that was sent (an empty section only for FORMERR, SERVFAIL, NOTIMP and REFUSED). A mismatch fails the attempt without counting against the upstream, so a spoofer cannot trip the circuit breaker. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1a536e7d0e
commit
dd1117fd91
8 files changed
+498
-9
No files matched your search
@@ -28,6 +28,8 @@ var (
|
||||
cacheHits prometheus.Counter
|
||||
cacheMisses prometheus.Counter
|
||||
cacheStaleHits prometheus.Counter
|
||||
coalesced prometheus.Counter
|
||||
prefetches prometheus.Counter
|
||||
upstreamErrors prometheus.Counter
|
||||
dnsErrors prometheus.Counter
|
||||
dropsTotal prometheus.Counter
|
||||
@@ -82,6 +84,14 @@ func initCollectors() {
|
||||
Namespace: Namespace, Name: "cache_stale_hits_total",
|
||||
Help: "Answers served from the serve-stale window.",
|
||||
})
|
||||
coalesced = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace, Name: "upstream_coalesced_total",
|
||||
Help: "Cache misses answered by sharing another query's in-flight upstream exchange.",
|
||||
})
|
||||
prefetches = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace, Name: "cache_prefetch_total",
|
||||
Help: "Background refreshes started for an entry that was stale or close to expiry.",
|
||||
})
|
||||
upstreamErrors = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace, Name: "upstream_errors_total",
|
||||
Help: "Upstream exchange failures.",
|
||||
@@ -143,7 +153,7 @@ func initCollectors() {
|
||||
})
|
||||
|
||||
Registry.MustRegister(
|
||||
queriesTotal, blockedTotal, cacheHits, cacheMisses, cacheStaleHits,
|
||||
queriesTotal, blockedTotal, cacheHits, cacheMisses, cacheStaleHits, coalesced, prefetches,
|
||||
upstreamErrors, dnsErrors, dropsTotal, refusedTotal, upstreamHealth,
|
||||
concurrentNow, listCount, listBytes, aclGroups, localRecords, up,
|
||||
queryDuration, upstreamDur, parseDuration,
|
||||
@@ -208,6 +218,12 @@ func RecordMiss() { initCollectors(); cacheMisses.Inc(); misses.Add(1) }
|
||||
// RecordStaleHit counts a serve-stale hit.
|
||||
func RecordStaleHit() { initCollectors(); cacheStaleHits.Inc(); staleHits.Add(1) }
|
||||
|
||||
// RecordCoalesced counts a query that shared an in-flight upstream exchange.
|
||||
func RecordCoalesced() { initCollectors(); coalesced.Inc() }
|
||||
|
||||
// RecordPrefetch counts a background refresh.
|
||||
func RecordPrefetch() { initCollectors(); prefetches.Inc() }
|
||||
|
||||
// RecordUpstreamError counts an upstream failure.
|
||||
func RecordUpstreamError() { initCollectors(); upstreamErrors.Inc() }
|
||||
|
||||
|
||||
Reference in new issue
Block a user