Skip to content

Commit 0adf914

Browse files
committed
Periodically check latest git SHA in collector and exit if it's not up-to-date
1 parent 216dcfa commit 0adf914

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

collector/src/bin/collector.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,11 @@ enum Commands {
713713
#[arg(long)]
714714
git_sha: Option<String>,
715715

716+
/// Periodically check if the collector's commit SHA matches the commit SHA of the
717+
/// rustc-perf repository.
718+
#[arg(long)]
719+
check_git_sha: bool,
720+
716721
#[command(flatten)]
717722
db: DbOption,
718723
},
@@ -1360,6 +1365,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13601365
Commands::BenchmarkJobQueue {
13611366
collector_name,
13621367
git_sha,
1368+
check_git_sha,
13631369
db,
13641370
} => {
13651371
log_db(&db);
@@ -1395,6 +1401,13 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13951401
));
13961402
}
13971403

1404+
log::info!(
1405+
"Starting collector with target {}, benchmark set {} and commit {}",
1406+
collector_config.target(),
1407+
collector_config.benchmark_set().get_id(),
1408+
collector_config.commit_sha().expect("missing commit SHA")
1409+
);
1410+
13981411
let benchmarks =
13991412
get_compile_benchmarks(&compile_benchmark_dir, CompileBenchmarkFilter::All)?;
14001413

@@ -1403,6 +1416,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
14031416
conn,
14041417
&collector_config,
14051418
benchmarks,
1419+
check_git_sha,
14061420
))?;
14071421

14081422
Ok(0)
@@ -1418,8 +1432,10 @@ async fn run_job_queue_benchmarks(
14181432
mut conn: Box<dyn Connection>,
14191433
collector: &CollectorConfig,
14201434
all_compile_benchmarks: Vec<Benchmark>,
1435+
check_git_sha: bool,
14211436
) -> anyhow::Result<()> {
1422-
// TODO: check collector SHA vs site SHA
1437+
let mut last_request_tag = None;
1438+
14231439
while let Some((benchmark_job, artifact_id)) = conn
14241440
.dequeue_benchmark_job(
14251441
collector.name(),
@@ -1428,6 +1444,23 @@ async fn run_job_queue_benchmarks(
14281444
)
14291445
.await?
14301446
{
1447+
// Here we check if we should update our commit SHA, if rustc-perf has been updated.
1448+
// We only check for updates when we switch *benchmark requests*, not *benchmark jobs*,
1449+
// to avoid changing code in the middle of benchmarking the same request.
1450+
// Note that if an update happens, the job that we have just dequeued will have its deque
1451+
// counter increased. But since updates are relatively rare, that shouldn't be a big deal,
1452+
// it will be dequeued again when the collector starts again.
1453+
if check_git_sha
1454+
&& last_request_tag.is_some()
1455+
&& last_request_tag.as_deref() != Some(benchmark_job.request_tag())
1456+
{
1457+
if needs_git_update(collector) {
1458+
log::warn!("Exiting collector to update itself from git.");
1459+
return Ok(());
1460+
}
1461+
}
1462+
last_request_tag = Some(benchmark_job.request_tag().to_string());
1463+
14311464
log::info!("Dequeued job {benchmark_job:?}, artifact_id {artifact_id:?}");
14321465
let result = run_benchmark_job(
14331466
conn.as_mut(),
@@ -1491,6 +1524,40 @@ async fn run_job_queue_benchmarks(
14911524
Ok(())
14921525
}
14931526

1527+
/// Returns true if the commit SHA of collector does not match the latest commit SHA of the master
1528+
/// branch of https://github.com/rust-lang/rustc-perf.
1529+
fn needs_git_update(collector: &CollectorConfig) -> bool {
1530+
let Some(commit_sha) = collector.commit_sha() else {
1531+
return false;
1532+
};
1533+
1534+
let mut cmd = Command::new("git");
1535+
cmd.arg("ls-remote")
1536+
.arg("https://github.com/rust-lang/rustc-perf")
1537+
.arg("HEAD");
1538+
let upstream_sha = match command_output(&mut cmd) {
1539+
Ok(output) => String::from_utf8(output.stdout)
1540+
.unwrap()
1541+
.trim()
1542+
.split_whitespace()
1543+
.next()
1544+
.unwrap()
1545+
.to_string(),
1546+
Err(error) => {
1547+
log::error!("Cannot determine latest SHA of rustc-perf: {error:?}");
1548+
return false;
1549+
}
1550+
};
1551+
if commit_sha != upstream_sha {
1552+
log::warn!(
1553+
"Commit {commit_sha} of collector is outdated, latest commit is {upstream_sha}."
1554+
);
1555+
true
1556+
} else {
1557+
false
1558+
}
1559+
}
1560+
14941561
/// Error that happened during benchmarking of a job.
14951562
enum BenchmarkJobError {
14961563
/// The error is non-recoverable.

0 commit comments

Comments
 (0)