feat(payload): adopt AtLeastOneHundredth for Config::unique_tag_ratio#1881
feat(payload): adopt AtLeastOneHundredth for Config::unique_tag_ratio#1881goxberry wants to merge 1 commit into
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
PR 5: Adopt
|
177b73a to
af42547
Compare
52e6ac8 to
24aaa41
Compare
af42547 to
123b9cc
Compare
Change the public `Config::unique_tag_ratio` field from `f32` to the
`AtLeastOneHundredth` alias of `BoundedProbability<{ f32::to_bits(0.01) }>`.
The `try_from` impl enforces the finite + `[0.01, 1.0]` invariant at
deserialize time, so the redundant `MIN_UNIQUE_TAG_RATIO..=MAX_UNIQUE_TAG_RATIO`
range check in `common::tags::Generator::new` is removed. The WARN-level
check for values in `[MIN, WARN_UNIQUE_TAG_RATIO]` is preserved.
The new type threads through `MemberGenerator::new`,
`common::tags::Generator::new`, `dogstatsd::common::tags::Generator::new`,
and `opentelemetry::common::TagGenerator::new`. The OTel `UNIQUE_TAG_RATIO`
constant becomes a `const AtLeastOneHundredth` via a `match` on `try_new`.
`MAX_UNIQUE_TAG_RATIO`, no longer referenced outside tests, is now
`#[cfg(test)]`.
At the comparison site in `<common::tags::Generator as Generator>::generate`,
`.get()` extracts the inner `f32` so RNG sequences and bit-exact output are
preserved.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
24aaa41 to
ce4d6c2
Compare
123b9cc to
4e9ba85
Compare

What does this PR do?
Change the public
dogstatsd::Config::unique_tag_ratiofield fromf32tothe
AtLeastOneHundredthalias ofBoundedProbability<{ f32::to_bits(0.01) }>.The
try_fromimpl enforces the finite +[0.01, 1.0]invariant atdeserialize time, so the redundant
MIN_UNIQUE_TAG_RATIO..=MAX_UNIQUE_TAG_RATIOrange check in
common::tags::Generator::newis removed. The WARN-levelcheck for values in
[MIN, WARN_UNIQUE_TAG_RATIO]is preserved.The new type threads through
MemberGenerator::new,common::tags::Generator::new,dogstatsd::common::tags::Generator::new,and
opentelemetry::common::TagGenerator::new. The OTelUNIQUE_TAG_RATIOconstant becomes a
const AtLeastOneHundredthvia amatchontry_new,with
unreachable!()in the Err arm (the bound is provably valid atconst-eval time).
MAX_UNIQUE_TAG_RATIO, no longer referenced outsidetests, is now
#[cfg(test)].At the comparison site in
<common::tags::Generator as Generator>::generate,.get()extracts the innerf32so RNG sequences and bit-exact output arepreserved.
Motivation
Fifth and final per-field PR in Phase 1 of the
BoundedProbabilityrollout.Pushes range validation to deserialize time once and removes the runtime
range check from the tag-generator constructor.
AtLeastOneHundredthischosen over
Probabilityto preserve the existing0.01floor and overAtLeastOneTenthso that in-the-wild configs in[0.01, 0.10)keepdeserializing.
Verification
cargo test -p lading-payload: 250 passed, 0 failed.cargo clippy -p lading-payload --all-targets -- -D warnings: clean.Criterion comparison vs. parent (
goxberry/probability-multivalue-pack-prob)for
cargo bench -p lading-payload --bench dogstatsd:dogstatsd_setupdogstatsd_throughput/1MiBdogstatsd_throughput/10MiBdogstatsd_throughput/100MiBdogstatsd_throughput/1GiB.get()isconst fnreturning a copiedf32, so the IR at the comparisonsite is bit-identical. The 1 MiB regression is most plausibly machine-state
noise (the bench was run right after a CPU-heavy OTel job had warmed the
system); the larger sizes do not reproduce it. OTel benches were skipped
because the OTel hot path is the same
common::tags::Generator::generatealready exercised by dogstatsd, and the OTel call sites only pass
UNIQUE_TAG_RATIOtoTagGenerator::new(init time, not hot path).Related issues
Phase 1 of
.claude/probability-type-rollout-plan.md, building on:BoundedProbability)TimestampConfig::probabilityValueConf::float_probabilityConfig::sampling_probabilityConfig::multivalue_pack_probabilityAdditional Notes
Wire format is unchanged:
BoundedProbabilitycontinues to round-trip as abare
f32viaserde(into = "f32", try_from = "f32"). TheMIN_UNIQUE_TAG_RATIOandWARN_UNIQUE_TAG_RATIOconstants are retainedbecause the WARN-level check still references them.