From c61dbfb90ef2531838f991beebcd6394c76d780e Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 21 Feb 2024 14:06:10 +0100 Subject: [PATCH] Experimentally hook up `statsdproxy` --- Cargo.lock | 58 ++++++++++++++++++++-- crates/symbolicator-service/Cargo.toml | 3 +- crates/symbolicator-service/src/metrics.rs | 25 +++++++--- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02d07091c..14df65d47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,9 +854,9 @@ checksum = "d7bba2f68a9fefca870fed897de7c655f9d5c1eaf1cd9517db96c9a3861f648b" [[package]] name = "cadence" -version = "1.1.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51923ae2126911a3456e05ddf421ece6380a214722bffa0ef15c5912d8fe8761" +checksum = "f39286bc075b023101dccdb79456a1334221c768b8faede0c2aff7ed29a9482d" dependencies = [ "crossbeam-channel", ] @@ -1120,7 +1120,7 @@ dependencies = [ "libc", "mio 0.7.14", "parking_lot 0.11.2", - "signal-hook", + "signal-hook 0.1.17", "winapi", ] @@ -1395,6 +1395,19 @@ dependencies = [ "syn 2.0.49", ] +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -3870,6 +3883,16 @@ dependencies = [ "signal-hook-registry", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -4032,6 +4055,25 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "statsdproxy" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793ec303cef342e5a80e717016050673430851d5e3159ba8275c0f801cc83c11" +dependencies = [ + "anyhow", + "cadence", + "clap", + "crc32fast", + "env_logger", + "log", + "rand", + "serde", + "serde_yaml", + "signal-hook 0.3.17", + "thread_local", +] + [[package]] name = "string_cache" version = "0.8.7" @@ -4511,6 +4553,7 @@ dependencies = [ "serde_yaml", "sha-1", "sha2", + "statsdproxy", "symbolic", "symbolicator-sources", "symbolicator-test", @@ -4727,6 +4770,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "test-assembler" version = "0.1.6" diff --git a/crates/symbolicator-service/Cargo.toml b/crates/symbolicator-service/Cargo.toml index d2b24c759..45ca69c35 100644 --- a/crates/symbolicator-service/Cargo.toml +++ b/crates/symbolicator-service/Cargo.toml @@ -14,7 +14,7 @@ aws-config = { version = "1.0.1", features = ["behavior-version-latest"] } aws-credential-types = { version = "1.0.1", features = ["hardcoded-credentials"] } aws-sdk-s3 = "1.4.0" aws-types = "1.0.1" -cadence = "1.0.0" +cadence = "0.29.0" chrono = { version = "0.4.19", features = ["serde"] } filetime = "0.2.16" flate2 = "1.0.23" @@ -34,6 +34,7 @@ serde = { version = "1.0.137", features = ["derive", "rc"] } serde_json = "1.0.81" serde_yaml = "0.9.14" sha2 = "0.10.6" +statsdproxy = { version = "0.1.2", features = ["cadence-adapter"] } symbolic = { version = "12.7.1", features = ["cfi", "common-serde", "debuginfo", "symcache"] } symbolicator-sources = { path = "../symbolicator-sources" } tempfile = "3.2.0" diff --git a/crates/symbolicator-service/src/metrics.rs b/crates/symbolicator-service/src/metrics.rs index 70e651db5..052bec992 100644 --- a/crates/symbolicator-service/src/metrics.rs +++ b/crates/symbolicator-service/src/metrics.rs @@ -3,7 +3,11 @@ use std::collections::BTreeMap; use std::net::ToSocketAddrs; use std::sync::OnceLock; -use cadence::{BufferedUdpMetricSink, QueuingMetricSink, StatsdClient}; +use cadence::StatsdClient; +use statsdproxy::cadence::StatsdProxyMetricSink; +use statsdproxy::config::AggregateMetricsConfig; +use statsdproxy::middleware::aggregate::AggregateMetrics; +use statsdproxy::middleware::upstream::Upstream; static METRICS_CLIENT: OnceLock = OnceLock::new(); @@ -18,11 +22,20 @@ pub fn configure_statsd(prefix: &str, host: A, tags: BTreeMap< if !addrs.is_empty() { tracing::info!("Reporting metrics to statsd at {}", addrs[0]); } - let socket = std::net::UdpSocket::bind("0.0.0.0:0").unwrap(); - socket.set_nonblocking(true).unwrap(); - let udp_sink = BufferedUdpMetricSink::from(&addrs[..], socket).unwrap(); - let queuing_sink = QueuingMetricSink::from(udp_sink); - let mut builder = StatsdClient::builder(prefix, queuing_sink); + let aggregator_sink = StatsdProxyMetricSink::new(move || { + let next_step = Upstream::new(&addrs[..]).unwrap(); + + let config = AggregateMetricsConfig { + aggregate_counters: true, + aggregate_gauges: true, + flush_offset: 0, + flush_interval: 5, + max_map_size: None, + }; + AggregateMetrics::new(config, next_step) + }); + + let mut builder = StatsdClient::builder(prefix, aggregator_sink); for (key, value) in tags { builder = builder.with_tag(key, value) }