Skip to content

feat(mesh-dns): close the observability gaps (#586) - #587

Merged
bpalermo merged 1 commit into
mainfrom
feat/586-mesh-dns-observability
Jul 25, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/586-mesh-dns-observability

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #586.

The mesh-DNS resolver is a standalone DaemonSet on the critical path for every managed pod's DNS (the CNI DNATs all UDP+TCP :53 to HOST_IP:18054), yet it shipped one counter and no logs at all. All 5 scope items in one PR.

1. Snapshot freshness envelope + agent heartbeat

The on-disk snapshot becomes a versioned envelope:

{"writtenAt": 1753440000, "generation": 42, "records": {"<ns>/<svc>": "<ip>"}}
  • ReadSnapshot still accepts the legacy bare map ({"<ns>/<svc>":"<ip>"}) and back-fills writtenAt from the file mtime, so an in-place upgrade never starts the resolver cold. The envelope is tried first and only accepted when it actually carries a records object, so a legacy file whose service keys collide with envelope field names still decodes.
  • WriteSnapshot(path, records, generation) stamps writtenAt=now and carries the caller's generation.
  • Agent heartbeat: the capture reconciler is purely event-driven (no short SyncPeriod → 10h resync), so a healthy quiet cluster would look stale. A new capture.MeshDNSHeartbeat controller-runtime Runnable re-stamps the snapshot every MeshDNSHeartbeatInterval (60s). Snapshot age therefore measures the writer's liveness, not cluster churn.
    • generation advances only on a content change, so a heartbeat rewrite is distinguishable from a real update.
    • The heartbeat is a no-op before the first projection — writing an empty table would flip the daemon ready and NXDOMAIN the entire mesh.
    • Registered only when --mesh-dns is on, and the rewrite is itself inert when the snapshot path is empty. NeedLeaderElection() == false (every node must re-stamp its own snapshot).

2. New instruments

Observable gauges (one registered callback; state copied out from under the Server RWMutex, never held across the export):

Instrument Kind
aether.mesh_dns.snapshot_age_seconds Float64ObservableGauge
aether.mesh_dns.snapshot_written_at_seconds Float64ObservableGauge
aether.mesh_dns.records Int64ObservableGauge
aether.mesh_dns.snapshot_generation Int64ObservableGauge (extra, see deviations)
aether.mesh_dns.watch_active Int64ObservableGauge 0/1
aether.mesh_dns.upstreams_configured Int64ObservableGauge
aether.mesh_dns.ready Int64ObservableGauge 0/1
aether.mesh_dns.snapshot_reloads_total{result} Int64Counter — success / missing / parse_error / read_error
aether.mesh_dns.query.duration{result} Float64Histogram, seconds

query.duration uses explicit buckets from 100µs (a mesh hit is an in-memory map read) to 5s; the OTel defaults would collapse the whole mesh path into bucket 0. Reload results are classified via a new ErrSnapshotParse sentinel + fs.ErrNotExist. Everything stays nil-safe.

3. Logs over OTLP + runtime metrics

SetupTelemetry now returns a Telemetry carrying an otelslog handler over an OTLP-gRPC sdklog.LoggerProvider, fanned into the daemon's slog alongside stderr (log.NewLoggerWithHandler). Before this, mesh-DNS logs existed only as pod stdout and died on every roll — which mattered because several failure modes' only signal is a log line.

common/telemetry/setup is deliberately not imported (it reaches controller-runtime and would undo the slim binary, #583) — only otlploggrpc + sdklog are mirrored locally. runtime.Start() adds Go runtime metrics (goroutine leaks on the TCP path were invisible). Both are non-fatal degradations surfaced as Telemetry.Warnings and logged at WARN; instrument-creation failures now log a WARN instead of newMetrics silently returning nil.

4. Empty-upstreams fix

With no upstream, every non-mesh query (cluster.local and external) becomes a forward_error — a node-wide DNS outage — previously announced at INFO as upstreams=[]. Now ERROR with an explicit message, plus upstreams_configured=0. Fail-open behaviour is unchanged (mesh names still resolve).

5. Chart

NODE_NAME from fieldRef: spec.nodeName, used for k8s.node.name in OTEL_RESOURCE_ATTRIBUTES (was $(HOST_IP), which never joined with the agent's node label). HOST_IP is kept for the bind address. No new flags. Chart bumped 0.86.0 → 0.87.0.

Slim-graph proof

$ bazel query 'somepath(//agent/cmd/mesh-dns:mesh-dns, @io_k8s_sigs_controller_runtime//pkg/client:client)'
INFO: Empty results
$ bazel query 'somepath(//agent/cmd/mesh-dns:mesh-dns, @com_github_envoyproxy_go_control_plane//...)'
INFO: Empty results

Also empty for @io_k8s_sigs_controller_runtime//... (any target) and @io_k8s_api//....

Validation

  • bazel test //... — 78/78 pass; bazel build //agent/... //charts/... green.
  • bazel build --config=ci //agent/... //common/... green (gocognit ≤ 15).
  • bazel run //:format + make format-check clean.
  • New tests: legacy bare-map read (incl. mtime fallback and envelope-shaped keys), envelope round-trip, corrupt/parse-error classification, all four reload result labels, gauge values (records / writtenAt / generation / ready / watch_active / upstreams, plus the empty-snapshot case), heartbeat ticking + clean cancel + defaults, cache-side generation semantics and the before-first-projection guard, and the empty-upstreams ERROR path.
  • No resolver DNS semantics changed: EDNS0 echo, NODATA-for-non-A, never-forward-the-zone, SO_REUSEPORT, marker-after-bind and the surge/readiness guarantee are all untouched.

Deviations

  • Added one instrument beyond the issue list: aether.mesh_dns.snapshot_generation, which is what makes "the agent re-stamped freshness" distinguishable from "the record table actually changed" at query time.
  • ReloadFromSnapshot's success log dropped from INFO to DEBUG — with a 60s heartbeat it would otherwise emit a per-node INFO line every minute, now shipped over OTLP.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR

The mesh-DNS resolver is a standalone DaemonSet on the critical path for
EVERY managed pod's DNS (the CNI DNATs all UDP+TCP :53 to HOST_IP:18054),
yet it shipped one counter and no logs at all.

Snapshot freshness envelope + agent heartbeat. The on-disk snapshot is now
{writtenAt, generation, records}; ReadSnapshot still accepts the legacy
bare map (back-filling writtenAt from the file mtime) so an in-place
upgrade never starts the resolver cold. Because the writer is event-driven
(no short SyncPeriod), a new MeshDNSHeartbeat runnable re-stamps the
snapshot every 60s even when nothing changed, so snapshot age measures the
WRITER's liveness rather than cluster churn. The generation advances only
on a content change, and the heartbeat never writes before the first
projection (an empty table would NXDOMAIN the whole mesh).

New instruments: snapshot_age_seconds, snapshot_written_at_seconds,
records, snapshot_generation, watch_active, upstreams_configured and ready
(observable gauges, exported from a registered callback that copies state
out from under the Server's RWMutex), snapshot_reloads_total{result} and
query.duration{result} with DNS-appropriate explicit buckets.

Logs now ship over OTLP: a LoggerProvider bridged into the daemon's slog
via otelslog, plus Go runtime metrics. common/telemetry/setup is
deliberately NOT imported — it reaches controller-runtime and would undo
the slim binary (#583); only otlploggrpc + sdklog are mirrored locally.

Empty upstreams is a node-wide DNS outage (every non-mesh query becomes a
forward_error) and was announced at INFO as "upstreams=[]". It is now an
ERROR plus upstreams_configured=0; the fail-open behaviour is unchanged.

Chart: NODE_NAME fieldRef so k8s.node.name is the node name, not its IP.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01EioJVuoepwStjHoRLB52WR
@bpalermo
bpalermo merged commit 997cc99 into main Jul 25, 2026
15 checks passed
@bpalermo
bpalermo deleted the feat/586-mesh-dns-observability branch July 25, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mesh-dns: close the observability gaps (snapshot staleness, log shipping, forward-path blindness)

1 participant