Skip to content

Commit ba16a2e

Browse files
committed
Create api endpoint for new status page
1 parent cfcd625 commit ba16a2e

File tree

6 files changed

+91
-11
lines changed

6 files changed

+91
-11
lines changed

database/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ pub struct ArtifactCollection {
807807
pub end_time: DateTime<Utc>,
808808
}
809809

810-
#[derive(Debug, Copy, Clone, PartialEq)]
810+
#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
811811
pub enum BenchmarkRequestStatus {
812812
WaitingForArtifacts,
813813
ArtifactsReady,
@@ -858,7 +858,7 @@ const BENCHMARK_REQUEST_TRY_STR: &str = "try";
858858
const BENCHMARK_REQUEST_MASTER_STR: &str = "master";
859859
const BENCHMARK_REQUEST_RELEASE_STR: &str = "release";
860860

861-
#[derive(Debug, Clone, PartialEq)]
861+
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
862862
pub enum BenchmarkRequestType {
863863
/// A Try commit
864864
Try {
@@ -886,7 +886,7 @@ impl fmt::Display for BenchmarkRequestType {
886886
}
887887
}
888888

889-
#[derive(Debug, Clone, PartialEq)]
889+
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
890890
pub struct BenchmarkRequest {
891891
commit_type: BenchmarkRequestType,
892892
// When was the compiler artifact created
@@ -1051,7 +1051,7 @@ impl BenchmarkRequestIndex {
10511051
}
10521052
}
10531053

1054-
#[derive(Debug, Clone, PartialEq)]
1054+
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
10551055
pub enum BenchmarkJobStatus {
10561056
Queued,
10571057
InProgress {
@@ -1093,7 +1093,7 @@ impl fmt::Display for BenchmarkJobStatus {
10931093
}
10941094
}
10951095

1096-
#[derive(Debug, Copy, Clone, PartialEq)]
1096+
#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
10971097
pub struct BenchmarkSet(u32);
10981098

10991099
impl BenchmarkSet {
@@ -1108,7 +1108,7 @@ impl BenchmarkSet {
11081108
/// Each request is split into several `BenchmarkJob`s. Collectors poll the
11091109
/// queue and claim a job only when its `benchmark_set` matches one of the sets
11101110
/// they are responsible for.
1111-
#[derive(Debug, Clone, PartialEq)]
1111+
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
11121112
pub struct BenchmarkJob {
11131113
id: u32,
11141114
target: Target,
@@ -1181,7 +1181,7 @@ impl BenchmarkJobConclusion {
11811181
}
11821182

11831183
/// The configuration for a collector
1184-
#[derive(Debug, PartialEq)]
1184+
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
11851185
pub struct CollectorConfig {
11861186
name: String,
11871187
target: Target,
@@ -1219,7 +1219,7 @@ impl CollectorConfig {
12191219

12201220
/// The data that can be retrived from the database directly to populate the
12211221
/// status page
1222-
#[derive(Debug, PartialEq)]
1222+
#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
12231223
pub struct PartialStatusPageData {
12241224
pub completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)>,
12251225
pub in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)>,

database/src/pool/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ where
20932093
// perform any computations on it
20942094
it.get::<_, String>(10),
20952095
// The errors, if there are none this will be an empty vector
2096-
it.get::<_, Vec<String>>(11),
2096+
it.get::<_, Option<Vec<String>>>(11).unwrap_or_default(),
20972097
)
20982098
})
20992099
.collect();

site/src/api.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ pub mod status {
391391
}
392392
}
393393

394+
pub mod status_new {
395+
use database::{BenchmarkJob, BenchmarkRequest, CollectorConfig};
396+
use serde::Serialize;
397+
398+
#[derive(Serialize, Debug)]
399+
pub struct Response {
400+
/// Completed requests alongside any errors
401+
pub completed: Vec<(BenchmarkRequest, Vec<String>)>,
402+
/// In progress requests alongside the jobs associated with the request
403+
pub in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)>,
404+
/// Configuration for all collectors including ones that are inactive
405+
pub collector_configs: Vec<CollectorConfig>,
406+
}
407+
}
408+
394409
pub mod self_profile_raw {
395410
use serde::{Deserialize, Serialize};
396411

site/src/request_handlers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod graph;
55
mod next_artifact;
66
mod self_profile;
77
mod status_page;
8+
mod status_page_new;
89

910
pub use bootstrap::handle_bootstrap;
1011
pub use dashboard::handle_dashboard;
@@ -19,6 +20,7 @@ pub use self_profile::{
1920
handle_self_profile_raw_download,
2021
};
2122
pub use status_page::handle_status_page;
23+
pub use status_page_new::handle_status_page_new;
2224

2325
use crate::api::{info, ServerResult};
2426
use crate::load::SiteCtxt;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::sync::Arc;
2+
3+
use crate::api::{status_new, ServerResult};
4+
use crate::load::SiteCtxt;
5+
6+
pub async fn handle_status_page_new(ctxt: Arc<SiteCtxt>) -> ServerResult<status_new::Response> {
7+
let conn = ctxt.conn().await;
8+
9+
let collector_configs = conn
10+
.get_collector_configs()
11+
.await
12+
.map_err(|e| e.to_string())?;
13+
// The query gives us `max_completed_requests` number of completed requests
14+
// and all inprogress requests without us needing to specify
15+
//
16+
// TODO; for `in_progress` requests we could look at the the completed
17+
// `requests`, then use the `duration_ms` to display an estimated job
18+
// finish time. Could also do that on the frontend but probably makes
19+
// sense to do in SQL.
20+
let partial_data = conn
21+
.get_status_page_data()
22+
.await
23+
.map_err(|e| e.to_string())?;
24+
25+
Ok(status_new::Response {
26+
completed: partial_data
27+
.completed_requests
28+
.iter()
29+
// @TODO Remove this
30+
.map(|it| (it.0.clone(), it.2.clone()))
31+
.collect(),
32+
in_progress: partial_data.in_progress,
33+
collector_configs,
34+
})
35+
}

site/src/server.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ async fn serve_req(server: Server, req: Request) -> Result<Response, ServerError
382382
.handle_get_async(&req, request_handlers::handle_status_page)
383383
.await;
384384
}
385+
"/perf/status_page_new" => {
386+
let ctxt: Arc<SiteCtxt> = server.ctxt.read().as_ref().unwrap().clone();
387+
let result = request_handlers::handle_status_page_new(ctxt).await;
388+
return match result {
389+
Ok(result) => Ok(http::Response::builder()
390+
.header_typed(ContentType::json())
391+
.body(hyper::Body::from(serde_json::to_string(&result).unwrap()))
392+
.unwrap()),
393+
Err(err) => Ok(http::Response::builder()
394+
.status(StatusCode::INTERNAL_SERVER_ERROR)
395+
.header_typed(ContentType::text_utf8())
396+
.header_typed(CacheControl::new().with_no_cache().with_no_store())
397+
.body(hyper::Body::from(err))
398+
.unwrap()),
399+
};
400+
}
385401
"/perf/next_artifact" => {
386402
return server
387403
.handle_get_async(&req, request_handlers::handle_next_artifact)
@@ -640,6 +656,7 @@ async fn handle_fs_path(
640656
| "/dashboard.html"
641657
| "/detailed-query.html"
642658
| "/help.html"
659+
| "/status_new.html"
643660
| "/status.html" => resolve_template(relative_path).await,
644661
_ => match TEMPLATES.get_static_asset(relative_path, use_compression)? {
645662
Payload::Compressed(data) => {
@@ -714,14 +731,18 @@ fn verify_gh_sig(cfg: &Config, header: &str, body: &[u8]) -> Option<bool> {
714731
Some(false)
715732
}
716733

717-
fn to_response<S>(result: ServerResult<S>, compression: &Option<BrotliEncoderParams>) -> Response
734+
fn to_response_with_content_type<S>(
735+
result: ServerResult<S>,
736+
content_type: ContentType,
737+
compression: &Option<BrotliEncoderParams>,
738+
) -> Response
718739
where
719740
S: Serialize,
720741
{
721742
match result {
722743
Ok(result) => {
723744
let response = http::Response::builder()
724-
.header_typed(ContentType::octet_stream())
745+
.header_typed(content_type)
725746
.header_typed(CacheControl::new().with_no_cache().with_no_store());
726747
let body = rmp_serde::to_vec_named(&result).unwrap();
727748
maybe_compressed_response(response, body, compression)
@@ -735,6 +756,13 @@ where
735756
}
736757
}
737758

759+
fn to_response<S>(result: ServerResult<S>, compression: &Option<BrotliEncoderParams>) -> Response
760+
where
761+
S: Serialize,
762+
{
763+
to_response_with_content_type(result, ContentType::octet_stream(), compression)
764+
}
765+
738766
pub fn maybe_compressed_response(
739767
response: http::response::Builder,
740768
body: Vec<u8>,

0 commit comments

Comments
 (0)