From 9d8d255474cd77eb60dddbf508fed77a3e8a8a05 Mon Sep 17 00:00:00 2001 From: Martin Beckmann Date: Mon, 23 Oct 2023 15:05:46 +0200 Subject: [PATCH] Log driver response when it comes in (#2009) # Description Currently we first `.join_all()` the driver `/solve` requests and only afterwards issue logs. The metrics correctly measure the time each requests takes but the logs make it look like all drivers respond at the same time which is confusing. # Changes Move logging / metrics into future created for `.join_all()` to issue the logs exactly when each individual `driver` returns their response. # Test Plan compiler --- crates/autopilot/src/run_loop.rs | 44 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/crates/autopilot/src/run_loop.rs b/crates/autopilot/src/run_loop.rs index bb3033d086..75a6582a16 100644 --- a/crates/autopilot/src/run_loop.rs +++ b/crates/autopilot/src/run_loop.rs @@ -318,40 +318,38 @@ impl RunLoop { let start = Instant::now(); futures::future::join_all(self.drivers.iter().map(|driver| async move { let result = self.solve(driver, request).await; - (start.elapsed(), result) - })) - .await - .into_iter() - .zip(&self.drivers) - .fold(Vec::new(), |mut solutions, ((elapsed, result), driver)| { - for solution in match result { + let solutions = match result { Ok(solutions) => { - Metrics::solve_ok(driver, elapsed); + Metrics::solve_ok(driver, start.elapsed()); solutions } Err(err) => { - Metrics::solve_err(driver, elapsed, &err); + Metrics::solve_err(driver, start.elapsed(), &err); if matches!(err, SolveError::NoSolutions) { tracing::debug!(driver = %driver.name, "solver found no solution"); } else { tracing::warn!(?err, driver = %driver.name, "solve error"); } - return solutions; + vec![] } - } { - match solution { - Ok(solution) => { - Metrics::solution_ok(driver); - solutions.push(Participant { driver, solution }) - } - Err(err) => { - Metrics::solution_err(driver, &err); - tracing::debug!(?err, driver = %driver.name, "invalid proposed solution"); - } + }; + + solutions.into_iter().filter_map(|solution| match solution { + Ok(solution) => { + Metrics::solution_ok(driver); + Some(Participant { driver, solution }) } - } - solutions - }) + Err(err) => { + Metrics::solution_err(driver, &err); + tracing::debug!(?err, driver = %driver.name, "invalid proposed solution"); + None + } + }) + })) + .await + .into_iter() + .flatten() + .collect() } /// Computes a driver's solutions for the solver competition.