Skip to content

Commit dfffe9a

Browse files
authored
Merge pull request #992 from rylev/comment-merged-commits
Leave perf result comment on PRs after the post-merge perf run is completed
2 parents 08677aa + b2383e9 commit dfffe9a

File tree

3 files changed

+335
-171
lines changed

3 files changed

+335
-171
lines changed

site/src/github.rs

+100-62
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};
@@ -501,6 +501,8 @@ pub struct PostComment {
501501
pub body: String,
502502
}
503503

504+
/// Post messages to GitHub for all queued commits that have
505+
/// not yet been marked as completed.
504506
pub async fn post_finished(ctxt: &SiteCtxt) {
505507
// If the github token is not configured, do not run this -- we don't want
506508
// to mark things as complete without posting the comment.
@@ -509,92 +511,128 @@ pub async fn post_finished(ctxt: &SiteCtxt) {
509511
}
510512
let conn = ctxt.conn().await;
511513
let index = ctxt.index.load();
512-
let mut commits = index
514+
let mut known_commits = index
513515
.commits()
514516
.into_iter()
515517
.map(|c| c.sha.to_string())
516518
.collect::<HashSet<_>>();
517-
let queued = conn.queued_commits().await;
519+
let (master_commits, queued_pr_commits, in_progress_artifacts) = futures::join!(
520+
collector::master_commits(),
521+
conn.queued_commits(),
522+
conn.in_progress_artifacts()
523+
);
524+
let master_commits = if let Ok(mcs) = master_commits {
525+
mcs.into_iter().map(|c| c.sha).collect::<HashSet<_>>()
526+
} else {
527+
// If we can't fetch master commits, return.
528+
// We'll eventually try again later
529+
return;
530+
};
518531

519-
for aid in conn.in_progress_artifacts().await {
532+
for aid in in_progress_artifacts {
520533
match aid {
521534
ArtifactId::Commit(c) => {
522-
commits.remove(&c.sha);
535+
known_commits.remove(&c.sha);
523536
}
524537
ArtifactId::Tag(_) => {
525-
// do nothing, for now, though eventually we'll want an artifact
526-
// queue
538+
// do nothing, for now, though eventually we'll want an artifact queue
527539
}
528540
}
529541
}
530-
for commit in queued {
531-
if !commits.contains(&commit.sha) {
532-
continue;
533-
}
534-
535-
// This commit has been benchmarked.
542+
for queued_commit in queued_pr_commits
543+
.into_iter()
544+
.filter(|c| known_commits.contains(&c.sha))
545+
{
546+
if let Some(completed) = conn.mark_complete(&queued_commit.sha).await {
547+
assert_eq!(completed, queued_commit);
536548

537-
if let Some(completed) = conn.mark_complete(&commit.sha).await {
538-
assert_eq!(completed, commit);
549+
let is_master_commit = master_commits.contains(&queued_commit.sha);
550+
post_comparison_comment(ctxt, queued_commit, is_master_commit).await;
551+
}
552+
}
553+
}
539554

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 \
555+
/// Posts a comment to GitHub summarizing the comparison of the queued commit with its parent
556+
///
557+
/// `is_master_commit` is used to differentiate messages for try runs and post-merge runs.
558+
async fn post_comparison_comment(ctxt: &SiteCtxt, commit: QueuedCommit, is_master_commit: bool) {
559+
let comparison_url = format!(
560+
"https://perf.rust-lang.org/compare.html?start={}&end={}",
561+
commit.parent_sha, commit.sha
562+
);
563+
let (summary, direction) =
564+
categorize_benchmark(commit.sha.clone(), commit.parent_sha, ctxt).await;
565+
let label = match direction {
566+
Some(Direction::Regression | Direction::Mixed) => "+perf-regression",
567+
Some(Direction::Improvement) | None => "-perf-regression",
568+
};
569+
let rollup_msg = if is_master_commit {
570+
""
571+
} else {
572+
"Benchmarking this pull request likely means that it is \
573+
perf-sensitive, so we're automatically marking it as not fit \
574+
for rolling up. "
575+
};
576+
let next_steps_msg = direction
577+
.map(|d| {
578+
format!(
579+
"{}{}",
580+
if is_master_commit {
581+
""
582+
} else {
583+
"While you can manually mark this PR as fit \
553584
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 \
585+
compiler perf."
586+
},
587+
match d {
588+
Direction::Regression | Direction::Mixed =>
589+
"\n\n**Next Steps**: If you can justify the \
558590
regressions found in this perf run, please indicate this with \
559591
`@rustbot label: +perf-regression-triaged` along with \
560592
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]({}).
574-
575-
**Summary**: {}
576-
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
582-
@rustbot label: +S-waiting-on-review -S-waiting-on-perf {}",
583-
commit.sha, comparison_url, summary, msg, label
584-
),
593+
please fix the regressions (either in this PR if it's not yet merged or \
594+
in another PR), and then add the `perf-regression-triaged` label to this PR.",
595+
Direction::Improvement => "",
596+
}
585597
)
586-
.await;
587-
}
588-
}
598+
})
599+
.unwrap_or(String::new());
600+
let bors_msg = if is_master_commit {
601+
""
602+
} else {
603+
"@bors rollup=never\n"
604+
};
605+
post_comment(
606+
&ctxt.config,
607+
commit.pr,
608+
format!(
609+
"Finished benchmarking commit ({sha}): [comparison url]({url}).
610+
611+
**Summary**: {summary}
612+
613+
{rollup}{next_steps}
614+
{bors}
615+
@rustbot label: +S-waiting-on-review -S-waiting-on-perf {label}",
616+
sha = commit.sha,
617+
url = comparison_url,
618+
summary = summary,
619+
rollup = rollup_msg,
620+
next_steps = next_steps_msg,
621+
bors = bors_msg,
622+
label = label
623+
),
624+
)
625+
.await;
589626
}
590627

591628
async fn categorize_benchmark(
592-
commit: &database::QueuedCommit,
629+
commit_sha: String,
630+
parent_sha: String,
593631
ctxt: &SiteCtxt,
594632
) -> (String, Option<Direction>) {
595633
let comparison = match crate::comparison::compare(
596-
collector::Bound::Commit(commit.parent_sha.clone()),
597-
collector::Bound::Commit(commit.sha.clone()),
634+
collector::Bound::Commit(parent_sha),
635+
collector::Bound::Commit(commit_sha),
598636
"instructions:u".to_owned(),
599637
ctxt,
600638
)

0 commit comments

Comments
 (0)