From 2cdc77c69dd21753fe89b14cd5ef39a1be4cb644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81owicki?= Date: Wed, 24 Apr 2024 15:01:28 +0200 Subject: [PATCH] Expose more things for more advanced sink impl cases --- cadence/src/ext.rs | 2 ++ cadence/src/io.rs | 6 +++--- cadence/src/sinks/core.rs | 12 ++++++------ cadence/src/sinks/mod.rs | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cadence/src/ext.rs b/cadence/src/ext.rs index 0989d67..b9a4d17 100644 --- a/cadence/src/ext.rs +++ b/cadence/src/ext.rs @@ -33,3 +33,5 @@ pub use crate::client::{ MetricBackend, ToCounterValue, ToDistributionValue, ToGaugeValue, ToHistogramValue, ToMeterValue, ToSetValue, ToTimerValue, }; +pub use crate::io::MultiLineWriter; +pub use crate::sinks::core::SocketStats; diff --git a/cadence/src/io.rs b/cadence/src/io.rs index a97f2c1..ee23369 100644 --- a/cadence/src/io.rs +++ b/cadence/src/io.rs @@ -24,7 +24,7 @@ struct WriterMetrics { /// writes the complete input in a single call to the underlying /// writer. #[derive(Debug)] -pub(crate) struct MultiLineWriter +pub struct MultiLineWriter where T: Write, { @@ -41,13 +41,13 @@ where { /// Create a new buffered `MultiLineWriter` instance that suffixes /// each write with a newline character ('\n'). - pub(crate) fn new(inner: T, cap: usize) -> MultiLineWriter { + pub fn new(inner: T, cap: usize) -> MultiLineWriter { Self::with_ending(inner, cap, "\n") } /// Create a new buffered `MultiLineWriter` instance that suffixes /// each write with the given line ending. - pub(crate) fn with_ending(inner: T, cap: usize, end: &str) -> MultiLineWriter { + pub fn with_ending(inner: T, cap: usize, end: &str) -> MultiLineWriter { MultiLineWriter { written: 0, capacity: cap, diff --git a/cadence/src/sinks/core.rs b/cadence/src/sinks/core.rs index a73e953..986f4c8 100644 --- a/cadence/src/sinks/core.rs +++ b/cadence/src/sinks/core.rs @@ -21,7 +21,7 @@ pub struct SinkStats { } #[derive(Debug, Clone, Default)] -pub(crate) struct SocketStats { +pub struct SocketStats { bytes_sent: Arc, packets_sent: Arc, bytes_dropped: Arc, @@ -29,23 +29,23 @@ pub(crate) struct SocketStats { } impl SocketStats { - pub(crate) fn incr_bytes_sent(&self, n: u64) { + pub fn incr_bytes_sent(&self, n: u64) { self.bytes_sent.fetch_add(n, Ordering::Relaxed); } - pub(crate) fn incr_packets_sent(&self) { + pub fn incr_packets_sent(&self) { self.packets_sent.fetch_add(1, Ordering::Relaxed); } - pub(crate) fn incr_bytes_dropped(&self, n: u64) { + pub fn incr_bytes_dropped(&self, n: u64) { self.bytes_dropped.fetch_add(n, Ordering::Relaxed); } - pub(crate) fn incr_packets_dropped(&self) { + pub fn incr_packets_dropped(&self) { self.packets_dropped.fetch_add(1, Ordering::Relaxed); } - pub(crate) fn update(&self, res: io::Result, len: usize) -> io::Result { + pub fn update(&self, res: io::Result, len: usize) -> io::Result { match res { Ok(written) => { self.incr_bytes_sent(written as u64); diff --git a/cadence/src/sinks/mod.rs b/cadence/src/sinks/mod.rs index 9b97087..5f2aefa 100644 --- a/cadence/src/sinks/mod.rs +++ b/cadence/src/sinks/mod.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -mod core; +pub mod core; mod queuing; mod spy; mod udp;