From 4afad487f3a6d065fc9b8baeadb1d055808b6538 Mon Sep 17 00:00:00 2001 From: Caleb Metz Date: Wed, 6 Nov 2024 13:02:38 -0500 Subject: [PATCH] Change target metrics server to wait on target running signal rather than experiment started signal. Signed-off-by: Caleb Metz --- lading/src/bin/lading.rs | 2 +- lading/src/target_metrics.rs | 12 +++++------- lading/src/target_metrics/expvar.rs | 10 +++++----- lading/src/target_metrics/prometheus.rs | 16 ++++++++-------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lading/src/bin/lading.rs b/lading/src/bin/lading.rs index 9b7396b8d..095ea9f35 100644 --- a/lading/src/bin/lading.rs +++ b/lading/src/bin/lading.rs @@ -465,7 +465,7 @@ async fn inner_main( let metrics_server = target_metrics::Server::new( cfg, shutdown_watcher.clone(), - experiment_started_watcher.clone(), + target_running_watcher.clone(), ); tokio::spawn(async { match metrics_server.run().await { diff --git a/lading/src/target_metrics.rs b/lading/src/target_metrics.rs index 711a8afc0..921f9986a 100644 --- a/lading/src/target_metrics.rs +++ b/lading/src/target_metrics.rs @@ -48,17 +48,15 @@ impl Server { pub fn new( config: Config, shutdown: lading_signal::Watcher, - experiment_started: lading_signal::Watcher, + target_running: lading_signal::Watcher, ) -> Self { match config { Config::Expvar(conf) => { - Self::Expvar(expvar::Expvar::new(conf, shutdown, experiment_started)) + Self::Expvar(expvar::Expvar::new(conf, shutdown, target_running)) + } + Config::Prometheus(conf) => { + Self::Prometheus(prometheus::Prometheus::new(conf, shutdown, target_running)) } - Config::Prometheus(conf) => Self::Prometheus(prometheus::Prometheus::new( - conf, - shutdown, - experiment_started, - )), } } diff --git a/lading/src/target_metrics/expvar.rs b/lading/src/target_metrics/expvar.rs index 8006e9da5..07ed61802 100644 --- a/lading/src/target_metrics/expvar.rs +++ b/lading/src/target_metrics/expvar.rs @@ -37,7 +37,7 @@ pub struct Config { pub struct Expvar { config: Config, shutdown: lading_signal::Watcher, - experiment_started: lading_signal::Watcher, + target_running: lading_signal::Watcher, } impl Expvar { @@ -49,12 +49,12 @@ impl Expvar { pub(crate) fn new( config: Config, shutdown: lading_signal::Watcher, - experiment_started: lading_signal::Watcher, + target_running: lading_signal::Watcher, ) -> Self { Self { config, shutdown, - experiment_started, + target_running, } } @@ -70,8 +70,8 @@ impl Expvar { /// /// None are known. pub(crate) async fn run(self) -> Result<(), Error> { - info!("Expvar target metrics scraper running, but waiting for warmup to complete"); - self.experiment_started.recv().await; // block until experimental lading_signal::Watcher entered + info!("Expvar target metrics scraper running, but waiting for target to run"); + self.target_running.recv().await; // block until experimental lading_signal::Watcher entered info!("Expvar target metrics scraper starting collection"); let client = reqwest::Client::new(); diff --git a/lading/src/target_metrics/prometheus.rs b/lading/src/target_metrics/prometheus.rs index a45c12521..07d56c380 100644 --- a/lading/src/target_metrics/prometheus.rs +++ b/lading/src/target_metrics/prometheus.rs @@ -65,7 +65,7 @@ pub struct Prometheus { config: Config, client: reqwest::Client, shutdown: lading_signal::Watcher, - experiment_started: lading_signal::Watcher, + target_running: lading_signal::Watcher, } impl Prometheus { @@ -77,14 +77,14 @@ impl Prometheus { pub(crate) fn new( config: Config, shutdown: lading_signal::Watcher, - experiment_started: lading_signal::Watcher, + target_running: lading_signal::Watcher, ) -> Self { let client = reqwest::Client::new(); Self { config, client, shutdown, - experiment_started, + target_running, } } @@ -103,8 +103,8 @@ impl Prometheus { #[allow(clippy::cast_possible_truncation)] #[allow(clippy::too_many_lines)] pub(crate) async fn run(self) -> Result<(), Error> { - info!("Prometheus target metrics scraper running, but waiting for warmup to complete"); - self.experiment_started.recv().await; + info!("Prometheus target metrics scraper running, but waiting for target to run"); + self.target_running.recv().await; info!("Prometheus target metrics scraper starting collection"); let client = self.client; @@ -378,7 +378,7 @@ mod tests { let server_uri = format!("http://{addr}/metrics"); let (shutdown_watcher, _) = lading_signal::signal(); - let (experiment_started_watcher, experiment_started_broadcaster) = lading_signal::signal(); + let (target_running_watcher, target_running_broadcast) = lading_signal::signal(); let p = Prometheus::new( Config { uri: server_uri, @@ -386,14 +386,14 @@ mod tests { tags, }, shutdown_watcher, - experiment_started_watcher, + target_running_watcher, ); let dr = metrics_util::debugging::DebuggingRecorder::new(); let snapshotter = dr.snapshotter(); dr.install().expect("failed to install recorder"); - experiment_started_broadcaster.signal(); + target_running_broadcast.signal(); p.scrape_metrics().await;