Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Sep 19, 2023
1 parent ef635bb commit 50733b7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.18.1-rc6]
### Changed
- The configuration option `float_weight` is changed to `float_probability`.

## [0.18.1-rc5]
### Changed
- Capitalization is renamed to snake-case in value configuration.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lading/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lading"
version = "0.18.1-rc5"
version = "0.18.1-rc6"
authors = ["Brian L. Troutwine <brian.troutwine@datadoghq.com>", "George Hahn <george.hahn@datadoghq.com"]
edition = "2021"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions lading_payload/src/dogstatsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn contexts_maximum() -> u16 {

fn value_config() -> ValueConf {
ValueConf {
float_weight: 128, // 50%
float_probability: 0.5, // 50%
range: ValueRange::Inclusive {
min: i64::MIN,
max: i64::MAX,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Default for MetricWeights {
#[derive(Debug, Deserialize, Clone, PartialEq, Copy)]
pub struct ValueConf {
/// Odds out of 256 that the value will be a float and not an integer.
float_weight: u8,
float_probability: f32,
range: ValueRange,
}

Expand Down
19 changes: 10 additions & 9 deletions lading_payload/src/dogstatsd/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use rand::{
distributions::{Standard, Uniform},
distributions::{OpenClosed01, Standard, Uniform},
prelude::Distribution,
Rng,
};
Expand All @@ -21,12 +21,12 @@ pub(crate) enum NumValue {
#[derive(Clone, Debug)]
pub(crate) enum NumValueGenerator {
Constant {
float_weight: u8,
float_probability: f32,
int: i64,
float: f64,
},
Uniform {
float_weight: u8,
float_probability: f32,
int_distr: Uniform<i64>,
float_distr: Uniform<f64>,
},
Expand All @@ -37,12 +37,12 @@ impl NumValueGenerator {
pub(crate) fn new(conf: ValueConf) -> Self {
match conf.range {
ValueRange::Constant(c) => Self::Constant {
float_weight: conf.float_weight,
float_probability: conf.float_probability,
int: c,
float: c as f64,
},
ValueRange::Inclusive { min, max } => Self::Uniform {
float_weight: conf.float_weight,
float_probability: conf.float_probability,
int_distr: Uniform::new_inclusive(min, max),
float_distr: Uniform::new_inclusive(min as f64, max as f64),
},
Expand All @@ -57,24 +57,25 @@ impl<'a> Generator<'a> for NumValueGenerator {
where
R: rand::Rng + ?Sized,
{
let prob: f32 = OpenClosed01.sample(rng);
match self {
Self::Constant {
float_weight,
float_probability,
int,
float,
} => {
if rng.gen_ratio(u32::from(*float_weight), 256) {
if prob < *float_probability {
NumValue::Float(*float)
} else {
NumValue::Int(*int)
}
}
Self::Uniform {
float_weight,
float_probability,
int_distr,
float_distr,
} => {
if rng.gen_ratio(u32::from(*float_weight), 256) {
if prob < *float_probability {
NumValue::Float(float_distr.sample(rng))
} else {
NumValue::Int(int_distr.sample(rng))
Expand Down

0 comments on commit 50733b7

Please sign in to comment.