Skip to content
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

Start target metrics server on target startup #1097

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lading/src/bin/lading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions lading/src/target_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)),
}
}

Expand Down
10 changes: 5 additions & 5 deletions lading/src/target_metrics/expvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand All @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions lading/src/target_metrics/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -378,22 +378,22 @@ 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,
metrics: None,
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;

Expand Down
Loading