Skip to content

Commit

Permalink
ref(statsd): Remove buffering/aggregation config options (#3184)
Browse files Browse the repository at this point in the history
As discussed in #2425, removes the options, there is no reason not to
buffer and not to aggregate/use statsdproxy.

Also cleans up the configuration a bit.
  • Loading branch information
Dav1dde authored Feb 29, 2024
1 parent 388560e commit f0f7246
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
20 changes: 0 additions & 20 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,6 @@ struct Metrics {
default_tags: BTreeMap<String, String>,
/// Tag name to report the hostname to for each metric. Defaults to not sending such a tag.
hostname_tag: Option<String>,
/// Emitted metrics will be buffered to optimize performance.
///
/// Defaults to `true`.
buffering: bool,
/// Emitted metrics will be aggregated to optimize bandwidth.
///
/// Defaults to `true`.
aggregation: bool,
/// Global sample rate for all emitted metrics between `0.0` and `1.0`.
///
/// For example, a value of `0.3` means that only 30% of the emitted metrics will be sent.
Expand All @@ -515,8 +507,6 @@ impl Default for Metrics {
prefix: "sentry.relay".into(),
default_tags: BTreeMap::new(),
hostname_tag: None,
buffering: true,
aggregation: true,
sample_rate: 1.0,
}
}
Expand Down Expand Up @@ -1857,16 +1847,6 @@ impl Config {
self.values.metrics.hostname_tag.as_deref()
}

/// Returns true if metrics buffering is enabled, false otherwise.
pub fn metrics_buffering(&self) -> bool {
self.values.metrics.buffering
}

/// Returns true if metrics aggregation is enabled, false otherwise.
pub fn metrics_aggregation(&self) -> bool {
self.values.metrics.aggregation
}

/// Returns the global sample rate for all metrics.
pub fn metrics_sample_rate(&self) -> f32 {
self.values.metrics.sample_rate
Expand Down
33 changes: 8 additions & 25 deletions relay-statsd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//! ```no_run
//! # use std::collections::BTreeMap;
//!
//! relay_statsd::init("myprefix", "localhost:8125", BTreeMap::new(), true, true, 1.0);
//! relay_statsd::init("myprefix", "localhost:8125", BTreeMap::new(), 1.0);
//! ```
//!
//! ## Macro Usage
Expand Down Expand Up @@ -57,13 +57,11 @@
//!
//! [Metric Types]: https://github.com/statsd/statsd/blob/master/docs/metric_types.md
use std::collections::BTreeMap;
use std::net::{ToSocketAddrs, UdpSocket};
use std::net::ToSocketAddrs;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;

use cadence::{
BufferedUdpMetricSink, Metric, MetricBuilder, QueuingMetricSink, StatsdClient, UdpMetricSink,
};
use cadence::{Metric, MetricBuilder, StatsdClient};
use parking_lot::RwLock;
use rand::distributions::{Distribution, Uniform};
use statsdproxy::cadence::StatsdProxyMetricSink;
Expand Down Expand Up @@ -227,8 +225,6 @@ pub fn init<A: ToSocketAddrs>(
prefix: &str,
host: A,
default_tags: BTreeMap<String, String>,
buffering: bool,
aggregating: bool,
sample_rate: f32,
) {
let addrs: Vec<_> = host.to_socket_addrs().unwrap().collect();
Expand All @@ -247,14 +243,11 @@ pub fn init<A: ToSocketAddrs>(
}
);

let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.set_nonblocking(true).unwrap();

let statsd_client = if aggregating {
let host = host.to_socket_addrs().unwrap().next().unwrap();
let statsd_client = {
let statsdproxy_sink = StatsdProxyMetricSink::new(move || {
let next_step = statsdproxy::middleware::upstream::Upstream::new(host)
let upstream = statsdproxy::middleware::upstream::Upstream::new(addrs[0])
.expect("failed to create statsdproxy metric sink");

statsdproxy::middleware::aggregate::AggregateMetrics::new(
AggregateMetricsConfig {
aggregate_gauges: true,
Expand All @@ -263,22 +256,12 @@ pub fn init<A: ToSocketAddrs>(
flush_offset: 0,
max_map_size: None,
},
next_step,
upstream,
)
});

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)
} else {
let simple_sink = UdpMetricSink::from(host, socket).unwrap();
StatsdClient::from_sink(prefix, simple_sink)
};
relay_log::debug!(
"metrics buffering is {}",
if buffering { "enabled" } else { "disabled" }
);

set_client(MetricsClient {
statsd_client,
Expand Down
2 changes: 0 additions & 2 deletions relay/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ pub fn init_metrics(config: &Config) -> Result<()> {
config.metrics_prefix(),
&addrs[..],
default_tags,
config.metrics_buffering(),
config.metrics_aggregation(),
config.metrics_sample_rate(),
);

Expand Down

0 comments on commit f0f7246

Please # to comment.