Skip to content

Commit 1e0b75c

Browse files
committed
Simplify backend code of the new status page
1 parent e9c0447 commit 1e0b75c

File tree

7 files changed

+172
-288
lines changed

7 files changed

+172
-288
lines changed

database/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ impl BenchmarkRequest {
986986
self.commit_date
987987
}
988988

989+
pub fn commit_type(&self) -> &BenchmarkRequestType {
990+
&self.commit_type
991+
}
992+
989993
pub fn is_master(&self) -> bool {
990994
matches!(self.commit_type, BenchmarkRequestType::Master { .. })
991995
}
@@ -1249,8 +1253,8 @@ pub struct InProgressRequestWithJobs {
12491253
}
12501254

12511255
#[derive(Debug, PartialEq)]
1252-
pub struct CompletedBenchmarkRequestWithErrors {
1253-
request: BenchmarkRequest,
1256+
pub struct BenchmarkRequestWithErrors {
1257+
pub request: BenchmarkRequest,
12541258
/// Benchmark (name) -> error
1255-
errors: HashMap<String, String>,
1259+
pub errors: HashMap<String, String>,
12561260
}

database/src/pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::selector::CompileTestCase;
22
use crate::{
33
ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkJob, BenchmarkJobConclusion,
4-
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend,
5-
CollectorConfig, CompileBenchmark, CompletedBenchmarkRequestWithErrors, Target,
4+
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestWithErrors,
5+
BenchmarkSet, CodegenBackend, CollectorConfig, CompileBenchmark, Target,
66
};
77
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
88
use chrono::{DateTime, Utc};
@@ -282,7 +282,7 @@ pub trait Connection: Send + Sync {
282282
async fn get_last_n_completed_benchmark_requests(
283283
&self,
284284
count: u64,
285-
) -> anyhow::Result<Vec<CompletedBenchmarkRequestWithErrors>>;
285+
) -> anyhow::Result<Vec<BenchmarkRequestWithErrors>>;
286286

287287
/// Return jobs of all requests that are currently in progress, and the jobs of their parents.
288288
/// The keys of the hashmap contain the request tags.

database/src/pool/postgres.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::selector::CompileTestCase;
33
use crate::{
44
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkJob,
55
BenchmarkJobConclusion, BenchmarkJobStatus, BenchmarkRequest, BenchmarkRequestIndex,
6-
BenchmarkRequestStatus, BenchmarkRequestType, BenchmarkSet, CodegenBackend, CollectionId,
7-
CollectorConfig, Commit, CommitType, CompileBenchmark, CompletedBenchmarkRequestWithErrors,
8-
Date, Index, Profile, QueuedCommit, Scenario, Target, BENCHMARK_JOB_STATUS_FAILURE_STR,
6+
BenchmarkRequestStatus, BenchmarkRequestType, BenchmarkRequestWithErrors, BenchmarkSet,
7+
CodegenBackend, CollectionId, CollectorConfig, Commit, CommitType, CompileBenchmark, Date,
8+
Index, Profile, QueuedCommit, Scenario, Target, BENCHMARK_JOB_STATUS_FAILURE_STR,
99
BENCHMARK_JOB_STATUS_IN_PROGRESS_STR, BENCHMARK_JOB_STATUS_QUEUED_STR,
1010
BENCHMARK_JOB_STATUS_SUCCESS_STR, BENCHMARK_REQUEST_MASTER_STR, BENCHMARK_REQUEST_RELEASE_STR,
1111
BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR, BENCHMARK_REQUEST_STATUS_COMPLETED_STR,
@@ -2048,7 +2048,7 @@ where
20482048
async fn get_last_n_completed_benchmark_requests(
20492049
&self,
20502050
count: u64,
2051-
) -> anyhow::Result<Vec<CompletedBenchmarkRequestWithErrors>> {
2051+
) -> anyhow::Result<Vec<BenchmarkRequestWithErrors>> {
20522052
let rows = self
20532053
.conn()
20542054
.query(
@@ -2090,7 +2090,7 @@ where
20902090
.into_iter()
20912091
.map(|request| {
20922092
let errors = errors.remove(request.tag().unwrap()).unwrap_or_default();
2093-
CompletedBenchmarkRequestWithErrors { request, errors }
2093+
BenchmarkRequestWithErrors { request, errors }
20942094
})
20952095
.collect())
20962096
}

database/src/pool/sqlite.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction}
22
use crate::selector::CompileTestCase;
33
use crate::{
44
ArtifactCollection, ArtifactId, Benchmark, BenchmarkJob, BenchmarkJobConclusion,
5-
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend,
6-
CollectionId, CollectorConfig, Commit, CommitType, CompileBenchmark,
7-
CompletedBenchmarkRequestWithErrors, Date, Profile, Target,
5+
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkRequestWithErrors,
6+
BenchmarkSet, CodegenBackend, CollectionId, CollectorConfig, Commit, CommitType,
7+
CompileBenchmark, Date, Profile, Target,
88
};
99
use crate::{ArtifactIdNumber, Index, QueuedCommit};
1010
use chrono::{DateTime, TimeZone, Utc};
@@ -1388,7 +1388,7 @@ impl Connection for SqliteConnection {
13881388
async fn get_last_n_completed_benchmark_requests(
13891389
&self,
13901390
_count: u64,
1391-
) -> anyhow::Result<Vec<CompletedBenchmarkRequestWithErrors>> {
1391+
) -> anyhow::Result<Vec<BenchmarkRequestWithErrors>> {
13921392
no_queue_implementation_abort!()
13931393
}
13941394
}

site/src/api.rs

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -393,102 +393,78 @@ pub mod status {
393393

394394
pub mod status_new {
395395
use chrono::{DateTime, Utc};
396-
use database::BenchmarkSet;
397396
use hashbrown::HashMap;
398397
use serde::Serialize;
399398

400399
#[derive(Serialize, Debug)]
401400
#[serde(rename_all = "camelCase")]
402-
pub struct BenchmarkRequestStatusUi {
403-
pub state: String,
404-
pub completed_at: Option<DateTime<Utc>>,
405-
pub duration_s: Option<u64>,
401+
pub enum BenchmarkRequestStatus {
402+
Queued,
403+
InProgress,
404+
Completed,
406405
}
407406

408407
#[derive(Serialize, Debug)]
409408
#[serde(rename_all = "camelCase")]
410-
pub struct BenchmarkRequestTypeUi {
411-
pub r#type: String,
412-
pub tag: Option<String>,
413-
pub parent_sha: Option<String>,
414-
pub pr: Option<u32>,
409+
pub enum BenchmarkRequestType {
410+
Release,
411+
Master,
412+
Try,
415413
}
416414

417415
#[derive(Serialize, Debug)]
418416
#[serde(rename_all = "camelCase")]
419-
pub struct BenchmarkRequestUi {
420-
pub status: BenchmarkRequestStatusUi,
421-
pub request_type: BenchmarkRequestTypeUi,
422-
pub commit_date: Option<DateTime<Utc>>,
417+
pub struct BenchmarkRequest {
418+
pub tag: String,
419+
pub status: BenchmarkRequestStatus,
420+
pub request_type: BenchmarkRequestType,
423421
pub created_at: DateTime<Utc>,
424-
pub backends: Vec<String>,
425-
pub profiles: String,
426-
pub errors: Vec<String>,
422+
pub completed_at: Option<DateTime<Utc>>,
423+
pub duration_s: Option<u64>,
424+
pub errors: HashMap<String, String>,
427425
}
428426

429427
#[derive(Serialize, Debug)]
430428
#[serde(rename_all = "camelCase")]
431-
pub struct BenchmarkJobStatusUi {
432-
pub state: String,
433-
pub started_at: Option<DateTime<Utc>>,
434-
pub completed_at: Option<DateTime<Utc>>,
435-
pub collector_name: Option<String>,
429+
pub enum BenchmarkJobStatus {
430+
Queued,
431+
InProgress,
432+
Success,
433+
Failed,
436434
}
437435

438436
#[derive(Serialize, Debug)]
439437
#[serde(rename_all = "camelCase")]
440-
pub struct BenchmarkJobUi {
438+
pub struct BenchmarkJob {
439+
pub request_tag: String,
441440
pub target: String,
442441
pub backend: String,
443442
pub profile: String,
444-
pub request_tag: String,
445-
pub benchmark_set: BenchmarkSet,
443+
pub benchmark_set: u32,
446444
pub created_at: DateTime<Utc>,
447-
pub status: BenchmarkJobStatusUi,
445+
pub status: BenchmarkJobStatus,
448446
pub deque_counter: u32,
449447
}
450448

451449
#[derive(Serialize, Debug)]
452450
#[serde(rename_all = "camelCase")]
453-
pub struct BenchmarkInProgressUi {
454-
pub request: BenchmarkRequestUi,
455-
pub jobs: Vec<BenchmarkJobUi>,
456-
}
457-
458-
#[derive(Serialize, Debug, Clone)]
459-
#[serde(rename_all = "camelCase")]
460-
pub struct CollectorConfigUi {
451+
pub struct Collector {
461452
pub name: String,
462453
pub target: String,
463-
pub benchmark_set: BenchmarkSet,
454+
pub benchmark_set: u32,
464455
pub is_active: bool,
465456
pub last_heartbeat_at: DateTime<Utc>,
466457
pub date_added: DateTime<Utc>,
467-
}
468-
469-
#[derive(Serialize, Debug, Clone)]
470-
#[serde(rename_all = "camelCase")]
471-
pub struct CollectorInfo {
472-
/// Configuration for the collector
473-
pub config: CollectorConfigUi,
474-
/// Jobs that are assigned to the collector from the currently inprogress
475-
/// request and possibly that request's parent.
476-
pub job_ids: Vec<u32>,
458+
pub jobs: Vec<BenchmarkJob>,
477459
}
478460

479461
#[derive(Serialize, Debug)]
480462
#[serde(rename_all = "camelCase")]
481463
pub struct Response {
482-
/// The current queue, ordered `in_progress`, ... the queue, `completed`
483-
pub queue_request_tags: Vec<String>,
484-
/// Hash table of request tags to requests
485-
pub requests_map: HashMap<String, BenchmarkRequestUi>,
486-
/// Hash table of job ids to jobs
487-
pub job_map: HashMap<u32, BenchmarkJobUi>,
488-
/// Hash table of benchmark set ids to CollectorInfo
489-
pub collector_work_map: HashMap<u32, CollectorInfo>,
490-
/// Request tag to a vector of job ids
491-
pub tag_to_jobs: HashMap<String, Vec<u32>>,
464+
/// The current queue, starting from the queued request that will be benchmarked at the
465+
/// latest time, then the `in_progress` requests, and then the `completed` requests.
466+
pub requests: Vec<BenchmarkRequest>,
467+
pub collectors: Vec<Collector>,
492468
}
493469
}
494470

0 commit comments

Comments
 (0)