-
Notifications
You must be signed in to change notification settings - Fork 100
ref(statsd): Use statsdproxy to pre-aggregate metrics in-memory #2425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
313b5e2
225900f
740f57f
346f060
ea0acea
eabb3c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
//! ```no_run | ||
//! # use std::collections::BTreeMap; | ||
//! | ||
//! relay_statsd::init("myprefix", "localhost:8125", BTreeMap::new(), true, 1.0); | ||
//! relay_statsd::init("myprefix", "localhost:8125", BTreeMap::new(), true, true, 1.0); | ||
//! ``` | ||
//! | ||
//! ## Macro Usage | ||
|
@@ -66,6 +66,8 @@ use cadence::{ | |
}; | ||
use parking_lot::RwLock; | ||
use rand::distributions::{Distribution, Uniform}; | ||
use statsdproxy::cadence::StatsdProxyMetricSink; | ||
use statsdproxy::config::AggregateMetricsConfig; | ||
|
||
/// Maximum number of metric events that can be queued before we start dropping them | ||
const METRICS_MAX_QUEUE_SIZE: usize = 100_000; | ||
|
@@ -226,6 +228,7 @@ pub fn init<A: ToSocketAddrs>( | |
host: A, | ||
default_tags: BTreeMap<String, String>, | ||
buffering: bool, | ||
aggregating: bool, | ||
sample_rate: f32, | ||
) { | ||
let addrs: Vec<_> = host.to_socket_addrs().unwrap().collect(); | ||
|
@@ -247,7 +250,24 @@ pub fn init<A: ToSocketAddrs>( | |
let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); | ||
socket.set_nonblocking(true).unwrap(); | ||
|
||
let statsd_client = if buffering { | ||
let statsd_client = if aggregating { | ||
let host = host.to_socket_addrs().unwrap().next().unwrap(); | ||
let statsdproxy_sink = StatsdProxyMetricSink::new(move || { | ||
let next_step = statsdproxy::middleware::upstream::Upstream::new(host) | ||
.expect("failed to create statsdproxy metric sink"); | ||
statsdproxy::middleware::aggregate::AggregateMetrics::new( | ||
AggregateMetricsConfig { | ||
aggregate_gauges: true, | ||
aggregate_counters: true, | ||
flush_interval: 1, | ||
flush_offset: 0, | ||
max_map_size: None, | ||
Comment on lines
+262
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be configurable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they should probably not have been options to begin with tbh |
||
}, | ||
next_step, | ||
) | ||
}); | ||
StatsdClient::from_sink(prefix, statsdproxy_sink) | ||
} else if buffering { | ||
let udp_sink = BufferedUdpMetricSink::from(host, socket).unwrap(); | ||
let queuing_sink = QueuingMetricSink::with_capacity(udp_sink, METRICS_MAX_QUEUE_SIZE); | ||
StatsdClient::from_sink(prefix, queuing_sink) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ pub fn init_metrics(config: &Config) -> Result<()> { | |
&addrs[..], | ||
default_tags, | ||
config.metrics_buffering(), | ||
config.metrics_aggregation(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: With this number of arguments, it might be nice to pass a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plan is to get rid of the options all together: #2425 (comment) What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK! |
||
config.metrics_sample_rate(), | ||
); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.