Repository navigation
fix(telemetry): report lost records once on stderr when the run drains - #439
Conversation
|
Assessment: Request Changes The single drain-time line, with no change to the exit code, fits the agreed triage scope. But the way the drain sorts its causes reports any failed final export as a timeout. That includes the PR's own unreachable-target scenario, and the tests do not catch it (see inline). Checks that held
Splitting the counter and stating plainly what the line does not prove are both good calls. |
|
Assessment: Comment b7bfee2 fixes both earlier findings. One narrower gap remains: deciding whether the drain finished from the provider-wide counter misses a cut in one lane when another lane is also failing (inline on Checks that held
|
## Problem
When a telemetry target failed, the collector counted the failed batch and printed nothing. When
the exit flush did not finish in time, the collector also counted it and printed nothing. So a
workload that filled the disk under a file target, or made an OTLP target hang, removed the records
of its own last actions with no signal, and the run still exited 0. The decision "Delivery is best
effort" (docs/design/decisions.md#delivery-is-best-effort) says that the collector prints to stderr
when delivery fails, but the code did not.
The receiver shared the same counter. So a refused agent payload (the one-permit relay bound, or the
fan-out bound) counted as a lost record, and the workload could raise any loss signal at will.
## Solution
`Collector::drained` now prints one stderr line when an export to a configured target failed, or
when the final export did not finish in time. The line names its cause:
strands-box: warning: telemetry records were lost: 2 exports to the configured targets failed
The line is printed once, at the drain, and not in `deliver`, so a workload that makes every batch
fail cannot fill stderr. It carries a count and fixed text only, and no destination or secret. The
exit code does not change, because a failed audit sink that the workload can break must not also
let the workload fail the run. Maintainers accepted this scope in triage: one stderr line at the
drain, no retry, no gap-marker record, and no non-zero exit.
The receiver now has its own counter, so `dropped` counts only batches an exporter failed to
deliver. An unfinished drain no longer increments `dropped`, because no export failed; the line
states that cause separately. `drained` keeps its signature, so the crate facade does not change.
The user page (docs/user/telemetry.md), the design page (docs/design/telemetry.md) and the crate
AGENTS.md now state the line and what it does not count: a record the SDK queue refuses, an agent
payload the receiver refuses, and a relay in flight at shutdown.
## Tests
- `box_telemetry.rs::an_unreachable_target_reports_the_lost_records_once`: an OTLP target on a
closed port gives exactly one loss line, and the run still succeeds. With the `eprintln!` removed,
this test fails.
- `box_telemetry.rs::a_declared_file_target_is_where_the_records_go` now also asserts that a target
that took every record prints no loss line.
- `collector.rs::a_lossy_drain_reports_the_loss_once`, `a_complete_drain_reports_no_loss` and
`an_unfinished_drain_alone_is_a_loss` pin the text and each cause.
- `cargo test -p strands-box-telemetry --all-features`: 87 passed. `cargo test -p strands-box
--all-features --test box_telemetry`: 26 passed, 1 ignored. `site_manifest`: 27 passed. fmt is
clean, clippy reports no owned warnings, and `Cargo.lock` holds one `reqwest`.
Not run: a Linux build (no cross-compiler on the macOS host), and a live Strands SDK agent run.
b7bfee2 to
c28824a
Compare
|
Assessment: Comment c28824a fixes the mixed-lane case from my last comment: a stalled lane next to a fast-failing lane now reports both causes, and Checks that held
|
|
Assessment: Approve (from the telemetry-drain side) 9aa7838 fixes the regression in my last comment, and I found nothing new in this commit. Each lane now decides "did not finish" for itself, before the SDK joins the lane errors. An error counts as a finished, failed export only when it is a failed export that the lane's own exporter started inside this shutdown. Checks that held
|
Human readable section
Problem: When Box could not deliver telemetry to a configured target, it lost the records and said nothing. That happened both during the run and at exit. A workload could use this to hide its own last actions: fill the disk under the file target, or make an OTLP target hang, then act and exit. The records were gone, and the run still exited 0. The design decision on telemetry delivery already says the collector prints to stderr when delivery fails, but the code did not.
Solution: When the run ends, Box prints one warning on stderr if an export to a configured target failed, or if the final export did not finish in time. The warning says which of these happened. The exit code does not change.
Trade-off: The warning comes once, at the end of the run, not at each failure. A workload cannot flood stderr that way, but the operator learns of the loss only when the run ends. The warning does not prove that nothing was lost when it is absent: records the telemetry queue refuses, agent payloads Box refuses, and relays in flight at shutdown are still not counted.
Description
Example line:
Decisions this depends on
deliver. This is the scope maintainers accepted in triage: one stderr line at the drain, no retry, no gap-marker record, and no non-zero exit. A non-zero exit would let a workload fail the run by breaking an audit sink it can reach.droppedwith the exporters, so a refused agent payload (the one-permit relay bound, or the fan-out bound) counted as a lost record. The workload could then raise the warning at will. Nowdroppedcounts only batches an exporter failed to deliver.dropped, and the line names it ("the final export did not finish in time") instead of calling it a failed export. A final export that fails at once (a closed port, a full disk) makes the SDK return an error, not a timeout, soshut_down_boundedreturns a typed outcome, and only a drain that got no answer, or a lane whose own shutdown did not finish, reads as "did not finish". A lane's shutdown did not finish when the SDK cut its final export at the deadline, or when the shutdown failed without a counted export failure from that shutdown (for example, a full queue refused the shutdown message, so nothing was exported). Each lane sets the flag itself, because the SDK joins every lane's error into one, so a lane that fails fast cannot hide a lane that did not finish.Collector::drainedkeeps its signature, the crate facade does not change, and the line carries a count and fixed text only, with no destination or secret.Docs in this PR:
docs/user/telemetry.md(errors section),docs/design/telemetry.md(limits), and the telemetry crate'sAGENTS.md.decisions.md#delivery-is-best-effortalready says the collector prints to stderr, and is now closer to true. A wording update there to "prints one line at the drain" is optional and left out.Checks CI cannot perform: a live Strands SDK agent run was not done.
Related Issues
None.
Type of Change
Bug fix
Testing
an_unreachable_target_reports_the_lost_records_once(box_telemetry): an OTLP target on a closed port gives exactly one loss line, and the run still succeeds. It fails when theeprintln!is removed.a_declared_file_target_is_where_the_records_gonow also asserts that a healthy target prints no loss line.a_lossy_drain_reports_the_loss_once,a_complete_drain_reports_no_lossandan_unfinished_drain_alone_is_a_losspin the text and each cause.a_counted_export_failure_is_not_reported_as_a_timeoutanda_fast_failing_final_export_is_not_a_timeoutpin that a final export that fails at once is reported as a failed export and not as "did not finish in time". The box test also asserts this. All three fail with the first version's mapping.a_cut_lane_is_reported_beside_a_failing_lanepins a cut lane (a file target on a full pipe) beside a lane that fails fast (OTLP on a closed port), and fails without the per-lane flag.a_shutdown_the_worker_never_receives_is_not_finishedpins a shutdown that a full queue refuses (4000 records behind a listener that never accepts), and fails when only a timeout sets the flag.a_refused_agent_payload_is_not_a_lost_recordpins that a payload the receiver refuses raises the receiver's own count and leavesdroppedat 0.At
9aa7838, rebased ontomain:cargo test --workspace --all-features: 5207 passed, 0 failed, 19 ignored.cargo test -p strands-box-telemetry --all-features: 92 passed.cargo test -p strands-box --all-features --test box_telemetry: 26 passed, 1 ignored.site_manifest: 27 passed. fmt is clean, clippy reports no owned warnings, andCargo.lockstill holds onereqwest.feature-critic ran on the diff. Its findings (the shared counter, the missing print pin, the doc-comment placement, and the wording) are fixed in this commit. It ran again on the per-lane fix: no blocker, and its three minor findings (a timing-dependent pipe fill, a comment, and an uncounted cut during an ordinary export now listed in the docs) are fixed. A third run, on the shutdown fix, found no blocker, and its three minor findings (an export in flight could answer for the shutdown, two stale doc comments, and a test that depends on the SDK queue defaults) are fixed.
Linux (Ubuntu, kernel 7.3, arm64, in a Lima VM), at the first commit (
0135c52before the rebase ontomain, now975ef51): the workspace build passes.cargo test -p strands-box-telemetry --all-features: 87 passed.cargo test -p strands-box --all-features --test box_telemetry: 26 passed, 1 ignored, includingan_unreachable_target_reports_the_lost_records_once.just clippypasses, and fmt is clean.I ran the relevant suites (
just check, orcargo test --workspace --all-features):cargo test --workspace --all-featurespassed, 5207 passed, 0 failed, 19 ignoredIf I touched Rust, I ran
cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warnings: fmt is clean. The plain-D warningsform stops on 9 lints that already exist in the vendoredcrates/shell, which this PR does not touch. Thejust clippyrecipe passes the whole workspace.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.