Skip to content

Commit

Permalink
Expose more things for more advanced sink impl cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mlowicki committed Apr 24, 2024
1 parent 1d966c8 commit 2cdc77c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cadence/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions cadence/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct WriterMetrics {
/// writes the complete input in a single call to the underlying
/// writer.
#[derive(Debug)]
pub(crate) struct MultiLineWriter<T>
pub struct MultiLineWriter<T>
where
T: Write,
{
Expand All @@ -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<T> {
pub fn new(inner: T, cap: usize) -> MultiLineWriter<T> {
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<T> {
pub fn with_ending(inner: T, cap: usize, end: &str) -> MultiLineWriter<T> {
MultiLineWriter {
written: 0,
capacity: cap,
Expand Down
12 changes: 6 additions & 6 deletions cadence/src/sinks/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ pub struct SinkStats {
}

#[derive(Debug, Clone, Default)]
pub(crate) struct SocketStats {
pub struct SocketStats {
bytes_sent: Arc<AtomicU64>,
packets_sent: Arc<AtomicU64>,
bytes_dropped: Arc<AtomicU64>,
packets_dropped: Arc<AtomicU64>,
}

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<usize>, len: usize) -> io::Result<usize> {
pub fn update(&self, res: io::Result<usize>, len: usize) -> io::Result<usize> {
match res {
Ok(written) => {
self.incr_bytes_sent(written as u64);
Expand Down
2 changes: 1 addition & 1 deletion cadence/src/sinks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2cdc77c

Please sign in to comment.