test(bottlecap): fix clock race in increment metric tests - #1368
Draft
lucaspimentel wants to merge 1 commit into
Draft
test(bottlecap): fix clock race in increment metric tests#1368lucaspimentel wants to merge 1 commit into
lucaspimentel wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only change correctly eliminates the documented timestamp race.
Pull request overview
Fixes flaky enhanced-metrics tests by reusing one timestamp for metric insertion and lookup.
Changes:
- Removes duplicate wall-clock reads from two tests.
- Prevents crossing ten-second aggregation bucket boundaries.
File summaries
| File | Description |
|---|---|
bottlecap/src/metrics/enhanced/lambda.rs |
Reuses the original timestamp in invocation and error metric assertions. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes a flaky race condition in two enhanced-metrics tests in
bottlecap/src/metrics/enhanced/lambda.rs:test_increment_invocation_metrictest_increment_errors_metricEach test read the wall clock twice: once for the timestamp passed to the increment method, and again (shadowing the first value) for the timestamp passed to
assert_sketch. Thedogstatsddependency rounds timestamps down to ten-second buckets ((timestamp / 10) * 10), and that bucket participates in the aggregator metric ID. When the two clock reads straddled a ten-second boundary, the metric was inserted under one ID and looked up under another, causing failures such asaws.lambda.enhanced.errors not found.This was observed in job 102934913271, which failed at 0.076s immediately after the clock crossed a ten-second boundary and passed on rerun with no code changes.
The fix reuses the test's first
nowvalue for both the increment method andassert_sketch, guaranteeing insertion and lookup use the same timestamp bucket. Test-only change: 12 deletions, no production code touched.Generator-level timestamp-injection clock races are intentionally out of scope and reserved for a follow-up PR.
Testing
cargo nextest run -p bottlecap metrics::enhanced::lambda::tests: 17 passedcargo nextest run --workspace: 684 passed, 0 failed, 0 skippedcargo fmt --all -- --check: passRUSTFLAGS="-D warnings" cargo clippy --workspace --all-targets --features default: passRUSTFLAGS="-D warnings" cargo clippy --workspace --all-targets --no-default-features --features fips: pass