Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Dec 13, 2023
1 parent 3f608a9 commit fb7d14a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@
use cadence::{CountedExt, Gauged, QueuingMetricSink, StatsdClient, UdpMetricSink};
#[cfg(feature = "statsd")]
use std::sync::atomic::{AtomicU64, Ordering};
use std::{fmt, io};

#[cfg(feature = "statsd")]
/// Queue with a maximum capacity of 8K events.
/// This program is extremely unlikely to ever reach that upper bound.
/// The bound is still here so that if it ever were to happen, we drop events
/// instead of indefinitely filling the memory with unsent events.
const QUEUE_SIZE: usize = 8 * 1024;

#[cfg(feature = "statsd")]
const PREFIX: &str = "tcp2udp";

#[cfg(feature = "statsd")]
#[derive(Debug)]
pub enum Error {
/// Failed to create + bind the statsd UDP socket.
BindUdpSocket(io::Error),
BindUdpSocket(std::io::Error),
/// Failed to create statsd client.
CreateStatsdClient(cadence::MetricError),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "statsd")]
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {
BindUdpSocket(_) => "Failed to bind the UDP socket".fmt(f),
Expand All @@ -30,6 +33,7 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "statsd")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use Error::*;
Expand Down
3 changes: 3 additions & 0 deletions src/tcp2udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum Tcp2UdpError {
BindTcpSocket(io::Error, SocketAddr),
/// Failed to start listening on TCP socket
ListenTcpSocket(io::Error, SocketAddr),
#[cfg(feature = "statsd")]
/// Failed to initialize statsd client
CreateStatsdClient(statsd::Error),
}
Expand All @@ -69,6 +70,7 @@ impl fmt::Display for Tcp2UdpError {
"Failed to start listening on TCP socket bound to {}",
addr
),
#[cfg(feature = "statsd")]
CreateStatsdClient(_) => "Failed to init metrics client".fmt(f),
}
}
Expand All @@ -84,6 +86,7 @@ impl std::error::Error for Tcp2UdpError {
SetReuseAddr(e) => Some(e),
BindTcpSocket(e, _) => Some(e),
ListenTcpSocket(e, _) => Some(e),
#[cfg(feature = "statsd")]
CreateStatsdClient(e) => Some(e),
}
}
Expand Down

0 comments on commit fb7d14a

Please sign in to comment.