feat(payload): adopt Probability for Config::multivalue_pack_probability#1880
feat(payload): adopt Probability for Config::multivalue_pack_probability#1880goxberry 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 4 plan: adopt
|
391a801 to
742fc08
Compare
ff156a8 to
52e6ac8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52e6ac86e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| tags_per_msg: ConfRange::Inclusive { min: 2, max: 50 }, | ||
| multivalue_count: ConfRange::Inclusive { min: 2, max: 32 }, | ||
| multivalue_pack_probability: 0.08, | ||
| multivalue_pack_probability: Probability::try_new(0.08).expect("0.08 is in [0.0, 1.0]"), |
There was a problem hiding this comment.
Replace the new expect in Config::default
This new .expect() violates the repository error-handling rule in /workspace/lading/AGENTS.md, which says No .unwrap() or .expect() and that production code must not panic. Even though 0.08 is currently valid, Config::default() is normal construction code, so keep this path panic-free by using an infallible constant/helper or otherwise avoiding .expect().
Useful? React with 👍 / 👎.
52e6ac8 to
24aaa41
Compare
742fc08 to
03dd039
Compare
Change the public `Config::multivalue_pack_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. `Config::valid` did not previously validate this field, so no check 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.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
24aaa41 to
ce4d6c2
Compare
03dd039 to
7d6eabc
Compare

What does this PR do?
Switches
Config::multivalue_pack_probability(inlading_payload::dogstatsd) from baref32toProbability(
BoundedProbability<{ f32::to_bits(0.0) }>from #1876). Thetry_fromimpl enforces finite +
[0.0, 1.0]at deserialize time.Config::valid()did not previously validate this field, so no check is removed — the new
type adds parse-time validation that did not exist before. The new type
threads through
MemberGenerator::newandMetricGenerator::new; at thehot-path comparison site in
<MetricGenerator as Generator>::generate,.get()extracts the innerf32so RNG draws and bit-exact output arepreserved.
Motivation
Phase 1, PR 4 of the stacked rollout planned in #1876 — wire
BoundedProbabilityaliases intolading_payloadconfigs one field at atime, smallest blast radius first. After
TimestampConfig::probability(#1877),
ValueConf::float_probability(#1878), andConfig::sampling_probability(#1879),Config::multivalue_pack_probabilityis next: it threads through the same
MemberGenerator::new->MetricGenerator::newconstructor chain indogstatsd.rs/dogstatsd/metric.rs, with one hot-path comparison site.Moving the validation into the type means an invalid
multivalue_pack_probabilityis rejected at parse time with a structurederror; the in-code field can no longer hold a value outside
[0.0, 1.0].Previously this field had no validation at all in
Config::valid(), so aNaN or out-of-range value would have been accepted silently and reached
the
OpenClosed01.sample(rng) < pcomparison.Related issues
Stacked on #1879 (PR 3:
Config::sampling_probability), which sits atop#1878 (PR 2), #1877 (PR 1), and #1876 (Phase 0). One field remains in this
rollout:
Config::unique_tag_ratio(PR 5,AtLeastOneHundredth).Additional Notes
Probabilityserializes as a baref32viaserde(into = "f32", try_from = "f32"), so YAML/JSON configs writtenfor the previous field type continue to parse.
Configstruct literal. Themultivalue_pack_probabilityfield ispub; external callers thatconstruct
Configliterally (rather than viaDefault) must now wrapthe value in
Probability::try_new(...). The in-tree default and alltest fixtures use
..Default::default()for this field, so no in-treefixtures need updating.
OpenClosed01.sample(rng) < multivalue_pack_probability.get();.get()is a
const fnreturning a copied scalar and inlines away.Default for Confignow constructsProbability::try_new(0.08).expect("0.08 is in [0.0, 1.0]")in placeof the bare
0.08.cargo check --workspace --all-targets,cargo clippy -p lading-payload --all-targets -- -D warnings,cargo fmt --all -- --check, andcargo test -p lading-payload --lib --tests(250 pass)all clean.
cargo bench -p lading-payload --bench dogstatsd(and--bench block) should be run against thefeat(payload): adopt Probability for Config::sampling_probability #1879 tip; deltas are expected to be machine noise since
.get()inlines away. Benches pending in a follow-up commit on this branch.