Skip to content

Commit

Permalink
feat(statsd): add config parameter to control metrics aggregation (#4376
Browse files Browse the repository at this point in the history
)

Adds a configuration flat to enable/disable local metric aggregation
through statsdproxy.
  • Loading branch information
Litarnus authored Dec 12, 2024
1 parent efefcca commit 692fbc3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Promote some `span.data` fields to the top level. ([#4298](https://github.com/getsentry/relay/pull/4298))
- Remove metrics summaries. ([#4278](https://github.com/getsentry/relay/pull/4278), [#4279](https://github.com/getsentry/relay/pull/4279), [#4296](https://github.com/getsentry/relay/pull/4296))
- Use async `redis` for `projectconfig`. ([#4284](https://github.com/getsentry/relay/pull/4284))
- Add config parameter to control metrics aggregation. ([#4376](https://github.com/getsentry/relay/pull/4376))

## 24.11.1

Expand Down
10 changes: 10 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ pub struct Metrics {
/// Setting it to `0` seconds disables the periodic metrics.
/// Defaults to 5 seconds.
pub periodic_secs: u64,
/// Whether local metric aggregation using statdsproxy should be enabled.
///
/// Defaults to `true`.
pub aggregate: bool,
}

impl Default for Metrics {
Expand All @@ -557,6 +561,7 @@ impl Default for Metrics {
hostname_tag: None,
sample_rate: 1.0,
periodic_secs: 5,
aggregate: true,
}
}
}
Expand Down Expand Up @@ -2030,6 +2035,11 @@ impl Config {
self.values.metrics.sample_rate
}

/// Returns whether local metric aggregation should be enabled.
pub fn metrics_aggregate(&self) -> bool {
self.values.metrics.aggregate
}

/// Returns the interval for periodic metrics emitted from Relay.
///
/// `None` if periodic metrics are disabled.
Expand Down
11 changes: 9 additions & 2 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(), 1.0);
//! relay_statsd::init("myprefix", "localhost:8125", BTreeMap::new(), 1.0, true);
//! ```
//!
//! ## Macro Usage
Expand Down Expand Up @@ -226,6 +226,7 @@ pub fn init<A: ToSocketAddrs>(
host: A,
default_tags: BTreeMap<String, String>,
sample_rate: f32,
aggregate: bool,
) {
let addrs: Vec<_> = host.to_socket_addrs().unwrap().collect();
if !addrs.is_empty() {
Expand All @@ -243,7 +244,7 @@ pub fn init<A: ToSocketAddrs>(
}
);

let statsd_client = {
let statsd_client = if aggregate {
let statsdproxy_sink = StatsdProxyMetricSink::new(move || {
let upstream = statsdproxy::middleware::upstream::Upstream::new(addrs[0])
.expect("failed to create statsdproxy metric sink");
Expand All @@ -260,6 +261,12 @@ pub fn init<A: ToSocketAddrs>(
)
});

StatsdClient::from_sink(prefix, statsdproxy_sink)
} else {
let statsdproxy_sink = StatsdProxyMetricSink::new(move || {
statsdproxy::middleware::upstream::Upstream::new(addrs[0])
.expect("failed to create statsdproxy metric sind")
});
StatsdClient::from_sink(prefix, statsdproxy_sink)
};

Expand Down
1 change: 1 addition & 0 deletions relay/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn init_metrics(config: &Config) -> Result<()> {
&addrs[..],
default_tags,
config.metrics_sample_rate(),
config.metrics_aggregate(),
);

Ok(())
Expand Down

0 comments on commit 692fbc3

Please sign in to comment.