-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: emit a tag in autoconnect's metrics (#435)
to distinguish its metrics from the legacy version and consolidate autoendpoint's metrics builder w/ autopush_common's SYNC-3893
- Loading branch information
Showing
5 changed files
with
45 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
//! Metrics tie-ins | ||
// TODO: consolidate this with autoendpoint::metrics | ||
|
||
use std::net::UdpSocket; | ||
|
||
use cadence::{BufferedUdpMetricSink, NopMetricSink, QueuingMetricSink, StatsdClient}; | ||
|
||
use crate::errors::Result; | ||
use cadence::{ | ||
BufferedUdpMetricSink, MetricError, NopMetricSink, QueuingMetricSink, StatsdClient, | ||
StatsdClientBuilder, | ||
}; | ||
|
||
/// Create a cadence StatsdClient from the given options | ||
pub fn new_metrics(host: Option<String>, port: u16) -> Result<StatsdClient> { | ||
let builder = if let Some(statsd_host) = host.as_ref() { | ||
/// Create a cadence StatsdClientBuilder from the given options | ||
pub fn builder( | ||
prefix: &str, | ||
host: &Option<String>, | ||
port: u16, | ||
) -> Result<StatsdClientBuilder, MetricError> { | ||
let builder = if let Some(host) = host { | ||
let socket = UdpSocket::bind("0.0.0.0:0")?; | ||
socket.set_nonblocking(true)?; | ||
|
||
let host = (statsd_host.as_str(), port); | ||
let udp_sink = BufferedUdpMetricSink::from(host, socket)?; | ||
let addr = (host.as_str(), port); | ||
let udp_sink = BufferedUdpMetricSink::from(addr, socket)?; | ||
let sink = QueuingMetricSink::from(udp_sink); | ||
StatsdClient::builder("autopush", sink) | ||
StatsdClient::builder(prefix, sink) | ||
} else { | ||
StatsdClient::builder("autopush", NopMetricSink) | ||
StatsdClient::builder(prefix, NopMetricSink) | ||
}; | ||
Ok(builder | ||
.with_error_handler(|err| error!("Metrics send error: {}", err)) | ||
.build()) | ||
Ok(builder.with_error_handler(|err| warn!("⚠️ Metric send error: {:?}", err))) | ||
} |