Skip to content

Commit f78ebf6

Browse files
committed
Enqueue master commits in pr_queue
1 parent 3ef307e commit f78ebf6

File tree

3 files changed

+130
-87
lines changed

3 files changed

+130
-87
lines changed

site/src/github.rs

Lines changed: 83 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::comparison::{ComparisonSummary, Direction};
33
use crate::load::{Config, SiteCtxt, TryCommit};
44

55
use anyhow::Context as _;
6-
use database::ArtifactId;
6+
use database::{ArtifactId, QueuedCommit};
77
use hashbrown::HashSet;
88
use reqwest::header::USER_AGENT;
99
use serde::{Deserialize, Serialize};
@@ -509,92 +509,117 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
509509
}
510510
let conn = ctxt.conn().await;
511511
let index = ctxt.index.load();
512-
let mut commits = index
512+
let mut already_tested_commits = index
513513
.commits()
514514
.into_iter()
515515
.map(|c| c.sha.to_string())
516516
.collect::<HashSet<_>>();
517-
let queued = conn.queued_commits().await;
517+
let (master_commits, queued_pr_commits, in_progress_artifacts) = futures::join!(
518+
collector::master_commits(),
519+
conn.queued_commits(),
520+
conn.in_progress_artifacts()
521+
);
522+
let master_commits = master_commits
523+
.unwrap()
524+
.into_iter()
525+
.map(|c| c.sha)
526+
.collect::<HashSet<_>>();
518527

519-
for aid in conn.in_progress_artifacts().await {
528+
for aid in in_progress_artifacts {
520529
match aid {
521530
ArtifactId::Commit(c) => {
522-
commits.remove(&c.sha);
531+
already_tested_commits.remove(&c.sha);
523532
}
524533
ArtifactId::Tag(_) => {
525-
// do nothing, for now, though eventually we'll want an artifact
526-
// queue
534+
// do nothing, for now, though eventually we'll want an artifact queue
527535
}
528536
}
529537
}
530-
for commit in queued {
531-
if !commits.contains(&commit.sha) {
532-
continue;
533-
}
534-
535-
// This commit has been benchmarked.
536-
538+
for commit in queued_pr_commits
539+
.into_iter()
540+
.filter(|c| already_tested_commits.contains(&c.sha))
541+
{
537542
if let Some(completed) = conn.mark_complete(&commit.sha).await {
538543
assert_eq!(completed, commit);
539544

540-
let comparison_url = format!(
541-
"https://perf.rust-lang.org/compare.html?start={}&end={}",
542-
commit.parent_sha, commit.sha
543-
);
544-
let (summary, direction) = categorize_benchmark(&commit, ctxt).await;
545-
let label = match direction {
546-
Some(Direction::Regression | Direction::Mixed) => "+perf-regression",
547-
Some(Direction::Improvement) | None => "-perf-regression",
548-
};
549-
let msg = direction
550-
.map(|d| {
551-
format!(
552-
"While you can manually mark this PR as fit \
545+
let is_master_commit = master_commits.contains(&commit.sha);
546+
post_comparison_comment(commit, ctxt, is_master_commit).await;
547+
}
548+
}
549+
}
550+
551+
async fn post_comparison_comment(commit: QueuedCommit, ctxt: &SiteCtxt, is_master_commit: bool) {
552+
let comparison_url = format!(
553+
"https://perf.rust-lang.org/compare.html?start={}&end={}",
554+
commit.parent_sha, commit.sha
555+
);
556+
let (summary, direction) =
557+
categorize_benchmark(commit.sha.clone(), commit.parent_sha, ctxt).await;
558+
let label = match direction {
559+
Some(Direction::Regression | Direction::Mixed) => "+perf-regression",
560+
Some(Direction::Improvement) | None => "-perf-regression",
561+
};
562+
let next_steps_msg = direction
563+
.map(|d| {
564+
format!(
565+
"{}{}",
566+
if is_master_commit {
567+
""
568+
} else {
569+
"While you can manually mark this PR as fit \
553570
for rollup, we strongly recommend not doing so since this PR led to changes in \
554-
compiler perf.{}",
555-
match d {
556-
Direction::Regression | Direction::Mixed =>
557-
"\n\n**Next Steps**: If you can justify the \
571+
compiler perf."
572+
},
573+
match d {
574+
Direction::Regression | Direction::Mixed =>
575+
"\n\n**Next Steps**: If you can justify the \
558576
regressions found in this perf run, please indicate this with \
559577
`@rustbot label: +perf-regression-triaged` along with \
560578
sufficient written justification. If you cannot justify the regressions \
561-
please fix the regressions and do another perf run. If the next run shows \
562-
neutral or positive results, the label will be automatically removed.",
563-
Direction::Improvement => "",
564-
}
565-
)
566-
})
567-
.unwrap_or(String::new());
568-
569-
post_comment(
570-
&ctxt.config,
571-
commit.pr,
572-
format!(
573-
"Finished benchmarking try commit ({}): [comparison url]({}).
579+
please fix the regressions (either in this PR if it's not yet merged or \
580+
in another PR) and do another perf run.",
581+
Direction::Improvement => "",
582+
}
583+
)
584+
})
585+
.unwrap_or(String::new());
586+
let rollup_msg = if is_master_commit {
587+
""
588+
} else {
589+
"Benchmarking this pull request likely means that it is \
590+
perf-sensitive, so we're automatically marking it as not fit \
591+
for rolling up. "
592+
};
593+
let bors_msg = if is_master_commit {
594+
""
595+
} else {
596+
"@bors rollup=never\n"
597+
};
598+
post_comment(
599+
&ctxt.config,
600+
commit.pr,
601+
format!(
602+
"Finished benchmarking commit ({}): [comparison url]({}).
574603
575604
**Summary**: {}
576605
577-
Benchmarking this pull request likely means that it is \
578-
perf-sensitive, so we're automatically marking it as not fit \
579-
for rolling up. {}
580-
581-
@bors rollup=never
606+
{}{}
607+
{}
582608
@rustbot label: +S-waiting-on-review -S-waiting-on-perf {}",
583-
commit.sha, comparison_url, summary, msg, label
584-
),
585-
)
586-
.await;
587-
}
588-
}
609+
commit.sha, comparison_url, summary, rollup_msg, next_steps_msg, bors_msg, label
610+
),
611+
)
612+
.await;
589613
}
590614

591615
async fn categorize_benchmark(
592-
commit: &database::QueuedCommit,
616+
commit_sha: String,
617+
parent_sha: String,
593618
ctxt: &SiteCtxt,
594619
) -> (String, Option<Direction>) {
595620
let comparison = match crate::comparison::compare(
596-
collector::Bound::Commit(commit.parent_sha.clone()),
597-
collector::Bound::Commit(commit.sha.clone()),
621+
collector::Bound::Commit(parent_sha),
622+
collector::Bound::Commit(commit_sha),
598623
"instructions:u".to_owned(),
599624
ctxt,
600625
)

site/src/load.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum MissingReason {
2323
/// This commmit has not yet been benchmarked
2424
Master {
2525
pr: u32,
26+
parent_sha: String,
2627
},
2728
TryParent,
2829
Try {
@@ -34,6 +35,16 @@ pub enum MissingReason {
3435
InProgress(Option<Box<MissingReason>>),
3536
}
3637

38+
impl MissingReason {
39+
/// If the commit is a master commit get its PR and parent_sha
40+
pub fn master_commit_pr_and_parent(&self) -> Option<(u32, &str)> {
41+
match self {
42+
Self::Master { pr, parent_sha } => Some((*pr, parent_sha)),
43+
_ => None,
44+
}
45+
}
46+
}
47+
3748
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
3849
pub struct TryCommit {
3950
pub sha: String,
@@ -177,6 +188,7 @@ impl SiteCtxt {
177188
// All recent master commits should have an associated PR
178189
MissingReason::Master {
179190
pr: c.pr.unwrap_or(0),
191+
parent_sha: c.parent_sha,
180192
},
181193
)
182194
})

site/src/request_handlers/next_commit.rs

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,47 @@ use collector::api::next_commit;
44
use std::sync::Arc;
55

66
pub async fn handle_next_commit(ctxt: Arc<SiteCtxt>) -> next_commit::Response {
7-
let commit = ctxt
8-
.missing_commits()
9-
.await
10-
.into_iter()
11-
.next()
12-
.map(|(commit, missing_reason)| {
13-
let (include, exclude, runs) = match missing_reason {
14-
crate::load::MissingReason::Try {
7+
let commit = ctxt.missing_commits().await.into_iter().next();
8+
9+
let commit = if let Some((commit, missing_reason)) = commit {
10+
// If we're going to run a master commit next, make sure
11+
// it's been enqueued in the pull_request_build table
12+
if let Some((pr, parent_sha)) = missing_reason.master_commit_pr_and_parent() {
13+
let conn = ctxt.conn().await;
14+
conn.queue_pr(pr, None, None, None).await;
15+
conn.pr_attach_commit(pr, &commit.sha, parent_sha).await;
16+
}
17+
let (include, exclude, runs) = match missing_reason {
18+
crate::load::MissingReason::Try {
19+
include,
20+
exclude,
21+
runs,
22+
..
23+
} => (include, exclude, runs),
24+
crate::load::MissingReason::InProgress(Some(previous)) => {
25+
if let crate::load::MissingReason::Try {
1526
include,
1627
exclude,
1728
runs,
1829
..
19-
} => (include, exclude, runs),
20-
crate::load::MissingReason::InProgress(Some(previous)) => {
21-
if let crate::load::MissingReason::Try {
22-
include,
23-
exclude,
24-
runs,
25-
..
26-
} = *previous
27-
{
28-
(include, exclude, runs)
29-
} else {
30-
(None, None, None)
31-
}
30+
} = *previous
31+
{
32+
(include, exclude, runs)
33+
} else {
34+
(None, None, None)
3235
}
33-
_ => (None, None, None),
34-
};
35-
next_commit::Commit {
36-
sha: commit.sha,
37-
include,
38-
exclude,
39-
runs,
4036
}
41-
});
37+
_ => (None, None, None),
38+
};
39+
Some(next_commit::Commit {
40+
sha: commit.sha,
41+
include,
42+
exclude,
43+
runs,
44+
})
45+
} else {
46+
None
47+
};
4248

4349
next_commit::Response { commit }
4450
}

0 commit comments

Comments
 (0)