feat(payload): adopt Probability for Config::sampling_probability#1879
Open
goxberry wants to merge 1 commit into
Open
feat(payload): adopt Probability for Config::sampling_probability#1879goxberry wants to merge 1 commit into
goxberry wants to merge 1 commit into
Conversation
Contributor
Author
|
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. |
|
This was referenced May 21, 2026
391a801 to
742fc08
Compare
0c1423a to
809f4f4
Compare
742fc08 to
03dd039
Compare
809f4f4 to
0797961
Compare
Change the public `Config::sampling_probability` field from `f32` to the
`Probability` alias of `BoundedProbability<{ f32::to_bits(0.0) }>`. The
`try_from` impl enforces the finite + `[0.0, 1.0]` invariant at deserialize
time, so the matching check in `Config::valid` is removed.
The new type threads through `MemberGenerator::new` and `MetricGenerator::new`.
At the comparison site in `<MetricGenerator as Generator>::generate`, `.get()`
extracts the inner `f32` so RNG sequences and bit-exact output are preserved.
03dd039 to
7d6eabc
Compare
0797961 to
8f98d9a
Compare
blt
approved these changes
May 21, 2026
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.

What does this PR do?
Switches
Config::sampling_probability(inlading_payload::dogstatsd) frombare
f32toProbability(BoundedProbability<{ f32::to_bits(0.0) }>from#1876). The
try_fromimpl enforces finite +[0.0, 1.0]at deserializetime, so the matching range/
is_finite()check inConfig::valid()isremoved. The new type threads through
MemberGenerator::newandMetricGenerator::new; at the comparison site in<MetricGenerator as Generator>::generate,.get()extracts the innerf32so RNG draws and bit-exact output are preserved.Motivation
Phase 1, PR 3 of the stacked rollout planned in #1876 — wire
BoundedProbabilityaliases intolading_payloadconfigs one field at atime, smallest blast radius first. After
TimestampConfig::probability(#1877) and
ValueConf::float_probability(#1878),Config::sampling_probabilityis next: it threads through theMemberGenerator::new->MetricGenerator::newconstructor chain indogstatsd.rs/dogstatsd/metric.rs, with one hot-path comparison site.Moving the validation into the type means an invalid
sampling_probabilityis rejected at parse time with a structured errorinstead of inside
Config::valid(); the in-code field can no longer holda value outside
[0.0, 1.0].Related issues
Stacked on #1878 (PR 2:
ValueConf::float_probability), which sits atop#1877 (PR 1) and #1876 (Phase 0). Remaining fields in this rollout:
Config::multivalue_pack_probability(PR 4,Probability) andConfig::unique_tag_ratio(PR 5,AtLeastOneHundredth).Additional Notes
Wire format unchanged.
Probabilityserializes as a baref32viaserde(into = "f32", try_from = "f32"), so YAML/JSON configs writtenfor the previous field type continue to parse.
Public API breakage at the
Configstruct literal. Thesampling_probabilityfield ispub; external callers that constructConfigliterally (rather than viaDefault) must now wrap the valuein
Probability::try_new(...). The in-tree default and all testfixtures use
..Default::default()for this field, so no in-treefixtures need updating.
No sampler swap. The hot-path comparison stays
OpenClosed01.sample(rng) < sampling_probability.get();.get()is aconst fnreturning a copied scalar and inlines away.Default value preserved.
Default for Confignow constructsProbability::try_new(0.5).expect("0.5 is in [0.0, 1.0]")in place ofthe bare
0.5.Verified.
cargo build --workspace,cargo clippy -p lading-payload --all-targets -- -D warnings, andcargo test -p lading-payload --lib(250 pass) all clean.
Bench delta.
cargo bench -p lading-payload --bench dogstatsd --baseline pr2(baseline saved from feat(payload): adopt Probability for ValueConf::float_probability #1878's tip):dogstatsd_setup: −0.19% (p = 0.59, no change)dogstatsd_throughput/1 MiB: −18% point estimate, but CI is[−36%, −3.3%] (p = 0.13, no change — noisy bench at this size)
dogstatsd_throughput/10 MiB: −1.7% (p < 0.05, criterion classifiesas "Change within noise threshold")
dogstatsd_throughput/100 MiB: −0.53% (p = 0.39, no change)dogstatsd_throughput/1 GiB: −0.27% (p = 0.66, no change)The corresponding
--bench blockrun againstpr2shows scattered±2-3% "regressions" on
cache_setupandcache_advanceplus a −9.0%"improvement" on
cache_read_at/1048576, on code that this PR doesnot touch. That sets a wide machine noise floor and confirms the
dogstatsd_throughputdeltas are run-to-run variance, not a realeffect — consistent with the expectation in the rollout plan (".get()
inlines away").