Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign status page #1718

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,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 @@ -158,7 +158,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
65 changes: 39 additions & 26 deletions database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,21 +1214,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 @@ -1372,23 +1382,7 @@ where
.unwrap()?;
let date = row.get::<_, Option<DateTime<Utc>>>(0);
let ty = row.get::<_, String>(1);

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),
}
Some(parse_artifact_id(&ty, artifact, date))
}

async fn purge_artifact(&self, aid: &ArtifactId) {
Expand All @@ -1401,3 +1395,22 @@ where
.unwrap();
}
}

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 @@ -1166,24 +1148,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 @@ -1252,3 +1241,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
54 changes: 42 additions & 12 deletions site/frontend/src/pages/status/data.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
interface Commit {
export interface Commit {
sha: string;
date: string;
type: "Try" | "Master";
}

interface BenchmarkStatus {
export interface BenchmarkError {
name: string;
error: string;
}
Expand All @@ -16,20 +16,50 @@ interface Step {
current_progress: number;
}

/**
* The `any` types in the interface below were chosen because the types are quite complex
* on the Rust side (they are modeled with enums encoded in a way that is not so simple to model in
* TS).
*/
export type Artifact =
| {
Commit: Commit;
}
| {
Tag: string;
};

export type MissingReason =
| {
Master: {
pr: number;
parent_sha: string;
is_try_parent: boolean;
};
}
| {
Try: {
pr: number;
parent_sha: string;
include: string | null;
exclude: string | null;
runs: number | null;
};
}
| {
InProgress: MissingReason;
};

interface CurrentState {
artifact: any;
artifact: Artifact;
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, any]>;
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
Loading