Skip to content

Commit

Permalink
Merge pull request #22 from mozilla-services/feat/3
Browse files Browse the repository at this point in the history
feat: setup a cadence error handler
  • Loading branch information
bbangert authored Jun 29, 2018
2 parents a881c38 + 26bb908 commit c258545
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ use server::ServerOptions;

/// Create a cadence StatsdClient from the given options
pub fn metrics_from_opts(opts: &ServerOptions) -> Result<StatsdClient> {
Ok(if let Some(statsd_host) = opts.statsd_host.as_ref() {
let builder = if let Some(statsd_host) = opts.statsd_host.as_ref() {
let socket = UdpSocket::bind("0.0.0.0:0")?;
socket.set_nonblocking(true)?;

let host = (statsd_host.as_str(), opts.statsd_port);
let udp_sink = BufferedUdpMetricSink::from(host, socket)?;
let sink = QueuingMetricSink::from(udp_sink);
StatsdClient::from_sink("autopush", sink)
StatsdClient::builder("autopush", sink)
} else {
StatsdClient::from_sink("autopush", NopMetricSink)
})
StatsdClient::builder("autopush", NopMetricSink)
};
Ok(builder
.with_error_handler(|err| error!("Metrics send error: {}", err))
.build())
}

0 comments on commit c258545

Please sign in to comment.