Skip to content

Commit e45236b

Browse files
committed
Feat; enqueue master commits, cron written but not wired up
1 parent d7d0647 commit e45236b

File tree

6 files changed

+265
-6
lines changed

6 files changed

+265
-6
lines changed

database/src/lib.rs

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,3 +798,154 @@ pub struct ArtifactCollection {
798798
pub duration: Duration,
799799
pub end_time: DateTime<Utc>,
800800
}
801+
802+
#[derive(Debug)]
803+
pub enum BenchmarkRequestCommitType {
804+
Try { pr: u32 },
805+
Master { pr: u32 },
806+
Release { tag: String },
807+
}
808+
809+
impl fmt::Display for BenchmarkRequestCommitType {
810+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
811+
match self {
812+
BenchmarkRequestCommitType::Try { pr: _ } => write!(f, "try"),
813+
BenchmarkRequestCommitType::Master { pr: _ } => write!(f, "master"),
814+
BenchmarkRequestCommitType::Release { tag: _ } => write!(f, "release"),
815+
}
816+
}
817+
}
818+
819+
#[derive(Debug)]
820+
pub enum BenchmarkRequestStatus {
821+
WaitingForArtifacts,
822+
WaitingForParent,
823+
Queued,
824+
InProgress,
825+
Completed,
826+
}
827+
828+
impl fmt::Display for BenchmarkRequestStatus {
829+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
830+
match self {
831+
BenchmarkRequestStatus::WaitingForArtifacts => write!(f, "waiting_for_artifacts"),
832+
BenchmarkRequestStatus::WaitingForParent => write!(f, "waiting_for_parent"),
833+
BenchmarkRequestStatus::Queued => write!(f, "queued"),
834+
BenchmarkRequestStatus::InProgress => write!(f, "in_progress"),
835+
BenchmarkRequestStatus::Completed => write!(f, "completed"),
836+
}
837+
}
838+
}
839+
840+
#[derive(Debug)]
841+
pub enum BenchmarkRequestType {
842+
/// A Try commit
843+
Try {
844+
sha: String,
845+
parent_sha: Option<String>,
846+
pr: u32,
847+
},
848+
/// A Master commit
849+
Master {
850+
sha: String,
851+
parent_sha: Option<String>,
852+
pr: u32,
853+
},
854+
/// A release only has a tag
855+
Release { tag: String },
856+
}
857+
858+
impl fmt::Display for BenchmarkRequestType {
859+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
860+
match self {
861+
BenchmarkRequestType::Try {
862+
sha: _,
863+
parent_sha: _,
864+
pr: _,
865+
} => write!(f, "try"),
866+
BenchmarkRequestType::Master {
867+
sha: _,
868+
parent_sha: _,
869+
pr: _,
870+
} => write!(f, "master"),
871+
BenchmarkRequestType::Release { tag: _ } => write!(f, "release"),
872+
}
873+
}
874+
}
875+
876+
#[derive(Debug)]
877+
pub struct BenchmarkRequest {
878+
pub commit_type: BenchmarkRequestType,
879+
pub created_at: DateTime<Utc>,
880+
pub completed_at: Option<DateTime<Utc>>,
881+
pub status: BenchmarkRequestStatus,
882+
pub backends: String,
883+
pub profiles: String,
884+
}
885+
886+
impl BenchmarkRequest {
887+
pub fn create_release(
888+
tag: &str,
889+
created_at: DateTime<Utc>,
890+
status: BenchmarkRequestStatus,
891+
backends: &str,
892+
profiles: &str,
893+
) -> Self {
894+
Self {
895+
commit_type: BenchmarkRequestType::Release {
896+
tag: tag.to_string(),
897+
},
898+
created_at,
899+
completed_at: None,
900+
status,
901+
backends: backends.to_string(),
902+
profiles: profiles.to_string(),
903+
}
904+
}
905+
906+
pub fn create_try(
907+
sha: &str,
908+
parent_sha: Option<&str>,
909+
pr: u32,
910+
created_at: DateTime<Utc>,
911+
status: BenchmarkRequestStatus,
912+
backends: &str,
913+
profiles: &str,
914+
) -> Self {
915+
Self {
916+
commit_type: BenchmarkRequestType::Try {
917+
pr,
918+
sha: sha.to_string(),
919+
parent_sha: parent_sha.map(|it| it.to_string()),
920+
},
921+
created_at,
922+
completed_at: None,
923+
status,
924+
backends: backends.to_string(),
925+
profiles: profiles.to_string(),
926+
}
927+
}
928+
929+
pub fn create_master(
930+
sha: &str,
931+
parent_sha: Option<&str>,
932+
pr: u32,
933+
created_at: DateTime<Utc>,
934+
status: BenchmarkRequestStatus,
935+
backends: &str,
936+
profiles: &str,
937+
) -> Self {
938+
Self {
939+
commit_type: BenchmarkRequestType::Master {
940+
pr,
941+
sha: sha.to_string(),
942+
parent_sha: parent_sha.map(|it| it.to_string()),
943+
},
944+
created_at,
945+
completed_at: None,
946+
status,
947+
backends: backends.to_string(),
948+
profiles: profiles.to_string(),
949+
}
950+
}
951+
}

database/src/pool.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
ArtifactCollection, ArtifactId, ArtifactIdNumber, CodegenBackend, CompileBenchmark, Target,
2+
ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, CodegenBackend,
3+
CompileBenchmark, Target,
34
};
45
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
56
use chrono::{DateTime, Utc};
@@ -178,6 +179,10 @@ pub trait Connection: Send + Sync {
178179

179180
/// Removes all data associated with the given artifact.
180181
async fn purge_artifact(&self, aid: &ArtifactId);
182+
183+
/// Add an item to the `benchmark_requests`, if the `benchmark_request`
184+
/// extists it will be ignored
185+
async fn insert_benchmark_request(&self, benchmark_request: &BenchmarkRequest);
181186
}
182187

183188
#[async_trait::async_trait]

database/src/pool/postgres.rs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, CodegenBackend, CollectionId,
4-
Commit, CommitType, CompileBenchmark, Date, Index, Profile, QueuedCommit, Scenario, Target,
3+
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkRequest,
4+
BenchmarkRequestType, CodegenBackend, CollectionId, Commit, CommitType, CompileBenchmark, Date,
5+
Index, Profile, QueuedCommit, Scenario, Target,
56
};
67
use anyhow::Context as _;
78
use chrono::{DateTime, TimeZone, Utc};
@@ -285,6 +286,22 @@ static MIGRATIONS: &[&str] = &[
285286
alter table pstat_series drop constraint test_case;
286287
alter table pstat_series add constraint test_case UNIQUE(crate, profile, scenario, backend, target, metric);
287288
"#,
289+
r#"
290+
CREATE TABLE IF NOT EXISTS benchmark_requests (
291+
id SERIAL PRIMARY KEY,
292+
tag TEXT NOT NULL UNIQUE,
293+
parent_sha TEXT,
294+
commit_type TEXT,
295+
pr INTEGER,
296+
created_at TIMESTAMPTZ NOT NULL,
297+
completed_at TIMESTAMPTZ,
298+
status TEXT NOT NULL,
299+
backends TEXT,
300+
profiles TEXT
301+
);
302+
CREATE INDEX IF NOT EXISTS benchmark_requests_status_idx on benchmark_requests (status);
303+
CREATE INDEX IF NOT EXISTS benchmark_requests_commit_type on benchmark_requests (commit_type);
304+
"#,
288305
];
289306

290307
#[async_trait::async_trait]
@@ -1365,6 +1382,66 @@ where
13651382
.await
13661383
.unwrap();
13671384
}
1385+
1386+
async fn insert_benchmark_request(&self, benchmark_request: &BenchmarkRequest) {
1387+
match &benchmark_request.commit_type {
1388+
BenchmarkRequestType::Try {
1389+
sha,
1390+
parent_sha,
1391+
pr,
1392+
}
1393+
| BenchmarkRequestType::Master {
1394+
sha,
1395+
parent_sha,
1396+
pr,
1397+
} => {
1398+
self.conn()
1399+
.execute(
1400+
r#"
1401+
INSERT INTO
1402+
benchmark_requests(parent_sha, pr, tag, created_at,
1403+
commit_type, status, backends, profiles)
1404+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
1405+
ON CONFLICT DO NOTHING;
1406+
"#,
1407+
&[
1408+
&parent_sha,
1409+
pr,
1410+
sha,
1411+
&benchmark_request.created_at,
1412+
&benchmark_request.commit_type.to_string(),
1413+
&benchmark_request.status.to_string(),
1414+
&benchmark_request.backends,
1415+
&benchmark_request.profiles,
1416+
],
1417+
)
1418+
.await
1419+
.unwrap();
1420+
}
1421+
BenchmarkRequestType::Release { tag } => {
1422+
self.conn()
1423+
.execute(
1424+
r#"
1425+
INSERT INTO
1426+
benchmark_requests(tag, created_at, commit_type,
1427+
status, backends, profiles)
1428+
VALUES ($1, $2, $3, $4, $5, $6);
1429+
ON CONFLICT DO NOTHING;
1430+
"#,
1431+
&[
1432+
tag,
1433+
&benchmark_request.created_at,
1434+
&benchmark_request.commit_type.to_string(),
1435+
&benchmark_request.status.to_string(),
1436+
&benchmark_request.backends,
1437+
&benchmark_request.profiles,
1438+
],
1439+
)
1440+
.await
1441+
.unwrap();
1442+
}
1443+
}
1444+
}
13681445
}
13691446

13701447
fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId {

database/src/pool/sqlite.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactCollection, ArtifactId, Benchmark, CodegenBackend, CollectionId, Commit, CommitType,
4-
CompileBenchmark, Date, Profile, Target,
3+
ArtifactCollection, ArtifactId, Benchmark, BenchmarkRequest, CodegenBackend, CollectionId,
4+
Commit, CommitType, CompileBenchmark, Date, Profile, Target,
55
};
66
use crate::{ArtifactIdNumber, Index, QueuedCommit};
77
use chrono::{DateTime, TimeZone, Utc};
@@ -1252,6 +1252,10 @@ impl Connection for SqliteConnection {
12521252
)
12531253
.unwrap();
12541254
}
1255+
1256+
async fn insert_benchmark_request(&self, _benchmark_request: &BenchmarkRequest) {
1257+
panic!("Queueing for SQLite has not been implemented, if you are wanting to test the queueing functionality please use postgres. Presuming you have docker installed, at the root of the repo you can run `make start-postgres` to spin up a postrgres database.");
1258+
}
12551259
}
12561260

12571261
fn parse_artifact_id(ty: &str, sha: &str, date: Option<i64>) -> ArtifactId {

site/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod server;
99
mod average;
1010
mod benchmark_metadata;
1111
mod comparison;
12+
mod queue_jobs;
1213
mod request_handlers;
1314
mod resources;
1415
mod selector;

site/src/load.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use serde::{Deserialize, Serialize};
1414
use crate::self_profile::SelfProfileCache;
1515
use collector::compile::benchmark::category::Category;
1616
use collector::{Bound, MasterCommit};
17-
use database::Pool;
1817
pub use database::{ArtifactId, Benchmark, Commit};
18+
use database::{BenchmarkRequest, BenchmarkRequestStatus, Pool};
1919
use database::{CommitType, Date};
2020

2121
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
@@ -282,6 +282,27 @@ impl SiteCtxt {
282282

283283
commits
284284
}
285+
286+
/// Store the latest master commits or do nothing if all of them are
287+
/// already in the database
288+
pub async fn enqueue_master_commits(&self) {
289+
let conn = self.conn().await;
290+
let master_commits = &self.get_master_commits().commits;
291+
292+
for master_commit in master_commits {
293+
let pr = master_commit.pr.unwrap_or(0);
294+
let benchmark = BenchmarkRequest::create_master(
295+
&master_commit.sha,
296+
Some(&master_commit.parent_sha),
297+
pr,
298+
master_commit.time,
299+
BenchmarkRequestStatus::Queued,
300+
"",
301+
"",
302+
);
303+
conn.insert_benchmark_request(&benchmark).await;
304+
}
305+
}
285306
}
286307

287308
/// Parses an artifact tag like `1.63.0` or `beta-2022-08-19` from a line taken from

0 commit comments

Comments
 (0)