Skip to content

Commit bfa79d4

Browse files
committed
update query to pull back parent and associated jobs
1 parent ccd8f70 commit bfa79d4

File tree

3 files changed

+130
-98
lines changed

3 files changed

+130
-98
lines changed

database/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,12 +1238,22 @@ impl CollectorConfig {
12381238
}
12391239
}
12401240

1241+
/// Mapping of a request to its parent along with all jobs
1242+
#[derive(Debug, PartialEq)]
1243+
pub struct InProgressRequestWithJobs {
1244+
/// In progress requests along with their associated jobs
1245+
pub request: (BenchmarkRequest, Vec<BenchmarkJob>),
1246+
/// Optionally the parent of the above request with _all_ their associated
1247+
/// jobs
1248+
pub parent: Option<(BenchmarkRequest, Vec<BenchmarkJob>)>,
1249+
}
1250+
12411251
/// The data that can be retrived from the database directly to populate the
12421252
/// status page
12431253
#[derive(Debug, PartialEq)]
12441254
pub struct PartialStatusPageData {
12451255
/// A Vector of; completed requests with any associated errors
12461256
pub completed_requests: Vec<(BenchmarkRequest, Vec<String>)>,
12471257
/// In progress requests along with their associated jobs
1248-
pub in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)>,
1258+
pub in_progress: Vec<InProgressRequestWithJobs>,
12491259
}

database/src/pool/postgres.rs

Lines changed: 117 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use crate::{
44
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob,
55
BenchmarkJobConclusion, BenchmarkJobStatus, BenchmarkRequest, BenchmarkRequestIndex,
66
BenchmarkRequestStatus, BenchmarkRequestType, BenchmarkSet, CodegenBackend, CollectionId,
7-
CollectorConfig, Commit, CommitType, CompileBenchmark, Date, Index, PartialStatusPageData,
8-
Profile, QueuedCommit, Scenario, Target, BENCHMARK_JOB_STATUS_FAILURE_STR,
9-
BENCHMARK_JOB_STATUS_IN_PROGRESS_STR, BENCHMARK_JOB_STATUS_QUEUED_STR,
10-
BENCHMARK_JOB_STATUS_SUCCESS_STR, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
7+
CollectorConfig, Commit, CommitType, CompileBenchmark, Date, InProgressRequestWithJobs, Index,
8+
PartialStatusPageData, Profile, QueuedCommit, Scenario, Target,
9+
BENCHMARK_JOB_STATUS_FAILURE_STR, BENCHMARK_JOB_STATUS_IN_PROGRESS_STR,
10+
BENCHMARK_JOB_STATUS_QUEUED_STR, BENCHMARK_JOB_STATUS_SUCCESS_STR,
11+
BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
1112
BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR, BENCHMARK_REQUEST_STATUS_COMPLETED_STR,
1213
BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR, BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR,
1314
BENCHMARK_REQUEST_TRY_STR,
@@ -1624,7 +1625,7 @@ where
16241625

16251626
let requests = rows
16261627
.into_iter()
1627-
.map(|it| row_to_benchmark_request(&it))
1628+
.map(|it| row_to_benchmark_request(&it, None))
16281629
.collect();
16291630
Ok(requests)
16301631
}
@@ -1984,14 +1985,23 @@ where
19841985
}
19851986

19861987
async fn get_status_page_data(&self) -> anyhow::Result<PartialStatusPageData> {
1987-
let max_completed_requests = 7;
1988+
let max_completed_requests = 30;
19881989

1989-
// Returns in progress requests along with their associated jobs
19901990
let in_progress_query = format!(
19911991
"
19921992
WITH in_progress_requests AS (
19931993
SELECT
1994-
{BENCHMARK_REQUEST_COLUMNS}
1994+
tag,
1995+
parent_sha,
1996+
pr,
1997+
commit_type,
1998+
status,
1999+
created_at,
2000+
completed_at,
2001+
backends,
2002+
profiles,
2003+
commit_date,
2004+
duration_ms
19952005
FROM
19962006
benchmark_request
19972007
WHERE
@@ -2022,15 +2032,73 @@ where
20222032
LEFT JOIN in_progress_requests ON job_queue.request_tag = in_progress_requests.tag
20232033
GROUP BY
20242034
job_queue.request_tag
2035+
), parent AS (
2036+
SELECT
2037+
benchmark_request.tag AS parent_tag,
2038+
benchmark_request.parent_sha AS parent_sha,
2039+
benchmark_request.pr AS parent_pr,
2040+
benchmark_request.commit_type AS parent_commit_type,
2041+
benchmark_request.status AS parent_status,
2042+
benchmark_request.created_at AS parent_created_at,
2043+
benchmark_request.completed_at AS parent_completed_at,
2044+
benchmark_request.backends AS parent_backends,
2045+
benchmark_request.profiles AS parent_profiles,
2046+
benchmark_request.commit_date AS parent_commit_date,
2047+
benchmark_request.duration_ms AS parent_duration_ms,
2048+
EXISTS (
2049+
SELECT
2050+
1
2051+
FROM
2052+
job_queue
2053+
WHERE
2054+
job_queue.request_tag = benchmark_request.tag
2055+
AND job_queue.status IN (
2056+
'{BENCHMARK_JOB_STATUS_QUEUED_STR}',
2057+
'{BENCHMARK_JOB_STATUS_IN_PROGRESS_STR}'
2058+
)
2059+
) AS parent_active
2060+
FROM
2061+
benchmark_request
2062+
LEFT JOIN
2063+
in_progress_requests ON benchmark_request.tag = in_progress_requests.parent_sha
2064+
), parent_jobs AS (
2065+
SELECT
2066+
request_tag AS parent_tag,
2067+
ARRAY_AGG(
2068+
ROW(
2069+
job_queue.id,
2070+
job_queue.request_tag,
2071+
job_queue.target,
2072+
job_queue.backend,
2073+
job_queue.profile,
2074+
job_queue.benchmark_set,
2075+
job_queue.status,
2076+
job_queue.created_at,
2077+
job_queue.started_at,
2078+
job_queue.completed_at,
2079+
job_queue.retry,
2080+
job_queue.collector_name
2081+
)::TEXT
2082+
) AS parent_jobs
2083+
FROM
2084+
job_queue
2085+
LEFT JOIN parent ON job_queue.request_tag = parent.parent_tag
2086+
GROUP BY
2087+
job_queue.request_tag
20252088
)
20262089
SELECT
20272090
in_progress_requests.*,
2028-
in_progress_jobs.jobs
2091+
in_progress_jobs.jobs,
2092+
parent.*,
2093+
parent_jobs.parent_jobs
20292094
FROM
20302095
in_progress_requests
20312096
LEFT JOIN
2032-
in_progress_jobs ON in_progress_requests.tag = in_progress_jobs.tag;
2033-
"
2097+
in_progress_jobs ON in_progress_requests.tag = in_progress_jobs.tag
2098+
LEFT JOIN
2099+
parent_jobs ON in_progress_requests.parent_sha = parent_jobs.parent_tag
2100+
LEFT JOIN
2101+
parent ON in_progress_requests.parent_sha = parent.parent_tag;"
20342102
);
20352103

20362104
// Gets requests along with how long the request took (latest job finish
@@ -2075,19 +2143,40 @@ where
20752143
"
20762144
);
20772145

2078-
let in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)> = self
2146+
let in_progress: Vec<InProgressRequestWithJobs> = self
20792147
.conn()
20802148
.query(&in_progress_query, &[])
20812149
.await?
20822150
.iter()
20832151
.map(|it| {
2084-
let benchmark_request = row_to_benchmark_request(it);
2152+
let benchmark_request = row_to_benchmark_request(it, None);
20852153
let jobs: Vec<BenchmarkJob> = it
20862154
.get::<_, Vec<String>>("jobs")
20872155
.iter()
20882156
.map(|it| benchmark_job_str_to_type(it).unwrap())
20892157
.collect();
2090-
(benchmark_request, jobs)
2158+
2159+
let parent_benchmark_request = row_to_benchmark_request(it, Some(12));
2160+
2161+
// This is ever-so-slightly grim however it allows us to not
2162+
// have to parse the text representation of the jobs. Which
2163+
// saves a reasonable amount of time to justify doing this.
2164+
let include_parent = it.get::<_, bool>("parent_active");
2165+
2166+
InProgressRequestWithJobs {
2167+
request: (benchmark_request, jobs),
2168+
parent: if include_parent {
2169+
// only parse the jobs if we need to include the parent
2170+
let parent_jobs: Vec<BenchmarkJob> = it
2171+
.get::<_, Vec<String>>("parent_jobs")
2172+
.iter()
2173+
.map(|it| benchmark_job_str_to_type(it).unwrap())
2174+
.collect();
2175+
Some((parent_benchmark_request, parent_jobs))
2176+
} else {
2177+
None
2178+
},
2179+
}
20912180
})
20922181
.collect();
20932182

@@ -2098,81 +2187,13 @@ where
20982187
.iter()
20992188
.map(|it| {
21002189
(
2101-
row_to_benchmark_request(it),
2190+
row_to_benchmark_request(it, None),
21022191
// The errors, if there are none this will be an empty vector
21032192
it.get::<_, Option<Vec<String>>>(11).unwrap_or_default(),
21042193
)
21052194
})
21062195
.collect();
21072196

2108-
let in_progress_tags: Vec<&str> =
2109-
in_progress.iter().map(|it| it.0.tag().unwrap()).collect();
2110-
2111-
let in_progress_tags: String = in_progress_tags.join(",");
2112-
2113-
// We don't do a status check on the jobs as we want to return all jobs,
2114-
// irrespective of status, that are attached to an inprogress
2115-
// benchmark_request
2116-
let rows = self
2117-
.conn()
2118-
.query(
2119-
"SELECT
2120-
id,
2121-
target,
2122-
backend,
2123-
profile,
2124-
request_tag,
2125-
benchmark_set,
2126-
created_at,
2127-
status,
2128-
started_at,
2129-
collector_name,
2130-
completed_at,
2131-
retry
2132-
FROM
2133-
job_queue WHERE job_queue.request_tag IN ($1);",
2134-
&[&in_progress_tags],
2135-
)
2136-
.await?;
2137-
2138-
let mut in_progress_jobs = vec![];
2139-
for row in rows {
2140-
let status_str = row.get::<_, &str>(7);
2141-
let status = match status_str {
2142-
BENCHMARK_JOB_STATUS_QUEUED_STR => BenchmarkJobStatus::Queued,
2143-
BENCHMARK_JOB_STATUS_IN_PROGRESS_STR => BenchmarkJobStatus::InProgress {
2144-
started_at: row.get::<_, DateTime<Utc>>(8),
2145-
collector_name: row.get::<_, String>(9),
2146-
},
2147-
BENCHMARK_JOB_STATUS_SUCCESS_STR | BENCHMARK_JOB_STATUS_FAILURE_STR => {
2148-
BenchmarkJobStatus::Completed {
2149-
started_at: row.get::<_, DateTime<Utc>>(8),
2150-
collector_name: row.get::<_, String>(9),
2151-
success: status_str == BENCHMARK_JOB_STATUS_SUCCESS_STR,
2152-
completed_at: row.get::<_, DateTime<Utc>>(10),
2153-
}
2154-
}
2155-
_ => panic!("Invalid benchmark job status: {status_str}"),
2156-
};
2157-
2158-
let job = BenchmarkJob {
2159-
id: row.get::<_, i32>(0) as u32,
2160-
target: Target::from_str(row.get::<_, &str>(1)).map_err(|e| anyhow::anyhow!(e))?,
2161-
backend: CodegenBackend::from_str(row.get::<_, &str>(2))
2162-
.map_err(|e| anyhow::anyhow!(e))?,
2163-
profile: Profile::from_str(row.get::<_, &str>(3))
2164-
.map_err(|e| anyhow::anyhow!(e))?,
2165-
request_tag: row.get::<_, String>(4),
2166-
benchmark_set: BenchmarkSet(row.get::<_, i32>(5) as u32),
2167-
created_at: row.get::<_, DateTime<Utc>>(6),
2168-
// The job is now in an in_progress state
2169-
status,
2170-
deque_counter: row.get::<_, i32>(11) as u32,
2171-
};
2172-
2173-
in_progress_jobs.push(job);
2174-
}
2175-
21762197
Ok(PartialStatusPageData {
21772198
completed_requests,
21782199
in_progress,
@@ -2231,18 +2252,19 @@ where
22312252
}
22322253
}
22332254

2234-
fn row_to_benchmark_request(row: &Row) -> BenchmarkRequest {
2235-
let tag = row.get::<_, Option<String>>(0);
2236-
let parent_sha = row.get::<_, Option<String>>(1);
2237-
let pr = row.get::<_, Option<i32>>(2);
2238-
let commit_type = row.get::<_, &str>(3);
2239-
let status = row.get::<_, &str>(4);
2240-
let created_at = row.get::<_, DateTime<Utc>>(5);
2241-
let completed_at = row.get::<_, Option<DateTime<Utc>>>(6);
2242-
let backends = row.get::<_, String>(7);
2243-
let profiles = row.get::<_, String>(8);
2244-
let commit_date = row.get::<_, Option<DateTime<Utc>>>(9);
2245-
let duration_ms = row.get::<_, Option<i32>>(10);
2255+
fn row_to_benchmark_request(row: &Row, row_offset: Option<usize>) -> BenchmarkRequest {
2256+
let row_offset = row_offset.unwrap_or(0);
2257+
let tag = row.get::<_, Option<String>>(0 + row_offset);
2258+
let parent_sha = row.get::<_, Option<String>>(1 + row_offset);
2259+
let pr = row.get::<_, Option<i32>>(2 + row_offset);
2260+
let commit_type = row.get::<_, &str>(3 + row_offset);
2261+
let status = row.get::<_, &str>(4 + row_offset);
2262+
let created_at = row.get::<_, DateTime<Utc>>(5 + row_offset);
2263+
let completed_at = row.get::<_, Option<DateTime<Utc>>>(6 + row_offset);
2264+
let backends = row.get::<_, String>(7 + row_offset);
2265+
let profiles = row.get::<_, String>(8 + row_offset);
2266+
let commit_date = row.get::<_, Option<DateTime<Utc>>>(9 + row_offset);
2267+
let duration_ms = row.get::<_, Option<i32>>(10 + row_offset);
22462268

22472269
let pr = pr.map(|v| v as u32);
22482270

site/src/request_handlers/status_page_new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ pub async fn handle_status_page_new(ctxt: Arc<SiteCtxt>) -> ServerResult<status_
141141
let mut in_progress: Vec<BenchmarkInProgressUi> = vec![];
142142
for it in partial_data.in_progress {
143143
in_progress.push(BenchmarkInProgressUi {
144-
request: benchmark_request_to_ui(&it.0, vec![]).map_err(error_to_string)?,
145-
jobs: it.1.iter().map(benchmark_job_to_ui).collect(),
144+
request: benchmark_request_to_ui(&it.request.0, vec![]).map_err(error_to_string)?,
145+
jobs: it.request.1.iter().map(benchmark_job_to_ui).collect(),
146146
});
147147
}
148148

0 commit comments

Comments
 (0)