Skip to content

Add trace diffing (--diff) and streaming JSON output (--stream-json) - #81

Merged
lance0 merged 1 commit into
masterfrom
diff-streaming
Jun 10, 2026
Merged

lance0 merged 1 commit into
masterfrom
diff-streaming

Conversation

@lance0

@lance0 lance0 commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the full Trace Diffing & Streaming section of the roadmap as the v0.20 theme.

Trace diffing (--diff before.json after.json)

  • Compares two saved sessions hop by hop: [path] markers for primary-responder changes, [added]/[lost] for hop presence, and +ip/-ip detail lines for ECMP responder-set churn
  • Avg RTT and loss shown side by side; latency shifts highlighted when >=5ms and >=20% of the before value
  • Summary line with change counts and destination reachability; ANSI color when stdout is a terminal
  • --diff ... --json emits the whole diff as machine-readable JSON
  • Warns when the two sessions trace different targets

Streaming JSON (--stream-json)

  • One JSON line per probe event (reply/timeout/late_reply), same schema as the events array in saved session files plus a target field for demultiplexing multi-target runs
  • Final summary line per target (complete, dest_ttl, total_sent, hops_responding)
  • Implies --no-tui; conflicts with batch output flags; works with -c or until Ctrl-C
  • Events are drained rather than indexed, keeping memory bounded for long-running monitoring pipelines; a final drain after receiver join catches late replies

Implementation notes

  • New src/export/diff.rs and src/export/stream.rs follow the existing export-module conventions (generic Write sinks, re-exported from export::)
  • --diff early-exits in main() like --replay (no sockets, no permissions needed); load_session error messages generalized from "replay file" to "session file"
  • External strings (hostnames, file paths) routed through sanitize_display before terminal output

Testing

  • 16 new tests (240 total passing): diff classification (path change, added/lost, silent-hop skipping, RTT significance thresholds, ECMP responder churn), NDJSON line schemas, CLI conflict matrix
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings clean
  • Manually verified: --diff text + JSON output against generated fixtures (piped through jq); --stream-json live against localhost with finite -c runs, infinite runs ended via SIGINT (graceful summary emission), and jq filter composability

--diff before.json after.json compares two saved sessions hop by hop:
path changes, added/lost hops, ECMP responder-set changes, avg RTT
deltas (highlighted when >=5ms and >=20%), loss changes, and
destination reachability. Combine with --json for machine-readable
diff output.

--stream-json emits each probe event (reply/timeout/late_reply) as one
JSON line on stdout for piping to jq/grep/monitoring pipelines. Lines
match the saved-session events schema with a target field added, and a
per-target summary line closes the stream. Events are drained rather
than indexed so memory stays bounded on infinite runs.
@lance0
lance0 merged commit cab96bd into master Jun 10, 2026
5 checks passed
@lance0
lance0 deleted the diff-streaming branch June 10, 2026 20:18
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