Skip to content

Add daemon mode, Prometheus exporter, and official Dockerfile - #82

Merged
lance0 merged 1 commit into
masterfrom
daemon-prometheus
Jun 10, 2026
Merged

lance0 merged 1 commit into
masterfrom
daemon-prometheus

Conversation

@lance0

@lance0 lance0 commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the Docker & Daemon Mode roadmap section (all items except Docker Hub publishing, which needs registry credentials).

Daemon mode (--daemon)

  • Headless probing with no per-hop stdout — for container/monitoring deployments
  • Composes with --prometheus and/or --stream-json; warns when started with neither (no output sink)
  • Conflicts with batch output flags and replay/diff

Prometheus exporter (--prometheus <ADDR>)

  • :9090 shorthand binds all interfaces; full host:port also accepted; invalid addresses rejected at arg validation
  • GET /metrics — OpenMetrics exposition: per-hop sent/response/timeout counters, RTT avg/min/max/stddev gauges, loss ratio, ECMP responder count, ttl_hop_info identity series; per-target reachability, path hops, total probes. Labels: target (resolved IP), host (name as given), ttl
  • GET /healthz — 200 for container orchestration
  • Hand-rolled HTTP/1.1 over the existing tokio runtime — no new dependencies; label values sanitized and escaped
  • Binds before workers spawn so port conflicts fail fast with a clear error

SIGTERM handling

docker stop now triggers the same graceful shutdown as Ctrl-C (repeat signal forces exit). Verified: container exits 0, not 143.

Dockerfile

Multi-stage rust:1.88-alpine (MSRV) → alpine:3.21 with CA certificates for enrichment lookups. Docker grants CAP_NET_RAW by default; docs cover --cap-add NET_RAW / Kubernetes securityContext for stricter runtimes.

Testing

  • 15 new tests (255 total passing): metrics rendering (counters/gauges/info series, unprobed-hop skipping, label escaping), async HTTP endpoint test (200/404/healthz), CLI parsing (:9090 shorthand, invalid addr rejection, conflict matrix, daemon+stream-json+prometheus composition)
  • cargo fmt --check / clippy --all-targets -- -D warnings clean
  • Live-verified in Docker: image builds (~2min), --daemon --prometheus :9090 1.1.1.1 serves real probe metrics, curl /healthz 200, docker stop → graceful SIGTERM shutdown, exit code 0

--daemon runs headless with no per-hop stdout, intended for container
and monitoring deployments; warns when started without an output sink.

--prometheus <ADDR> serves an OpenMetrics endpoint (GET /metrics) plus
GET /healthz for container orchestration. Per-hop sent/response/timeout
counters, RTT avg/min/max/stddev gauges, loss ratio, ECMP responder
count, and hop identity info series; per-target reachability, path
length, and total probes. Hand-rolled HTTP/1.1 over the existing tokio
runtime - no new dependencies.

SIGTERM now triggers the same graceful shutdown as Ctrl-C on unix, so
docker stop exits cleanly (code 0, not 143).

The Dockerfile is a multi-stage Alpine/musl build pinned to the MSRV
toolchain, producing a minimal runtime image with CA certificates for
enrichment lookups.
@lance0
lance0 merged commit e7f9776 into master Jun 10, 2026
5 checks passed
@lance0
lance0 deleted the daemon-prometheus branch June 10, 2026 20:40
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.

1 participant