Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lading_payload/src/dogstatsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ pub struct Config {
/// Number of tags per individual dogstatsd msg a tag is a key-value pair
/// separated by a :
pub tags_per_msg: ConfRange<u8>,
/// Probability between 0 and 1 that a given dogstatsd msg
/// contains multiple values
pub multivalue_pack_probability: f32,
/// Probability that a given dogstatsd msg contains multiple values
pub multivalue_pack_probability: Probability,
/// The count of values that will be generated if multi-value is chosen to
/// be generated
pub multivalue_count: ConfRange<u16>,
Expand Down Expand Up @@ -271,7 +270,7 @@ impl Default for Config {
tag_length: ConfRange::Inclusive { min: 3, max: 100 },
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]"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

sampling_range: ConfRange::Inclusive { min: 0.1, max: 1.0 },
sampling_probability: Probability::try_new(0.5).expect("0.5 is in [0.0, 1.0]"),
kind_weights: KindWeights::default(),
Expand Down Expand Up @@ -420,7 +419,7 @@ impl MemberGenerator {
tag_length: ConfRange<u16>,
tags_per_msg: ConfRange<u8>,
multivalue_count: ConfRange<u16>,
multivalue_pack_probability: f32,
multivalue_pack_probability: Probability,
sampling: ConfRange<f32>,
sampling_probability: Probability,
kind_weights: KindWeights,
Expand Down
6 changes: 3 additions & 3 deletions lading_payload/src/dogstatsd/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) struct MetricGenerator {
pub(crate) timestamp_probability: Probability,
pub(crate) templates: Vec<template::Template>,
pub(crate) multivalue_count: ConfRange<u16>,
pub(crate) multivalue_pack_probability: f32,
pub(crate) multivalue_pack_probability: Probability,
pub(crate) sampling: ConfRange<f32>,
pub(crate) sampling_probability: Probability,
pub(crate) num_value_generator: NumValueGenerator,
Expand All @@ -50,7 +50,7 @@ impl MetricGenerator {
num_contexts: usize,
name_length: ConfRange<u16>,
multivalue_count: ConfRange<u16>,
multivalue_pack_probability: f32,
multivalue_pack_probability: Probability,
sampling: ConfRange<f32>,
sampling_probability: Probability,
metric_weights: &WeightedIndex<u16>,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a> Generator<'a> for MetricGenerator {
values.push(value);

let prob: f32 = OpenClosed01.sample(&mut rng);
if prob < self.multivalue_pack_probability {
if prob < self.multivalue_pack_probability.get() {
let num_desired_values = self.multivalue_count.sample(&mut rng) as usize;
for _ in 1..num_desired_values {
values.push(self.num_value_generator.generate(&mut rng)?);
Expand Down
Loading