Skip to content

Commit

Permalink
Log driver response when it comes in (#2009)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
MartinquaXD authored Oct 23, 2023
1 parent 7e6cbcc commit 9d8d255
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9d8d255

Please sign in to comment.