Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
- **`_FILE` secrets are checked.** A missing or unreadable `*_FILE` path, a non-regular file, or one readable by group or others stops startup with exit 64. It used to be ignored silently (listener tokens) or logged (S3 keys), leaving the credential empty. Mount secrets mode `0400`.
- **The debug writers are build-time opt-ins.** The netlink capture writer (`-writeFiles` / `-capturePath`) is compiled in only with `-tags capture`, which no flavor or image sets; use `nix build .#xtcp2-capture`. The `file:` destination needs `-tags dest_file` and is in the full (development) flavor only, so `xtcp2-<dest>` slim flavors and their images no longer have it. Asking for either on a binary without it exits 64 at startup with the tag to rebuild with; `ConfigService.Set` refuses it with `FailedPrecondition`. A capture build reports `+capture` in its version line, and when armed logs a warning and sets `xtcp2_debug_capture_enabled 1`.
- **`/ip` and the daemons carry no netlink write verbs.** goip's write verbs and `pkg/xtcpnl`'s write builders compile only with `-tags goip_write`, which only `goip` and `goip-parity` are built with. `/ip` on xtcp2 and go-link-monitor answers a write verb 400 as before; an untagged `goip` answers one `ErrWriteNotCompiled` (exit 1), so a `go build ./cmd/goip` that needs them must add the tag. The Nix `goip` and `goip-parity` store names gain `-goip_write`; their binary paths are unchanged. `checks.no-write-encoders` proves the daemons link no write encoder and import no `os/exec` (bar minio-go's credentials provider).
- **Operator strings reject control characters.** `hostname`, `location`, `label` and `tag` (flags, env or `ConfigService.Set`) now fail validation, exit 64, if they hold a C0 control, DEL or a C1 control; their length limits are unchanged.

### New

- **The S3 upload queue never blocks polling.** It used to block the poller once 16 envelopes were waiting for a slow or unreachable S3. Now `-s3QueueDepth` (default 16, max 4096) and `-s3MaxBufferedBytes` (default 64 MiB, `0` = no byte bound) bound it, and past either it drops the oldest envelope. Drops are counted in `xtcp_s3_dropped_total{reason}` and `xtcp_s3_dropped_bytes_total{reason}`; `xtcp_s3_buffered_bytes{stage}` shows what is held, and `queueFull` now counts drops. Env `S3_QUEUE_DEPTH`, `S3_MAX_BUFFERED_BYTES`; startup-only (`ConfigService.Set` keeps the running values). Budget ≈ `-s3MaxBufferedBytes` + the flush threshold + one upload ([design](docs/design-jitter-and-backoff.md#back-pressure--memory)).
- **S3 spill directory.** `-s3SpillDir` / `S3_SPILL_DIR` keeps Parquet objects that failed to upload on disk and uploads them, oldest first, once S3 is back, including after a restart. With it the worker tries each upload once and spills on failure, so it keeps draining the queue during an outage. `-s3SpillMaxBytes` / `S3_SPILL_MAX_BYTES` (default 1 GiB) bounds the directory, deleting the oldest past it. Metrics `xtcp_s3_spill_total{result}`, `xtcp_s3_spill_objects`, `xtcp_s3_spill_bytes`. Off by default; startup-only ([design](docs/design-jitter-and-backoff.md#spill-directory)).
- **Strings from tenants and the network are cleaned.** Container names and images, a tenant's interface names, LLDP and NIC strings, the ASN feed's network owner, netns names and congestion names are cut to 256 bytes (16 for interface and congestion names) at a UTF-8 boundary. Invalid UTF-8 and control characters (C0, DEL, C1) become U+FFFD. Each is cleaned once, where it enters, not per row.
- **Per-namespace caps.** `-maxDumpBytes` (default 256 MiB) and `-maxRecordsPerNetns` (default 262144) bound one namespace's dump per poll: packets past the byte cap are drained undecoded, and records past the record cap are dropped before decode. `-maxNetns` (default 4096) bounds the namespaces tracked. At the cap, tracked namespaces keep their slots, and new ones wait for a freed slot, first come, first served. Alert on `xtcp_netns_dropped_total`. Drops are counted in `xtcp_dump_dropped_total{reason}` and `xtcp_netns_dropped_total`, with one log line per truncated dump or short reconcile. `0` turns a cap off; the matching env vars are `MAX_DUMP_BYTES`, `MAX_RECORDS_PER_NETNS` and `MAX_NETNS`. The caps are startup-only: `ConfigService.Set` keeps the running values. No healthy host should reach the defaults; a host that does now loses that namespace's excess rows, where it used to collect them all ([polling and batching](docs/polling-and-batching.md#per-namespace-caps)).
- **Socket-count gate, reconcile limits, per-owner quota.** Before each poll xtcp2 reads each namespace's sockstat (an fd opened in the namespace; `pread`, or io_uring batches with `-ioUring`) and, when the total is over `-maxRecordsPerPoll` (default 1,048,576), degrades only the namespaces over their fair share: first TIME_WAIT/SYN_RECV are not asked for, then one of K port shards is dumped per poll. `-maxNetnsPerOwner` (default 64) caps namespaces tracked per owner (the container runtime's cgroup), `-maxNetnsAddsPerReconcile` (256) the adds per reconcile, and `-reconcileTimeout` (1s) the namespace scan; a timed-out scan deletes nothing. New metrics `xtcp_poll_sockets`, `xtcp_poll_degraded_total{level}` and `xtcp_reconcile_incomplete_total{reason}`; `xtcp_netns_dropped_total` gains `reason`. `0` turns each off; all are startup-only. Each tracked namespace now holds four fds (was two: sockstat and `ip_local_port_range` are new), and xtcp2 warns at startup when `RLIMIT_NOFILE` can't cover them ([polling and batching](docs/polling-and-batching.md#socket-count-gate), [network namespaces](docs/network-namespaces.md#configuration)). The analysis behind an upstream all-namespace dump is in [docs/kernel](docs/kernel/inet-diag-all-netns.md).
- **Vulnerability check.** `checks.govulncheck` runs govulncheck against a pinned snapshot of the Go vulnerability database, with no tags and with every flavor tag, and fails on a reachable finding not in its accepted list. One is accepted: GO-2026-6859 in `net/http`, fixed in go1.27.4, until the toolchain moves. `nix run .#govulncheck-fresh` checks against the live database and runs `go mod verify`; `nix build .#sbom-<binary>` writes a CycloneDX SBOM for any binary package.
Expand Down
4 changes: 4 additions & 0 deletions cmd/xtcp2/testdata/defineflags-golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,15 @@ s3Endpoint s3parquet: S3-compatible endpoint URL (e.g. http://127.0.0.1:9000 fo
s3FlushInterval 0s s3parquet: staleness ceiling — force-flush the in-memory Parquet object after this long even if under the byte cap. 0 = derive as max(-frequency, 30m).
s3FlushJitterPct 20 s3parquet: jitter as a percent (0-100) of -s3FlushInterval, applied to the timed flush so the fleet doesn't ceiling-flush in lockstep. 0 disables.
s3FlushThresholdJitterPct 20 s3parquet: per-object downward jitter as a percent (0-100) of the byte cap; each object finalizes at threshold*(1-rand[0,pct/100]) to de-sync the size-cap upload path. 0 disables.
s3MaxBufferedBytes 67108864 s3parquet: marshaled envelope bytes the upload queue may hold. Past it the oldest envelope is dropped (reason="buffered_bytes"); the newest is always kept. 0 = no byte bound. Falls back to S3_MAX_BUFFERED_BYTES env.
s3ParquetFlushBytes 0 s3parquet: soft cap on the in-memory Parquet builder's uncompressed row bytes before finalize+upload. 0 = daemon default (63 MiB).
s3Prefix s3parquet: optional key prefix within the bucket. Combined with Hive-style partitioning host=…/date=…/hour=…/<file>.parquet.
s3QueueDepth 16 s3parquet: envelopes queued for the upload worker (max 4096). Past it the oldest is dropped and counted in xtcp_s3_dropped_total{reason="queue_depth"}, so an S3 outage never blocks polling. 0 = 16. Falls back to S3_QUEUE_DEPTH env.
s3Region s3parquet: S3 region. Defaults to 'us-east-1' when empty; required by AWS, ignored by most MinIO setups.
s3SecretKey s3parquet: S3 secret key. Prefer S3_SECRET_KEY_FILE (path to a file, mode 0400, holding the key): a flag value shows in ps and docker inspect, warns, and is refused by production builds. Never logged.
s3SkipBucketProbe false s3parquet: skip the startup BucketExists probe (a HeadBucket needing s3:ListBucket). Set true for a write-only, s3:PutObject-only credential. Falls back to S3_SKIP_BUCKET_PROBE env.
s3SpillDir s3parquet: directory for Parquet objects that failed to upload; they are retried in the background, oldest first. The worker then tries each upload once and spills on failure, so it keeps draining the queue during an S3 outage. Empty = no spill (drop after -s3UploadMaxAttempts). One daemon per directory. Falls back to S3_SPILL_DIR env.
s3SpillMaxBytes 1073741824 s3parquet: bytes -s3SpillDir may hold; past it the oldest spilled object is deleted. 0 = 1 GiB. Falls back to S3_SPILL_MAX_BYTES env.
s3UploadBackoffCap 0s s3parquet: cap on a single upload retry's backoff window (full jitter draws in [0,window]). 0 = derive as clamp(-frequency/10, 1s, 1h).
s3UploadMaxAttempts 10 s3parquet: max upload attempts (original + retries) before dropping the object. Retries use full-jitter exponential backoff.
tag label applied to the protobuf
Expand Down
4 changes: 4 additions & 0 deletions cmd/xtcp2/testdata/printflags-golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*s3FlushThresholdJitterPct: 117
*s3UploadMaxAttempts: 118
*s3UploadBackoffCap: 119ms
*s3QueueDepth: 1191
*s3MaxBufferedBytes: 1192
*s3SpillDir: s3SpillDir-v
*s3SpillMaxBytes: 1193
*reconcileFrequency: 120ms
*reconcileBeforePoll: false
*maxDumpBytes: 1201
Expand Down
58 changes: 52 additions & 6 deletions cmd/xtcp2/xtcp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,15 @@ const (
// docs/design-jitter-and-backoff.md. A 0 pct disables the corresponding
// jitter (restoring deterministic behavior); the two 0-valued durations
// mean "derive from poll_frequency" (see the s3parquet destination).
pollJitterPctCst uint = 20
s3FlushIntervalCst = 0 * time.Second
s3FlushJitterPctCst uint = 20
s3FlushThresholdJitterPctCst uint = 20
s3UploadMaxAttemptsCst uint = 10
s3UploadBackoffCapCst = 0 * time.Second
pollJitterPctCst uint = 20
s3FlushIntervalCst = 0 * time.Second
s3FlushJitterPctCst uint = 20
s3FlushThresholdJitterPctCst uint = 20
s3UploadMaxAttemptsCst uint = 10
s3UploadBackoffCapCst = 0 * time.Second
s3QueueDepthCst uint = 16
s3MaxBufferedBytesCst uint64 = 64 * 1024 * 1024
s3SpillMaxBytesCst uint64 = 1024 * 1024 * 1024

// Namespace-reconcile cadence defaults (Method B /proc-scan discovery).
// reconcileBeforePoll ties discovery to poll cadence (reconcile before each
Expand Down Expand Up @@ -309,6 +312,10 @@ type mainFlags struct {
s3FlushThresholdJitterPct *uint
s3UploadMaxAttempts *uint
s3UploadBackoffCap *time.Duration
s3QueueDepth *uint
s3MaxBufferedBytes *uint64
s3SpillDir *string
s3SpillMaxBytes *uint64

reconcileFrequency *time.Duration
reconcileBeforePoll *bool
Expand Down Expand Up @@ -550,6 +557,10 @@ func defineS3Flags(f *mainFlags) {
f.s3FlushThresholdJitterPct = flag.Uint("s3FlushThresholdJitterPct", s3FlushThresholdJitterPctCst, "s3parquet: per-object downward jitter as a percent (0-100) of the byte cap; each object finalizes at threshold*(1-rand[0,pct/100]) to de-sync the size-cap upload path. 0 disables.")
f.s3UploadMaxAttempts = flag.Uint("s3UploadMaxAttempts", s3UploadMaxAttemptsCst, "s3parquet: max upload attempts (original + retries) before dropping the object. Retries use full-jitter exponential backoff.")
f.s3UploadBackoffCap = flag.Duration("s3UploadBackoffCap", s3UploadBackoffCapCst, "s3parquet: cap on a single upload retry's backoff window (full jitter draws in [0,window]). 0 = derive as clamp(-frequency/10, 1s, 1h).")
f.s3QueueDepth = flag.Uint("s3QueueDepth", s3QueueDepthCst, "s3parquet: envelopes queued for the upload worker (max 4096). Past it the oldest is dropped and counted in xtcp_s3_dropped_total{reason=\"queue_depth\"}, so an S3 outage never blocks polling. 0 = 16. Falls back to S3_QUEUE_DEPTH env.")
f.s3MaxBufferedBytes = flag.Uint64("s3MaxBufferedBytes", s3MaxBufferedBytesCst, "s3parquet: marshaled envelope bytes the upload queue may hold. Past it the oldest envelope is dropped (reason=\"buffered_bytes\"); the newest is always kept. 0 = no byte bound. Falls back to S3_MAX_BUFFERED_BYTES env.")
f.s3SpillDir = flag.String("s3SpillDir", "", "s3parquet: directory for Parquet objects that failed to upload; they are retried in the background, oldest first. The worker then tries each upload once and spills on failure, so it keeps draining the queue during an S3 outage. Empty = no spill (drop after -s3UploadMaxAttempts). One daemon per directory. Falls back to S3_SPILL_DIR env.")
f.s3SpillMaxBytes = flag.Uint64("s3SpillMaxBytes", s3SpillMaxBytesCst, "s3parquet: bytes -s3SpillDir may hold; past it the oldest spilled object is deleted. 0 = 1 GiB. Falls back to S3_SPILL_MAX_BYTES env.")
}

// defineCapFlags registers the three caps on what a tenant can cost the
Expand Down Expand Up @@ -742,6 +753,10 @@ func printS3Flags(f *mainFlags) {
fmt.Println("*s3FlushThresholdJitterPct:", *f.s3FlushThresholdJitterPct)
fmt.Println("*s3UploadMaxAttempts:", *f.s3UploadMaxAttempts)
fmt.Println("*s3UploadBackoffCap:", *f.s3UploadBackoffCap)
fmt.Println("*s3QueueDepth:", *f.s3QueueDepth)
fmt.Println("*s3MaxBufferedBytes:", *f.s3MaxBufferedBytes)
fmt.Println("*s3SpillDir:", *f.s3SpillDir)
fmt.Println("*s3SpillMaxBytes:", *f.s3SpillMaxBytes)
fmt.Println("*reconcileFrequency:", *f.reconcileFrequency)
fmt.Println("*reconcileBeforePoll:", *f.reconcileBeforePoll)
}
Expand Down Expand Up @@ -871,6 +886,10 @@ func buildConfig(f *mainFlags, des *xtcp_config.EnabledDeserializers) *xtcp_conf
S3FlushThresholdJitterPct: uint32(*f.s3FlushThresholdJitterPct),
S3UploadMaxAttempts: uint32(*f.s3UploadMaxAttempts),
S3UploadBackoffCap: durationpb.New(*f.s3UploadBackoffCap),
S3QueueDepth: uint32(*f.s3QueueDepth),
S3MaxBufferedBytes: *f.s3MaxBufferedBytes,
S3SpillDir: *f.s3SpillDir,
S3SpillMaxBytes: *f.s3SpillMaxBytes,
ReconcileFrequency: durationpb.New(*f.reconcileFrequency),
ReconcileBeforePoll: *f.reconcileBeforePoll,
MaxDumpBytes: *f.maxDumpBytes,
Expand Down Expand Up @@ -1651,6 +1670,7 @@ func environmentOverrideConfig(c *xtcp_config.XtcpConfig, debugLevel uint) {
envOverridePacket(c, debugLevel)
envOverrideMarshalAndDest(c, debugLevel)
envOverrideCaps(c, debugLevel)
envOverrideS3Queue(c, debugLevel)
envOverrideKafka(c, debugLevel)
envOverrideLabeling(c, debugLevel)
envOverrideEnrichment(c, debugLevel)
Expand Down Expand Up @@ -2378,6 +2398,28 @@ func checkNoPositional(args []string) error {
return fmt.Errorf("unexpected argument %q: flags take -name value, and an empty value must be quoted (-name \"\" or -name=)", args[0])
}

// envOverrideS3Queue applies S3_QUEUE_DEPTH, S3_MAX_BUFFERED_BYTES,
// S3_SPILL_DIR and S3_SPILL_MAX_BYTES, the s3parquet upload queue's bounds
// and its spill directory.
func envOverrideS3Queue(c *xtcp_config.XtcpConfig, debugLevel uint) {
if v, ok := envUint32("S3_QUEUE_DEPTH"); ok {
c.S3QueueDepth = v
logEnv("S3_QUEUE_DEPTH", fmt.Sprintf("c.S3QueueDepth:%d", v), debugLevel)
}
if v, ok := envUint64("S3_MAX_BUFFERED_BYTES"); ok {
c.S3MaxBufferedBytes = v
logEnv("S3_MAX_BUFFERED_BYTES", fmt.Sprintf("c.S3MaxBufferedBytes:%d", v), debugLevel)
}
if v, ok := envString("S3_SPILL_DIR"); ok {
c.S3SpillDir = v
logEnv("S3_SPILL_DIR", "c.S3SpillDir:"+v, debugLevel)
}
if v, ok := envUint64("S3_SPILL_MAX_BYTES"); ok {
c.S3SpillMaxBytes = v
logEnv("S3_SPILL_MAX_BYTES", fmt.Sprintf("c.S3SpillMaxBytes:%d", v), debugLevel)
}
}

// envOverrideCaps applies MAX_DUMP_BYTES, MAX_RECORDS_PER_NETNS and
// MAX_NETNS; see defineCapFlags.
func envOverrideCaps(c *xtcp_config.XtcpConfig, debugLevel uint) {
Expand Down Expand Up @@ -2436,4 +2478,8 @@ func printConfigCaps(c *xtcp_config.XtcpConfig) {
fmt.Println("c.ReconcileTimeout:", c.ReconcileTimeout.AsDuration())
fmt.Println("c.MaxNetnsPerOwner:", c.MaxNetnsPerOwner)
fmt.Println("c.MaxNetnsAddsPerReconcile:", c.MaxNetnsAddsPerReconcile)
fmt.Println("c.S3QueueDepth:", c.S3QueueDepth)
fmt.Println("c.S3MaxBufferedBytes:", c.S3MaxBufferedBytes)
fmt.Println("c.S3SpillDir:", c.S3SpillDir)
fmt.Println("c.S3SpillMaxBytes:", c.S3SpillMaxBytes)
}
6 changes: 5 additions & 1 deletion cmd/xtcp2/xtcp2_flags_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const (
// mainFlags field must be a registered flag and every registered flag must
// have a field. A flag added without a field, or a field that stops being
// registered, is the drift this file exists to notice.
mainFlagsFieldCountCst = 139 // + treatmentConfig (embedded agent) and treatmentAttribution (journal reader)
mainFlagsFieldCountCst = 143 // + treatmentConfig (embedded agent) and treatmentAttribution (journal reader)

printFlagsGoldenCst = "testdata/printflags-golden.txt"
defineFlagsGoldenCst = "testdata/defineflags-golden.txt"
Expand Down Expand Up @@ -190,6 +190,10 @@ func populatedMainFlags() *mainFlags {
s3FlushThresholdJitterPct: u(117),
s3UploadMaxAttempts: u(118),
s3UploadBackoffCap: ms(119),
s3QueueDepth: u(1191),
s3MaxBufferedBytes: u64(1192),
s3SpillDir: s("s3SpillDir-v"),
s3SpillMaxBytes: u64(1193),

reconcileFrequency: ms(120),
reconcileBeforePoll: b(false),
Expand Down
Loading