Skip to content

Commit 512e960

Browse files
authored
Merge pull request #2314 from Kobzol/better-error
Improve error reporting in status page and logs
2 parents a4f5ad4 + 0b22dc1 commit 512e960

File tree

3 files changed

+112
-72
lines changed

3 files changed

+112
-72
lines changed

collector/src/bin/collector.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,10 @@ async fn run_benchmark_job(
17221722
Ok(sysroot) => sysroot,
17231723
Err(SysrootDownloadError::SysrootShaNotFound) => {
17241724
return Err(BenchmarkJobError::Permanent(anyhow::anyhow!(
1725-
"Artifacts for SHA {} and target {} were not found on CI servers",
1725+
"Artifacts for SHA `{}`, target `{}` and backend `{}` were not found on CI servers",
17261726
commit.sha,
1727-
job.target().as_str()
1727+
job.target().as_str(),
1728+
job.backend().as_str()
17281729
)))
17291730
}
17301731
Err(SysrootDownloadError::IO(error)) => return Err(error.into()),

site/frontend/src/pages/status/page.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {formatISODate, formatSecondsAsDuration} from "../../utils/formatting";
88
import {useExpandedStore} from "../../utils/expansion";
99
import {
1010
BenchmarkRequest,
11-
BenchmarkRequestStatus,
1211
CollectorConfig,
1312
isJobComplete,
1413
StatusResponse,
@@ -83,7 +82,8 @@ function getDuration(request: BenchmarkRequest): string {
8382
return "";
8483
}
8584
86-
function formatStatus(status: BenchmarkRequestStatus): string {
85+
function formatStatus(request: BenchmarkRequest): string {
86+
const status = request.status;
8787
if (status === "Completed") {
8888
return "Finished";
8989
} else if (status === "InProgress") {
@@ -95,8 +95,8 @@ function formatStatus(status: BenchmarkRequestStatus): string {
9595
}
9696
}
9797
98-
function hasErrors(errors: Dict<string>) {
99-
return Object.keys(errors).length !== 0;
98+
function hasErrors(request: BenchmarkRequest) {
99+
return Object.keys(request.errors).length !== 0;
100100
}
101101
102102
function getErrorsLength(errors: Dict<string>) {
@@ -133,7 +133,11 @@ function RequestProgress({
133133
}, 0);
134134
135135
if (request.status === "Completed") {
136-
return "";
136+
if (hasErrors(request)) {
137+
return "";
138+
} else {
139+
return "";
140+
}
137141
} else if (request.status === "Queued") {
138142
return "";
139143
} else {
@@ -186,7 +190,7 @@ loadStatusData(loading);
186190
<td>{{ req.requestType }}</td>
187191
<td><CommitSha :tag="req.tag"></CommitSha></td>
188192
<td>
189-
{{ formatStatus(req.status)
193+
{{ formatStatus(req)
190194
}}{{
191195
req.status === "Completed" && req.hasPendingJobs ? "*" : ""
192196
}}
@@ -206,7 +210,7 @@ loadStatusData(loading);
206210
</td>
207211

208212
<td>
209-
<template v-if="hasErrors(req.errors)">
213+
<template v-if="hasErrors(req)">
210214
<button @click="toggleExpandedErrors(req.tag)">
211215
{{ getErrorsLength(req.errors) }}
212216
{{ hasExpandedErrors(req.tag) ? "(hide)" : "(show)" }}

site/src/job_queue/mod.rs

Lines changed: 98 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use collector::benchmark_set::benchmark_set_count;
99
use database::pool::{JobEnqueueResult, Transaction};
1010
use database::{
1111
BenchmarkJobKind, BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus,
12-
BenchmarkRequestType, CodegenBackend, Date, PendingBenchmarkRequests, Profile, QueuedCommit,
13-
Target,
12+
BenchmarkRequestType, CodegenBackend, Connection, Date, PendingBenchmarkRequests, Profile,
13+
QueuedCommit, Target,
1414
};
1515
use parking_lot::RwLock;
1616
use std::sync::Arc;
@@ -370,12 +370,12 @@ pub async fn enqueue_benchmark_request(
370370
/// Returns benchmark requests that were completed.
371371
async fn process_benchmark_requests(
372372
conn: &mut dyn database::pool::Connection,
373-
) -> anyhow::Result<Vec<BenchmarkRequest>> {
373+
completed_benchmarks: &mut Vec<BenchmarkRequest>,
374+
) -> anyhow::Result<()> {
374375
let queue = build_queue(conn).await?;
375376

376377
log::debug!("Current queue: {queue:?}");
377378

378-
let mut completed = vec![];
379379
for request in queue {
380380
match request.status() {
381381
BenchmarkRequestStatus::InProgress => {
@@ -386,7 +386,7 @@ async fn process_benchmark_requests(
386386
.context("cannot mark benchmark request as completed")?
387387
{
388388
log::info!("Request {tag} marked as completed");
389-
completed.push(request);
389+
completed_benchmarks.push(request);
390390
continue;
391391
}
392392
break;
@@ -403,7 +403,7 @@ async fn process_benchmark_requests(
403403
}
404404
}
405405
}
406-
Ok(completed)
406+
Ok(())
407407
}
408408

409409
/// Creates new benchmark requests, enqueues jobs for ready benchmark requests and
@@ -432,73 +432,108 @@ async fn perform_queue_tick(ctxt: &SiteCtxt) -> anyhow::Result<()> {
432432
log::error!("Could not insert release benchmark requests into the database: {error:?}");
433433
}
434434
}
435+
436+
let mut completed_benchmarks = vec![];
435437
// Enqueue waiting requests and try to complete in-progress ones
436-
let completed_reqs = process_benchmark_requests(&mut *conn)
438+
let mut result = process_benchmark_requests(&mut *conn, &mut completed_benchmarks)
437439
.await
438-
.context("Failed to process benchmark requests")?;
440+
.context("Failed to process benchmark requests");
441+
442+
// Send a comment to GitHub for completed requests and reload the DB index,
443+
// regardless whether there was an error when processing the requests or not.
444+
if !completed_benchmarks.is_empty() {
445+
result = combine_result(
446+
result,
447+
handle_completed_requests(ctxt, &mut *conn, completed_benchmarks)
448+
.await
449+
.context("Failed to send comparison comment(s)"),
450+
);
451+
}
439452

440453
// If some change happened, reload the benchmark request index
441454
if requests_inserted {
442-
ctxt.known_benchmark_requests.store(Arc::new(
443-
conn.load_benchmark_request_index()
444-
.await
445-
.context("Failed to load benchmark request index")?,
446-
));
455+
match conn
456+
.load_benchmark_request_index()
457+
.await
458+
.context("Failed to load benchmark request index")
459+
{
460+
Ok(index) => {
461+
ctxt.known_benchmark_requests.store(Arc::new(index));
462+
}
463+
Err(error) => {
464+
result = combine_result(result, Err(error));
465+
}
466+
};
467+
}
468+
469+
// Propagate the error
470+
result
471+
}
472+
473+
fn combine_result<T>(a: anyhow::Result<T>, b: anyhow::Result<T>) -> anyhow::Result<T> {
474+
match (a, b) {
475+
(Ok(v), Ok(_)) => Ok(v),
476+
(Err(e), Ok(_)) | (Ok(_), Err(e)) => Err(e),
477+
(Err(e1), Err(e2)) => Err(anyhow::anyhow!("{e2:?}\n\nPreceded by: {e1:?}")),
447478
}
479+
}
448480

449-
// Send a comment to GitHub for completed requests and reload the DB index
450-
if !completed_reqs.is_empty() {
451-
let index = database::Index::load(&mut *conn).await;
452-
log::info!("index has {} commits", index.commits().len());
453-
ctxt.index.store(Arc::new(index));
454-
455-
// Refresh the landing page
456-
ctxt.landing_page.store(Arc::new(None));
457-
458-
// Send comments to GitHub
459-
for request in completed_reqs {
460-
let (is_master, pr, sha, parent_sha) = match request.commit_type() {
461-
BenchmarkRequestType::Try {
462-
pr,
463-
parent_sha,
464-
sha,
465-
} => (
466-
false,
467-
*pr,
468-
sha.clone().expect("Completed try commit without a SHA"),
469-
parent_sha
470-
.clone()
471-
.expect("Completed try commit without a parent SHA"),
472-
),
473-
BenchmarkRequestType::Master {
474-
pr,
475-
sha,
476-
parent_sha,
477-
} => (true, *pr, sha.clone(), parent_sha.clone()),
478-
BenchmarkRequestType::Release { .. } => continue,
479-
};
480-
let commit = QueuedCommit {
481+
/// Reload the main index and send GitHub comments.
482+
async fn handle_completed_requests(
483+
ctxt: &SiteCtxt,
484+
conn: &mut dyn Connection,
485+
completed_benchmarks: Vec<BenchmarkRequest>,
486+
) -> anyhow::Result<()> {
487+
// Reload the index, so that it has the new results
488+
let index = database::Index::load(conn).await;
489+
log::info!("Index has {} commits", index.commits().len());
490+
ctxt.index.store(Arc::new(index));
491+
492+
// Refresh the landing page
493+
ctxt.landing_page.store(Arc::new(None));
494+
495+
// Send comments to GitHub
496+
for request in completed_benchmarks {
497+
let (is_master, pr, sha, parent_sha) = match request.commit_type() {
498+
BenchmarkRequestType::Try {
499+
pr,
500+
parent_sha,
501+
sha,
502+
} => (
503+
false,
504+
*pr,
505+
sha.clone().expect("Completed try commit without a SHA"),
506+
parent_sha
507+
.clone()
508+
.expect("Completed try commit without a parent SHA"),
509+
),
510+
BenchmarkRequestType::Master {
481511
pr,
482512
sha,
483513
parent_sha,
484-
include: None,
485-
exclude: None,
486-
runs: None,
487-
commit_date: request.commit_date().map(Date),
488-
backends: Some(
489-
request
490-
.backends()?
491-
.into_iter()
492-
.map(|b| b.as_str())
493-
.collect::<Vec<_>>()
494-
.join(","),
495-
),
496-
};
497-
log::debug!("Posting comparison comment to {pr}");
498-
post_comparison_comment(ctxt, commit, is_master).await?;
499-
}
514+
} => (true, *pr, sha.clone(), parent_sha.clone()),
515+
BenchmarkRequestType::Release { .. } => continue,
516+
};
517+
let commit = QueuedCommit {
518+
pr,
519+
sha,
520+
parent_sha,
521+
include: None,
522+
exclude: None,
523+
runs: None,
524+
commit_date: request.commit_date().map(Date),
525+
backends: Some(
526+
request
527+
.backends()?
528+
.into_iter()
529+
.map(|b| b.as_str())
530+
.collect::<Vec<_>>()
531+
.join(","),
532+
),
533+
};
534+
log::debug!("Posting comparison comment to {pr}");
535+
post_comparison_comment(ctxt, commit, is_master).await?;
500536
}
501-
502537
Ok(())
503538
}
504539

@@ -743,7 +778,7 @@ mod tests {
743778
ctx.complete_request("bar").await;
744779
ctx.insert_master_request("foo", "bar", 1).await;
745780

746-
process_benchmark_requests(ctx.db_mut()).await?;
781+
process_benchmark_requests(ctx.db_mut(), &mut vec![]).await?;
747782
let jobs = ctx
748783
.db()
749784
.get_jobs_of_in_progress_benchmark_requests()

0 commit comments

Comments
 (0)