Skip to content

Commit be55ea8

Browse files
committed
When generating dsd metrics, always attempt to use each context at least once, via round-robin
1 parent 7740f86 commit be55ea8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lading_payload/src/dogstatsd/metric.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) struct MetricGenerator {
2727
pub(crate) sampling: ConfRange<f32>,
2828
pub(crate) sampling_probability: f32,
2929
pub(crate) num_value_generator: NumValueGenerator,
30+
pub(crate) ctx_idx: std::cell::Cell<usize>,
3031
}
3132

3233
impl MetricGenerator {
@@ -86,6 +87,7 @@ impl MetricGenerator {
8687
sampling,
8788
sampling_probability,
8889
num_value_generator: NumValueGenerator::new(value_conf),
90+
ctx_idx: std::cell::Cell::new(0),
8991
})
9092
}
9193
}
@@ -102,8 +104,10 @@ impl<'a> Generator<'a> for MetricGenerator {
102104
// and the program should crash prior to this point.
103105
let template: &Template = self
104106
.templates
105-
.choose(&mut rng)
106-
.expect("failed to choose templates");
107+
.get(self.ctx_idx.get())
108+
.expect("failed to get template");
109+
self.ctx_idx
110+
.set((self.ctx_idx.get() + 1) % self.templates.len());
107111

108112
let container_id = choose_or_not_ref(&mut rng, &self.container_ids).map(String::as_str);
109113
// https://docs.datadoghq.com/metrics/custom_metrics/dogstatsd_metrics_submission/#sample-rates

0 commit comments

Comments
 (0)