Skip to content

Commit

Permalink
Redesign status page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Sep 11, 2023
1 parent 7bcf41b commit 2db0c66
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 188 deletions.
1 change: 1 addition & 0 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ pub struct CompileBenchmark {

#[derive(Debug)]
pub struct ArtifactCollection {
pub artifact: ArtifactId,
pub duration: Duration,
pub end_time: DateTime<Utc>,
}
2 changes: 1 addition & 1 deletion database/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait Connection: Send + Sync {

async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;

async fn last_artifact_collection(&self) -> Option<ArtifactCollection>;
async fn last_n_artifact_collections(&self, n: u32) -> Vec<ArtifactCollection>;

/// Returns the sha of the parent commit, if available.
///
Expand Down
63 changes: 38 additions & 25 deletions database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,21 +1211,31 @@ where
})
.collect()
}
async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
async fn last_n_artifact_collections(&self, n: u32) -> Vec<ArtifactCollection> {
self.conn()
.query_opt(
"select date_recorded, duration \
from artifact_collection_duration \
.query(
"select art.name, art.date, art.type, acd.date_recorded, acd.duration \
from artifact_collection_duration as acd \
join artifact as art on art.id = acd.aid \
order by date_recorded desc \
limit 1;",
&[],
limit $1;",
&[&n],
)
.await
.unwrap()
.map(|r| ArtifactCollection {
end_time: r.get(0),
duration: Duration::from_secs(r.get::<_, i32>(1) as u64),
.into_iter()
.map(|r| {
let sha = r.get::<_, String>(0);
let date = r.get::<_, Option<DateTime<Utc>>>(1);
let ty = r.get::<_, String>(2);

ArtifactCollection {
artifact: parse_artifact_id(&ty, &sha, date),
end_time: r.get(3),
duration: Duration::from_secs(r.get::<_, i32>(4) as u64),
}
})
.collect()
}
async fn parent_of(&self, sha: &str) -> Option<String> {
self.conn()
Expand Down Expand Up @@ -1369,22 +1379,25 @@ where
.unwrap()?;
let date = row.get::<_, Option<DateTime<Utc>>>(0);
let ty = row.get::<_, String>(1);
Some(parse_artifact_id(&ty, artifact, date))
}
}

match ty.as_str() {
"master" => Some(ArtifactId::Commit(Commit {
sha: artifact.to_owned(),
date: Date(date.expect("date present for master commits")),
r#type: CommitType::Master,
})),
"try" => Some(ArtifactId::Commit(Commit {
sha: artifact.to_owned(),
date: date
.map(Date)
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
r#type: CommitType::Try,
})),
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
_ => panic!("unknown artifact type: {:?}", ty),
}
fn parse_artifact_id(ty: &str, sha: &str, date: Option<DateTime<Utc>>) -> ArtifactId {
match ty {
"master" => ArtifactId::Commit(Commit {
sha: sha.to_owned(),
date: Date(date.expect("date present for master commits")),
r#type: CommitType::Master,
}),
"try" => ArtifactId::Commit(Commit {
sha: sha.to_owned(),
date: date
.map(Date)
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
r#type: CommitType::Try,
}),
"release" => ArtifactId::Tag(sha.to_owned()),
_ => panic!("unknown artifact type: {:?}", ty),
}
}
77 changes: 44 additions & 33 deletions database/src/pool/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,25 +577,7 @@ impl Connection for SqliteConnection {
.optional()
.unwrap()?;

match ty.as_str() {
"master" => Some(ArtifactId::Commit(Commit {
sha: artifact.to_owned(),
date: Date(
Utc.timestamp_opt(date.expect("master has date"), 0)
.unwrap(),
),
r#type: CommitType::Master,
})),
"try" => Some(ArtifactId::Commit(Commit {
sha: artifact.to_owned(),
date: date
.map(|d| Date(Utc.timestamp_opt(d, 0).unwrap()))
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
r#type: CommitType::Try,
})),
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
_ => panic!("unknown artifact type: {:?}", ty),
}
Some(parse_artifact_id(ty.as_str(), artifact, date))
}

async fn record_duration(&self, artifact: ArtifactIdNumber, duration: Duration) {
Expand Down Expand Up @@ -1162,24 +1144,31 @@ impl Connection for SqliteConnection {
.collect()
}

async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
async fn last_n_artifact_collections(&self, n: u32) -> Vec<ArtifactCollection> {
self.raw_ref()
.query_row(
"select date_recorded, duration \
from artifact_collection_duration \
.prepare_cached(
"select art.name, art.date, art.type, acd.date_recorded, acd.duration \
from artifact_collection_duration as acd \
join artifact as art on art.id = acd.aid \
order by date_recorded desc \
limit 1;",
params![],
|r| {
Ok((
Utc.timestamp_opt(r.get(0)?, 0).unwrap(),
Duration::from_secs(r.get(1)?),
))
},
limit ?;",
)
.optional()
.unwrap()
.map(|(end_time, duration)| ArtifactCollection { end_time, duration })
.query(params![&n])
.unwrap()
.mapped(|r| {
let sha = r.get::<_, String>(0)?;
let date = r.get::<_, Option<i64>>(1)?;
let ty = r.get::<_, String>(2)?;

Ok(ArtifactCollection {
artifact: parse_artifact_id(&ty, &sha, date),
end_time: Utc.timestamp_opt(r.get(3)?, 0).unwrap(),
duration: Duration::from_secs(r.get(4)?),
})
})
.collect::<Result<Vec<_>, _>>()
.unwrap()
}

async fn parent_of(&self, sha: &str) -> Option<String> {
Expand Down Expand Up @@ -1239,3 +1228,25 @@ impl Connection for SqliteConnection {
.unwrap()
}
}

fn parse_artifact_id(ty: &str, sha: &str, date: Option<i64>) -> ArtifactId {
match ty {
"master" => ArtifactId::Commit(Commit {
sha: sha.to_owned(),
date: Date(
Utc.timestamp_opt(date.expect("master has date"), 0)
.unwrap(),
),
r#type: CommitType::Master,
}),
"try" => ArtifactId::Commit(Commit {
sha: sha.to_owned(),
date: date
.map(|d| Date(Utc.timestamp_opt(d, 0).unwrap()))
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
r#type: CommitType::Try,
}),
"release" => ArtifactId::Tag(sha.to_owned()),
_ => panic!("unknown artifact type: {:?}", ty),
}
}
32 changes: 32 additions & 0 deletions site/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"vue-tsc": "^1.8.3"
},
"dependencies": {
"date-fns": "^2.30.0",
"highcharts": "6.0.7",
"msgpack-lite": "^0.1.26",
"parcel": "^2.8.3",
Expand Down
16 changes: 11 additions & 5 deletions site/frontend/src/pages/status/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface Commit {
type: "Try" | "Master";
}

interface BenchmarkStatus {
export interface BenchmarkError {
name: string;
error: string;
}
Expand Down Expand Up @@ -50,10 +50,16 @@ interface CurrentState {
progress: Step[];
}

export interface FinishedRun {
artifact: Artifact;
pr: number | null;
errors: BenchmarkError[];
duration: number;
finished_at: number;
}

export interface StatusResponse {
last_commit: Commit | null;
benchmarks: BenchmarkStatus[];
missing: Array<[Commit, MissingReason]>;
finished_runs: FinishedRun[];
current: CurrentState | null;
most_recent_end: number | null;
missing: Array<[Commit, MissingReason]>;
}
19 changes: 19 additions & 0 deletions site/frontend/src/pages/status/expansion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {ref} from "vue";

export function useExpandedStore() {
const expanded = ref(new Set());

function isExpanded(sha: string) {
return expanded.value.has(sha);
}

function toggleExpanded(sha: string) {
if (isExpanded(sha)) {
expanded.value.delete(sha);
} else {
expanded.value.add(sha);
}
}

return {toggleExpanded, isExpanded};
}
Loading

0 comments on commit 2db0c66

Please sign in to comment.