Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

### Fixes

- **Uplinks follow a route change.** The uplink columns were chosen once at startup, so after a route-metric swap they still named the old uplink until a restart, while egress and locality had moved. Auto-detected uplinks are now re-read every `-localityRefreshInterval` (default 60s, 0 = never; pinned `-uplinkInterfaces` are never re-read). An unchanged list costs one `/proc` read; a changed one is read again from sysfs and lldpd and swapped in whole. New counter outcomes under `function="refreshUplinks"`: `unchanged`, `changed`, `lldp_error`.
- **Egress follows the lowest route metric.** With two routes for the same prefix, `enrich_socket_dest_egress_ifname` named the one listed last, which the kernel lists by ascending metric, so it was the highest-metric route. That is the one the kernel uses last. The lowest metric now wins, and on a tie the first route listed, as in the kernel's lookup.
- **Congestion names are matched whole.** `inet_diag_cong_enum` came from the first three letters, so `dctcp-reno` (DCTCP's fallback when ECN isn't negotiated) read as DCTCP and any name starting `cub` as CUBIC. Names now match exactly: `dctcp-reno` and look-alikes are UNSPECIFIED with their name kept, `bbr1` is BBR1, and `prague` gets its enum. A 2-letter name (`nv`, `lp`) without NLA padding is accepted (the minimum was 4 bytes). The in-tree names are now constants, so decoding them no longer allocates.
- **`nsid` 0 is no longer ambiguous.** The kernel's first namespace id is 0, which read the same as "no id" and as `-populateNsid` off; Docker gives its containers ids 0, 1, 2… in creation order, so one container per host had the ambiguous 0. New column `nsid_assigned` (proto tag 33, a free slot, so no record epoch bump) is true exactly when `nsid` holds an assigned id: filter on it, not on `nsid != 0`. Existing ClickHouse deployments add it with `build/containers/clickhouse/sql/migrations/nsid-assigned.sql`; rows from older daemons read false. The CSV/TSV default columns gain it after `nsid`, shifting the later columns by one. Golden records compare `nsid` again, numbered like the other ids.
Expand Down
2 changes: 1 addition & 1 deletion cmd/xtcp2/testdata/defineflags-golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ listenerSignedSkewMinutes 1 HMAC UTC-minute signed token skew in minutes (0-5).
lldpdSocket /run/lldpd.socket path to the lldpd control unix socket used by -enrichLldp. Falls back to LLDPD_SOCKET env.
lldpdVersionHint optional lldpd version hint (e.g. "1.0.18") to disambiguate the control-protocol struct layout; empty = auto-detect. Falls back to LLDPD_VERSION_HINT env.
localityEvents false with -enrichLocality, keep each namespace's locality snapshot current from rtnetlink link/address/route notifications (one listener per namespace) so a change shows within about a second; -localityRefreshInterval then becomes a backstop resync. Ignored without -enrichLocality. Falls back to LOCALITY_EVENTS env.
localityRefreshInterval 1m0s how often -enrichLocality re-dumps every namespace's addresses/routes on the reconcile path (new namespaces are always dumped on the next reconcile; failed or loopback-only namespaces retry on a 30s-5m backoff); 0 = discover each namespace once, never refresh. Falls back to LOCALITY_REFRESH_INTERVAL env.
localityRefreshInterval 1m0s how often -enrichLocality re-dumps every namespace's addresses/routes on the reconcile path (new namespaces are always dumped on the next reconcile; failed or loopback-only namespaces retry on a 30s-5m backoff); 0 = discover each namespace once, never refresh. Auto-detected uplinks (no -uplinkInterfaces) are re-read on the same interval. Falls back to LOCALITY_REFRESH_INTERVAL env.
location deployment grouping/facility this daemon runs in (data center, PoP, region, site, …); stamped on every record's `location`. Falls back to LOCATION env.
marshal protobufList Marshaling of the exported data (protobufList, protoJson, protoText, msgpack, jsonl, csv, tsv)
maxDumpBytes 268435456 cap on the bytes of one namespace's inet_diag dump per poll; packets past it are drained undecoded and counted in xtcp_dump_dropped_total{reason="bytes"}. 0 = unlimited. Falls back to MAX_DUMP_BYTES env.
Expand Down
2 changes: 1 addition & 1 deletion cmd/xtcp2/xtcp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func defineEnrichmentFlags(f *mainFlags) {
f.ipmetaBootstrapPath = flag.String("ipmetaBootstrapPath", ipmetaBootstrapPathCst, "optional zstd-compressed lookup artifact baked into the image and used by -enrichAsn before live refresh. Falls back to IPMETA_BOOTSTRAP_PATH env.")
f.ipmetaCachePath = flag.String("ipmetaCachePath", ipmetaCachePathCst, "optional writable zstd-compressed lookup artifact used by -enrichAsn before the image bootstrap and refreshed after successful live reloads. Falls back to IPMETA_CACHE_PATH env.")
f.enrichLocality = flag.Bool("enrichLocality", enrichLocalityCst, "best-effort: per namespace, dump the local addresses + routing table via rtnetlink and classify each socket's destination as self/local-subnet/remote, stamping the enrich_socket_dest_locality + interface-name columns (bound idiag_if and route egress). Non-fatal on read failure. Falls back to ENRICH_LOCALITY env."+enricherBuildNote(xtcp.EnricherLocality))
f.localityRefreshInterval = flag.Duration("localityRefreshInterval", localityRefreshIntervalCst, "how often -enrichLocality re-dumps every namespace's addresses/routes on the reconcile path (new namespaces are always dumped on the next reconcile; failed or loopback-only namespaces retry on a 30s-5m backoff); 0 = discover each namespace once, never refresh. Falls back to LOCALITY_REFRESH_INTERVAL env.")
f.localityRefreshInterval = flag.Duration("localityRefreshInterval", localityRefreshIntervalCst, "how often -enrichLocality re-dumps every namespace's addresses/routes on the reconcile path (new namespaces are always dumped on the next reconcile; failed or loopback-only namespaces retry on a 30s-5m backoff); 0 = discover each namespace once, never refresh. Auto-detected uplinks (no -uplinkInterfaces) are re-read on the same interval. Falls back to LOCALITY_REFRESH_INTERVAL env.")
f.localityEvents = flag.Bool("localityEvents", localityEventsCst, "with -enrichLocality, keep each namespace's locality snapshot current from rtnetlink link/address/route notifications (one listener per namespace) so a change shows within about a second; -localityRefreshInterval then becomes a backstop resync. Ignored without -enrichLocality. Falls back to LOCALITY_EVENTS env.")
}

Expand Down
8 changes: 8 additions & 0 deletions docs/design-metadata-enrichment.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ usable routes count (up, not reject, not on `lo`: every host has the kernel's
bridge) is replaced by the physical NICs under its `lower_*` sysfs links, since
those carry the NIC attributes and the LLDP neighbours.

Auto-detected uplinks are re-read every `-localityRefreshInterval` (default 60s,
0 = never), so a route-metric swap moves the uplink columns within one interval,
the same as egress and locality. A tick whose list is unchanged reads only
`/proc`; a changed list is read again from sysfs and lldpd off the hot path and
its stamp replaces the old one atomically, so a record never mixes two. Pinned
`-uplinkInterfaces` are never re-read. Outcomes are counted under
`function="refreshUplinks"`: `unchanged`, `changed`, `lldp_error`.

### Docker API limits

Docker's list and inspect bodies carry tenant-chosen data (image labels, the
Expand Down
2 changes: 1 addition & 1 deletion docs/design-rocm-ernic-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Any column that comes out exactly equal also gets a goldenrec unit row (`pkg/gol
- **A dropped SYN (found later):** in 2 of 12 captures `oracle_segs_out` was 1 or 2 short, while the kernel's own sum (`ss`, printed beside xtcp2's) agreed with xtcp2. The pcap on tap-ionic0 showed one SYN with no reply, and a new connection from another port 1 s later. ionic1 had dropped the SYN (every 64th frame). tcp_client's 1 s dial timeout then closed that socket just as the kernel's first SYN retransmit came due (`TCP_TIMEOUT_INIT`, include/net/tcp.h:174), and the closed socket's `segs_out` was lost. The ernic clients now use `-dialTimeout 30s`, so the kernel resends the SYN on the same socket.
- **Dropped rows:** `retrans_covers_drops` and `bytes_retrans_mss` were not added. The bulk transfers are echoes, so some dropped frames are pure ACKs for the echoed data, and TCP never retransmits those. Retransmits can therefore be fewer than the drops.
- **netem `loss_seen`:** the row's detail now reports netem's own drop count per namespace (`tc -s qdisc`). No failure has happened since, so the cause is still open (TODO).
- **Uplinks (phase 6):** `DefaultUplinks` trusts the kernel's listing order (ascending metric), puts IPv4 before IPv6, and runs once at startup (pkg/xtcp/enrich.go). `TestDefaultUplinksMetric` pins that behavior. TODO: the uplink columns don't follow a runtime metric change until xtcp2 restarts. Egress and locality refresh every 60 s, so only the uplinks lag.
- **Uplinks (phase 6):** `DefaultUplinks` trusts the kernel's listing order (ascending metric), puts IPv4 before IPv6, and runs once at startup (pkg/xtcp/enrich.go). `TestDefaultUplinksMetric` pins that behavior. Done in round 4: auto-detected uplinks are re-read every `locality_refresh_interval` (`refreshUplinks`; unchanged lists cost one `/proc` read, the stamp is swapped whole), so a metric swap moves them with egress and locality. The golden capture's `uplink_follows_metric` row swaps the e1000e's route in front of ionic0's after poll 2 and checks a later poll. `applyEnrichment` with the atomic stamp: 18.2 to 20.1 ns/op against 17.9 to 18.2 before (host load 5 to 9), 0 allocs.
- **Keepalive probe in flight (diff flake, TODO):** in one of five captures, `xtcp2-golden diff` reported an idle `golden-cc-a` connection with `inet_diag_msg_retrans` 1 and `tcp_info_probes` 1, but `total_retrans` 0 and nothing unacked. The poll caught Go's default 15 s keepalive probe before its ACK: the probe sets `icsk_probes_out` (net/ipv4/tcp_timer.c:844), `tcp_ack` clears it (net/ipv4/tcp_input.c:4430), and inet_diag reports it as `idiag_retrans` while the keepalive timer is pending (net/ipv4/inet_diag.c:295). This predates this work. A fix is `-keepalive 1h` on the idle workloads: the keepalive timer still shows (`inet_diag_msg_timer` 2), but no probe is sent during a capture.
- **Captures:** five, all 47 rows PASS on each (one at host load 18.6), with the oracle exact on all four NICs every time. `xtcp2-golden diff` is clean between captures 1, 3, 4 and 5; capture 2 differs only by the keepalive probe above. The sequence flow sent about 3100 frames with 12 drops, retransmitted 11 or 12 times (an 11 means one drop was a pure ACK), and never had an RTO, so `seq_no_rto` is asserted.
- **After the SYN fix:** eight more captures with a pcap on tap-ionic0. In seven, every row passed and the oracle was exact on all four NICs. The eighth failed only `loss_seen`, the netem TODO above, and aborted before the oracle ran.
Expand Down
4 changes: 4 additions & 0 deletions nix/microvms/mkVm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2422,8 +2422,12 @@ let
]
# The golden flavor adds locality and ASN over goldenAsnDb; the families
# check keeps the base args.
# The 5s refresh lets the capture's uplink_follows_metric row see a route
# swap re-read within a poll (refreshUplinks).
++ lib.optionals isS3ParquetGolden [
"-enrichLocality"
"-localityRefreshInterval"
"5s"
"-enrichAsn"
"-asnDbPath"
"${goldenAsnDb}"
Expand Down
22 changes: 21 additions & 1 deletion nix/microvms/scripts/golden-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ done
golden_ns_id=$(ip netns list | sed -n 's/^golden-ns (id: \([0-9]*\))$/\1/p')
caps=$(systemctl show xtcp2 -p CapabilityBoundingSet --value)

stop_and_fetch_second_poll "$OUT/raw.parquet"
# Uplinks follow a route change (refreshUplinks): move uplink 2's default
# route (the e1000e's, metric 2048) in front of ionic0's (512), wait for
# xtcp2 to re-read the uplinks (-localityRefreshInterval 5s), then for a
# poll that starts after that. Poll 2, the fixture, was taken before the
# swap; the later poll goes to $OUT/swap.parquet for uplink_follows_metric
# and is deleted after it.
swap_dev=$(ip -j route show default via 10.0.3.2 | jq -r '.[0].dev // empty')
[ -n "$swap_dev" ] || fail "uplink swap: no default route via 10.0.3.2"
ip route add default via 10.0.3.2 dev "$swap_dev" metric 256
ip route del default via 10.0.3.2 dev "$swap_dev" metric 2048
wait_for uplinks changed 1 30
wait_for envelopeFlush poll_end "$(($(metric envelopeFlush poll_end) + 1))" 60
stop_and_fetch_second_poll "$OUT/raw.parquet" "$OUT/swap.parquet"
ip route add default via 10.0.3.2 dev "$swap_dev" metric 2048
ip route del default via 10.0.3.2 dev "$swap_dev" metric 256

P="read_parquet('$OUT/raw.parquet')"
rows=$(q "SELECT count(*) FROM $P")
Expand Down Expand Up @@ -352,6 +366,12 @@ got=$(q "SELECT concat_ws(',', max(uplink2_nic_driver), max(uplink2_nic_pci_vend
ok=0
[ "$got" = "e1000e,32902,true,true" ] && ok=1
row uplink2 positive "$ok" "uplink2 driver, PCI vendor, firmware set, bus set: $got"
S="read_parquet('$OUT/swap.parquet')"
got=$(q "SELECT concat_ws(',', string_agg(DISTINCT uplink1_nic_driver, '/'), string_agg(DISTINCT uplink2_nic_driver, '/')) FROM $S")
ok=0
[ "$got" = "e1000e,ionic" ] && ok=1
row uplink_follows_metric positive "$ok" "uplink1, uplink2 drivers in a poll after $swap_dev's default route moved to metric 256: $got"
rm -f "$OUT/swap.parquet"
n=$(q "SELECT count(*) FROM $P WHERE uplink1_nic_driver = 'virtio_net' OR uplink2_nic_driver = 'virtio_net'")
ok=0
[ "$n" -eq 0 ] && ok=1
Expand Down
20 changes: 14 additions & 6 deletions nix/microvms/scripts/golden-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ wait_second_poll() {
fail "expected two poll_end and no poll_timeout, got $ends and $timeouts"
}

# stop_and_fetch_second_poll stops xtcp2 (Close uploads poll 2's object)
# and downloads that object, the newer of the two, to $1.
# stop_and_fetch_second_poll stops xtcp2 (Close uploads the last poll's
# object) and downloads poll 2's object, the second oldest, to $1. With no
# $2 there must be exactly two objects; with $2, xtcp2 was left running for
# more polls: there must be at least three, and the newest goes to $2.
stop_and_fetch_second_poll() {
systemctl stop xtcp2
local listing="" count second
local listing="" count second want=2
if [ -n "${2:-}" ]; then want=3; fi
for _ in $(seq 1 30); do
listing=$(rclone lsf -R --files-only --include '*.parquet' --format tp --separator ' ' "s3:$BUCKET" 2>/dev/null || true)
if [ "$(printf '%s' "$listing" | grep -c . || true)" -ge 2 ]; then break; fi
if [ "$(printf '%s' "$listing" | grep -c . || true)" -ge "$want" ]; then break; fi
sleep 1
done
count=$(printf '%s' "$listing" | grep -c . || true)
[ "$count" -eq 2 ] || fail "expected 2 objects (polls 1 and 2), got $count"
second=$(printf '%s\n' "$listing" | sort | tail -n1 | awk '{print $NF}')
if [ -z "${2:-}" ]; then
[ "$count" -eq 2 ] || fail "expected 2 objects (polls 1 and 2), got $count"
else
[ "$count" -ge 3 ] || fail "expected at least 3 objects (polls 1, 2 and later), got $count"
rclone copyto "s3:$BUCKET/$(printf '%s\n' "$listing" | sort | tail -n1 | awk '{print $NF}')" "$2" || fail "download failed"
fi
second=$(printf '%s\n' "$listing" | sort | sed -n 2p | awk '{print $NF}')
rclone copyto "s3:$BUCKET/$second" "$1" || fail "download failed"
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/nicinfo/uplinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ const maxLowerDepth = 8
// The metric is not read: the kernel lists same-prefix routes in ascending
// metric order (IPv4 fib_find_alias, net/ipv4/fib_trie.c; IPv6
// fib6_add_rt2node, net/ipv6/ip6_fib.c), so the listing order is already the
// lowest metric first. xtcp2 calls this once at startup; a later route change
// does not move the uplink columns until a restart.
// lowest metric first. xtcp2 calls this at startup and again every
// locality_refresh_interval, so a route change moves the uplink columns
// within one interval (pkg/xtcp refreshUplinks).
func DefaultUplinks(maxN int) []string {
return defaultUplinks("/proc", "/sys", maxN)
}
Expand Down
Loading