Skip to content

Commit 962cbe6

Browse files
committed
Store commit_date in benchmark_request
We need it to fill the `artifact` table.
1 parent 1de2935 commit 962cbe6

File tree

8 files changed

+77
-78
lines changed

8 files changed

+77
-78
lines changed

database/schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ Columns:
284284
* **parent_sha** (`text`): Parent SHA of the benchmarked commit.
285285
* Can be `NULL` for try requests without compiler artifacts.
286286
* **commit_type** (`text NOT NULL`): One of `master`, `try` or `release`.
287+
* **commit_date** (`timestamptz`): Datetime when the compiler artifact commit (not the request) was created.
288+
* Can be `NULL` for try requests without compiler artifacts.
287289
* **pr** (`int`): Pull request number associated with the master/try commit.
288290
* `NULL` for release requests.
289291
* **created_at** (`timestamptz NOT NULL`): Datetime when the request was created.

database/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ impl fmt::Display for BenchmarkRequestType {
889889
#[derive(Debug, Clone, PartialEq)]
890890
pub struct BenchmarkRequest {
891891
commit_type: BenchmarkRequestType,
892+
// When was the compiler artifact created
893+
commit_date: Option<DateTime<Utc>>,
892894
created_at: DateTime<Utc>,
893895
status: BenchmarkRequestStatus,
894896
backends: String,
@@ -897,47 +899,45 @@ pub struct BenchmarkRequest {
897899

898900
impl BenchmarkRequest {
899901
/// Create a release benchmark request that is in the `ArtifactsReady` status.
900-
pub fn create_release(tag: &str, created_at: DateTime<Utc>) -> Self {
902+
pub fn create_release(tag: &str, commit_date: DateTime<Utc>) -> Self {
901903
Self {
902904
commit_type: BenchmarkRequestType::Release {
903905
tag: tag.to_string(),
904906
},
905-
created_at,
907+
commit_date: Some(commit_date),
908+
created_at: Utc::now(),
906909
status: BenchmarkRequestStatus::ArtifactsReady,
907910
backends: String::new(),
908911
profiles: String::new(),
909912
}
910913
}
911914

912915
/// Create a try request that is in the `WaitingForArtifacts` status.
913-
pub fn create_try_without_artifacts(
914-
pr: u32,
915-
created_at: DateTime<Utc>,
916-
backends: &str,
917-
profiles: &str,
918-
) -> Self {
916+
pub fn create_try_without_artifacts(pr: u32, backends: &str, profiles: &str) -> Self {
919917
Self {
920918
commit_type: BenchmarkRequestType::Try {
921919
pr,
922920
sha: None,
923921
parent_sha: None,
924922
},
925-
created_at,
923+
commit_date: None,
924+
created_at: Utc::now(),
926925
status: BenchmarkRequestStatus::WaitingForArtifacts,
927926
backends: backends.to_string(),
928927
profiles: profiles.to_string(),
929928
}
930929
}
931930

932931
/// Create a master benchmark request that is in the `ArtifactsReady` status.
933-
pub fn create_master(sha: &str, parent_sha: &str, pr: u32, created_at: DateTime<Utc>) -> Self {
932+
pub fn create_master(sha: &str, parent_sha: &str, pr: u32, commit_date: DateTime<Utc>) -> Self {
934933
Self {
935934
commit_type: BenchmarkRequestType::Master {
936935
pr,
937936
sha: sha.to_string(),
938937
parent_sha: parent_sha.to_string(),
939938
},
940-
created_at,
939+
commit_date: Some(commit_date),
940+
created_at: Utc::now(),
941941
status: BenchmarkRequestStatus::ArtifactsReady,
942942
backends: String::new(),
943943
profiles: String::new(),

database/src/pool.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub trait Connection: Send + Sync {
211211
pr: u32,
212212
sha: &str,
213213
parent_sha: &str,
214+
commit_date: DateTime<Utc>,
214215
) -> anyhow::Result<()>;
215216

216217
/// Add a benchmark job to the job queue.
@@ -543,12 +544,12 @@ mod tests {
543544
// Complete
544545
let req_a = BenchmarkRequest::create_try_without_artifacts(42, Utc::now(), "", "");
545546
// WaitingForArtifacts
546-
let req_b = BenchmarkRequest::create_try_without_artifacts(42, Utc::now(), "", "");
547-
let req_c = BenchmarkRequest::create_try_without_artifacts(42, Utc::now(), "", "");
547+
let req_b = BenchmarkRequest::create_try_without_artifacts(42, "", "");
548+
let req_c = BenchmarkRequest::create_try_without_artifacts(42, "", "");
548549

549550
db.insert_benchmark_request(&parent).await.unwrap();
550551
db.insert_benchmark_request(&req_a).await.unwrap();
551-
db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1")
552+
db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now())
552553
.await
553554
.unwrap();
554555

@@ -615,7 +616,7 @@ mod tests {
615616
// ArtifactsReady
616617
let req_b = BenchmarkRequest::create_release("1.80.0", time);
617618
// WaitingForArtifacts
618-
let req_c = BenchmarkRequest::create_try_without_artifacts(50, time, "", "");
619+
let req_c = BenchmarkRequest::create_try_without_artifacts(50, "", "");
619620
// InProgress
620621
let req_d = BenchmarkRequest::create_master("sha-2", "parent-sha-2", 51, time);
621622
// Completed
@@ -649,10 +650,10 @@ mod tests {
649650
let db = ctx.db_client();
650651
let db = db.connection().await;
651652

652-
let req = BenchmarkRequest::create_try_without_artifacts(42, Utc::now(), "", "");
653+
let req = BenchmarkRequest::create_try_without_artifacts(42, "", "");
653654

654655
db.insert_benchmark_request(&req).await.unwrap();
655-
db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1")
656+
db.attach_shas_to_try_benchmark_request(42, "sha1", "sha-parent-1", Utc::now())
656657
.await
657658
.unwrap();
658659

database/src/pool/postgres.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ static MIGRATIONS: &[&str] = &[
378378
ALTER TABLE job_queue DROP COLUMN IF EXISTS collector_id;
379379
CREATE INDEX IF NOT EXISTS job_queue_status_target_benchmark_set_idx ON job_queue (status, target, benchmark_set);
380380
"#,
381+
r#"
382+
ALTER TABLE benchmark_request ADD COLUMN commit_date TIMESTAMPTZ NULL;
383+
"#,
381384
];
382385

383386
#[async_trait::async_trait]
@@ -1485,9 +1488,10 @@ where
14851488
status,
14861489
created_at,
14871490
backends,
1488-
profiles
1491+
profiles,
1492+
commit_date
14891493
)
1490-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8);
1494+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
14911495
"#,
14921496
&[
14931497
&benchmark_request.tag(),
@@ -1498,6 +1502,7 @@ where
14981502
&benchmark_request.created_at,
14991503
&benchmark_request.backends,
15001504
&benchmark_request.profiles,
1505+
&benchmark_request.commit_date,
15011506
],
15021507
)
15031508
.await
@@ -1563,6 +1568,7 @@ where
15631568
pr: u32,
15641569
sha: &str,
15651570
parent_sha: &str,
1571+
commit_date: DateTime<Utc>,
15661572
) -> anyhow::Result<()> {
15671573
self.conn()
15681574
.execute(
@@ -1571,7 +1577,8 @@ where
15711577
SET
15721578
tag = $1,
15731579
parent_sha = $2,
1574-
status = $3
1580+
status = $3,
1581+
commit_date = $6
15751582
WHERE
15761583
pr = $4
15771584
AND commit_type = 'try'
@@ -1583,6 +1590,7 @@ where
15831590
&BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR,
15841591
&(pr as i32),
15851592
&BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR,
1593+
&commit_date,
15861594
],
15871595
)
15881596
.await
@@ -1603,7 +1611,8 @@ where
16031611
created_at,
16041612
completed_at,
16051613
backends,
1606-
profiles
1614+
profiles,
1615+
commit_date
16071616
FROM benchmark_request
16081617
WHERE status IN('{BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR}', '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}')"#
16091618
);
@@ -1626,6 +1635,7 @@ where
16261635
let completed_at = row.get::<_, Option<DateTime<Utc>>>(6);
16271636
let backends = row.get::<_, String>(7);
16281637
let profiles = row.get::<_, String>(8);
1638+
let commit_date = row.get::<_, Option<DateTime<Utc>>>(9);
16291639

16301640
let pr = pr.map(|v| v as u32);
16311641

@@ -1640,6 +1650,7 @@ where
16401650
parent_sha,
16411651
pr: pr.expect("Try commit in the DB without a PR"),
16421652
},
1653+
commit_date,
16431654
created_at,
16441655
status,
16451656
backends,
@@ -1652,6 +1663,7 @@ where
16521663
.expect("Master commit in the DB without a parent SHA"),
16531664
pr: pr.expect("Master commit in the DB without a PR"),
16541665
},
1666+
commit_date,
16551667
created_at,
16561668
status,
16571669
backends,
@@ -1661,6 +1673,7 @@ where
16611673
commit_type: BenchmarkRequestType::Release {
16621674
tag: tag.expect("Release commit in the DB without a SHA"),
16631675
},
1676+
commit_date,
16641677
created_at,
16651678
status,
16661679
backends,

database/src/pool/sqlite.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ impl Connection for SqliteConnection {
12891289
_pr: u32,
12901290
_sha: &str,
12911291
_parent_sha: &str,
1292+
_commit_date: DateTime<Utc>,
12921293
) -> anyhow::Result<()> {
12931294
no_queue_implementation_abort!()
12941295
}

site/src/github.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub mod comparison_summary;
44
use crate::api::github::Commit;
55
use crate::job_queue::run_new_queue;
66
use crate::load::{MissingReason, SiteCtxt, TryCommit};
7+
use chrono::{DateTime, Utc};
8+
use serde::Deserialize;
79
use std::sync::LazyLock;
810
use std::time::Duration;
911

10-
use serde::Deserialize;
11-
1212
type BoxedError = Box<dyn std::error::Error + Send + Sync>;
1313

1414
pub const RUST_REPO_GITHUB_API_URL: &str = "https://api.github.com/repos/rust-lang/rust";
@@ -236,13 +236,18 @@ pub async fn rollup_pr_number(
236236

237237
async fn attach_shas_to_try_benchmark_request(
238238
conn: &dyn database::pool::Connection,
239-
pr: u32,
240-
sha: &str,
241-
parent_sha: &str,
239+
pr_number: u32,
240+
commit: &TryCommit,
241+
commit_date: DateTime<Utc>,
242242
) {
243243
if run_new_queue() {
244244
if let Err(e) = conn
245-
.attach_shas_to_try_benchmark_request(pr, sha, parent_sha)
245+
.attach_shas_to_try_benchmark_request(
246+
pr_number,
247+
&commit.sha,
248+
&commit.parent_sha,
249+
commit_date,
250+
)
246251
.await
247252
{
248253
log::error!("Failed to add shas to try commit {}", e);
@@ -279,8 +284,8 @@ pub async fn enqueue_shas(
279284
attach_shas_to_try_benchmark_request(
280285
&*conn,
281286
pr_number,
282-
&try_commit.sha,
283-
&try_commit.parent_sha,
287+
&try_commit,
288+
commit_response.commit.committer.date,
284289
)
285290
.await;
286291

site/src/job_queue/mod.rs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ async fn create_benchmark_request_releases(
6868
.take(20)
6969
.collect();
7070

71-
for (name, date_time) in releases {
72-
if date_time >= cutoff && !index.contains_tag(&name) {
73-
let release_request = BenchmarkRequest::create_release(&name, date_time);
71+
for (name, commit_date) in releases {
72+
if commit_date >= cutoff && !index.contains_tag(&name) {
73+
let release_request = BenchmarkRequest::create_release(&name, commit_date);
7474
log::info!("Inserting release benchmark request {release_request:?}");
7575
if let Err(error) = conn.insert_benchmark_request(&release_request).await {
7676
log::error!("Failed to insert release benchmark request: {error}");
@@ -305,43 +305,21 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
305305

306306
#[cfg(test)]
307307
mod tests {
308-
use super::*;
309-
use chrono::{Datelike, Duration, TimeZone, Utc};
310-
use database::{
311-
tests::run_postgres_test, BenchmarkJobConclusion, BenchmarkSet, CodegenBackend, Profile,
312-
};
313-
314-
fn days_ago(day_str: &str) -> chrono::DateTime<Utc> {
315-
// Walk backwards until the first non-digit, then slice
316-
let days = day_str
317-
.strip_prefix("days")
318-
.unwrap()
319-
.parse::<i64>()
320-
.unwrap();
321-
322-
let timestamp = Utc::now() - Duration::days(days);
323-
// zero out the seconds
324-
Utc.with_ymd_and_hms(
325-
timestamp.year(),
326-
timestamp.month(),
327-
timestamp.day(),
328-
0,
329-
0,
330-
0,
331-
)
332-
.unwrap()
333-
}
308+
use crate::job_queue::build_queue;
309+
use chrono::Utc;
310+
use database::tests::run_postgres_test;
311+
use database::{BenchmarkRequest, BenchmarkRequestStatus};
334312

335-
fn create_master(sha: &str, parent: &str, pr: u32, age_days: &str) -> BenchmarkRequest {
336-
BenchmarkRequest::create_master(sha, parent, pr, days_ago(age_days))
313+
fn create_master(sha: &str, parent: &str, pr: u32) -> BenchmarkRequest {
314+
BenchmarkRequest::create_master(sha, parent, pr, Utc::now())
337315
}
338316

339-
fn create_try(pr: u32, age_days: &str) -> BenchmarkRequest {
340-
BenchmarkRequest::create_try_without_artifacts(pr, days_ago(age_days), "", "")
317+
fn create_try(pr: u32) -> BenchmarkRequest {
318+
BenchmarkRequest::create_try_without_artifacts(pr, "", "")
341319
}
342320

343-
fn create_release(tag: &str, age_days: &str) -> BenchmarkRequest {
344-
BenchmarkRequest::create_release(tag, days_ago(age_days))
321+
fn create_release(tag: &str) -> BenchmarkRequest {
322+
BenchmarkRequest::create_release(tag, Utc::now())
345323
}
346324

347325
async fn db_insert_requests(
@@ -482,26 +460,26 @@ mod tests {
482460
* +----------------+
483461
**/
484462
let requests = vec![
485-
create_master("bar", "parent1", 10, "days2"),
486-
create_master("345", "parent2", 11, "days2"),
487-
create_master("aaa", "parent3", 12, "days2"),
488-
create_master("rrr", "parent4", 13, "days2"),
489-
create_master("123", "bar", 14, "days2"),
490-
create_master("foo", "345", 15, "days2"),
491-
create_try(16, "days1"),
492-
create_release("v1.2.3", "days2"),
493-
create_try(17, "days1"),
494-
create_master("mmm", "aaa", 18, "days2"),
463+
create_master("bar", "parent1", 10),
464+
create_master("345", "parent2", 11),
465+
create_master("aaa", "parent3", 12),
466+
create_master("rrr", "parent4", 13),
467+
create_master("123", "bar", 14),
468+
create_master("foo", "345", 15),
469+
create_try(16),
470+
create_release("v1.2.3"),
471+
create_try(17),
472+
create_master("mmm", "aaa", 18),
495473
];
496474

497475
db_insert_requests(&*db, &requests).await;
498-
db.attach_shas_to_try_benchmark_request(16, "try1", "rrr")
476+
db.attach_shas_to_try_benchmark_request(16, "try1", "rrr", Utc::now())
499477
.await
500478
.unwrap();
501479
db.update_benchmark_request_status("try1", BenchmarkRequestStatus::InProgress)
502480
.await
503481
.unwrap();
504-
db.attach_shas_to_try_benchmark_request(17, "baz", "foo")
482+
db.attach_shas_to_try_benchmark_request(17, "baz", "foo", Utc::now())
505483
.await
506484
.unwrap();
507485

site/src/request_handlers/github.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ async fn record_try_benchmark_request_without_artifacts(
8484
) {
8585
// We only want to run this if the new system is running
8686
if run_new_queue() {
87-
let try_request =
88-
BenchmarkRequest::create_try_without_artifacts(pr, chrono::Utc::now(), backends, "");
87+
let try_request = BenchmarkRequest::create_try_without_artifacts(pr, backends, "");
8988
log::info!("Inserting try benchmark request {try_request:?}");
9089
if let Err(e) = conn.insert_benchmark_request(&try_request).await {
9190
log::error!("Failed to insert try benchmark request: {}", e);

0 commit comments

Comments
 (0)