From a71f7924c66f0c13435673c15923e725d6dbad8a Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Tue, 21 Nov 2023 11:22:18 -0500 Subject: [PATCH 1/2] Adds constructors for metric and kind weights --- lading_payload/src/dogstatsd.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lading_payload/src/dogstatsd.rs b/lading_payload/src/dogstatsd.rs index 1deb424dc..d374d0e9a 100644 --- a/lading_payload/src/dogstatsd.rs +++ b/lading_payload/src/dogstatsd.rs @@ -91,6 +91,17 @@ pub struct KindWeights { service_check: u8, } +impl KindWeights { + /// Create a new instance of `KindWeights` according to the args + pub fn new(metric: u8, event: u8, service_check: u8) -> Self { + Self { + metric, + event, + service_check, + } + } +} + impl Default for KindWeights { fn default() -> Self { KindWeights { @@ -115,6 +126,20 @@ pub struct MetricWeights { histogram: u8, } +impl MetricWeights { + /// Create a new instance of `MetricWeights` according to the args + pub fn new(count: u8, gauge: u8, timer: u8, distribution: u8, set: u8, histogram: u8) -> Self { + Self { + count, + gauge, + timer, + distribution, + set, + histogram, + } + } +} + impl Default for MetricWeights { fn default() -> Self { MetricWeights { From 535cf10605fe5efb7b078fc35bfb509e9eb24842 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Tue, 21 Nov 2023 11:43:34 -0500 Subject: [PATCH 2/2] Re-adds generate --- lading_payload/src/dogstatsd.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lading_payload/src/dogstatsd.rs b/lading_payload/src/dogstatsd.rs index d374d0e9a..2f2ff676f 100644 --- a/lading_payload/src/dogstatsd.rs +++ b/lading_payload/src/dogstatsd.rs @@ -569,6 +569,16 @@ impl DogStatsD { .unwrap() } + /// Generate a single `Member`. + /// Prefer using the Serialize implementation for `DogStatsD` which + /// generates a stream of `Member`s according to some constraints. + pub fn generate(&self, rng: &mut R) -> Member + where + R: rand::Rng + ?Sized, + { + self.member_generator.generate(rng) + } + /// Create a new instance of `DogStatsD`. /// /// # Errors