Skip to content

feat(payload): adopt Probability for Config::sampling_probability#1879

Open
goxberry wants to merge 1 commit into
goxberry/probability-value-conf-floatfrom
goxberry/probability-sampling-prob
Open

feat(payload): adopt Probability for Config::sampling_probability#1879
goxberry wants to merge 1 commit into
goxberry/probability-value-conf-floatfrom
goxberry/probability-sampling-prob

Conversation

@goxberry
Copy link
Copy Markdown
Contributor

@goxberry goxberry commented May 21, 2026

What does this PR do?

Switches Config::sampling_probability (in lading_payload::dogstatsd) from
bare f32 to Probability (BoundedProbability<{ f32::to_bits(0.0) }> from
#1876). The try_from impl enforces finite + [0.0, 1.0] at deserialize
time, so the matching range/is_finite() 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 draws and bit-exact output are preserved.

Motivation

Phase 1, PR 3 of the stacked rollout planned in #1876 — wire
BoundedProbability aliases into lading_payload configs one field at a
time, smallest blast radius first. After TimestampConfig::probability
(#1877) and ValueConf::float_probability (#1878),
Config::sampling_probability is next: it threads through the
MemberGenerator::new -> MetricGenerator::new constructor chain in
dogstatsd.rs / dogstatsd/metric.rs, with one hot-path comparison site.

Moving the validation into the type means an invalid
sampling_probability is rejected at parse time with a structured error
instead of inside Config::valid(); the in-code field can no longer hold
a 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) and
Config::unique_tag_ratio (PR 5, AtLeastOneHundredth).

Additional Notes

  • Wire format unchanged. Probability serializes as a bare f32 via
    serde(into = "f32", try_from = "f32"), so YAML/JSON configs written
    for the previous field type continue to parse.

  • Public API breakage at the Config struct literal. The
    sampling_probability field is pub; external callers that construct
    Config literally (rather than via Default) must now wrap the value
    in Probability::try_new(...). The in-tree default and all test
    fixtures use ..Default::default() for this field, so no in-tree
    fixtures need updating.

  • No sampler swap. The hot-path comparison stays
    OpenClosed01.sample(rng) < sampling_probability.get(); .get() is a
    const fn returning a copied scalar and inlines away.

  • Default value preserved. Default for Config now constructs
    Probability::try_new(0.5).expect("0.5 is in [0.0, 1.0]") in place of
    the bare 0.5.

  • Verified. cargo build --workspace, cargo clippy -p lading-payload --all-targets -- -D warnings, and cargo 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 classifies
      as "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 block run against pr2 shows scattered
    ±2-3% "regressions" on cache_setup and cache_advance plus a −9.0%
    "improvement" on cache_read_at/1048576, on code that this PR does
    not touch. That sets a wide machine noise floor and confirms the
    dogstatsd_throughput deltas are run-to-run variance, not a real
    effect — consistent with the expectation in the rollout plan (".get()
    inlines away").

Copy link
Copy Markdown
Contributor Author

goxberry commented May 21, 2026

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 Bot commented May 21, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

Changelog Check | changelog-check   View in Datadog   GitHub Actions

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. No changes to CHANGELOG.md detected. Add 'no-changelog' label if this is intentional.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7d6eabc | Docs | Datadog PR Page | Give us feedback!

@goxberry goxberry marked this pull request as ready for review May 21, 2026 02:44
@goxberry goxberry requested a review from a team as a code owner May 21, 2026 02:45
@goxberry goxberry force-pushed the goxberry/probability-sampling-prob branch from 391a801 to 742fc08 Compare May 21, 2026 05:44
@goxberry goxberry force-pushed the goxberry/probability-value-conf-float branch from 0c1423a to 809f4f4 Compare May 21, 2026 05:44
@goxberry goxberry force-pushed the goxberry/probability-sampling-prob branch from 742fc08 to 03dd039 Compare May 21, 2026 06:34
@goxberry goxberry force-pushed the goxberry/probability-value-conf-float branch from 809f4f4 to 0797961 Compare May 21, 2026 06:34
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.
@goxberry goxberry force-pushed the goxberry/probability-sampling-prob branch from 03dd039 to 7d6eabc Compare May 21, 2026 06:47
@goxberry goxberry force-pushed the goxberry/probability-value-conf-float branch from 0797961 to 8f98d9a Compare May 21, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants