Skip to content

Feat; status page queries #2217

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,10 @@ impl BenchmarkJob {
| BenchmarkJobStatus::Completed { collector_name, .. } => Some(collector_name),
}
}

pub fn status(&self) -> &BenchmarkJobStatus {
&self.status
}
}

/// Describes the final state of a job
Expand Down Expand Up @@ -1201,3 +1205,11 @@ impl CollectorConfig {
self.date_added
}
}

/// The data that can be retrived from the database directly to populate the
/// status page
#[derive(Debug, PartialEq)]
pub struct PartialStatusPageData {
pub completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)>,
pub in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)>,
}
141 changes: 140 additions & 1 deletion database/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::selector::CompileTestCase;
use crate::{
ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkJob, BenchmarkJobConclusion,
BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, BenchmarkSet, CodegenBackend,
CollectorConfig, CompileBenchmark, Target,
CollectorConfig, CompileBenchmark, PartialStatusPageData, Target,
};
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -265,6 +265,8 @@ pub trait Connection: Send + Sync {
id: u32,
benchmark_job_conculsion: &BenchmarkJobConclusion,
) -> anyhow::Result<()>;

async fn get_status_page_data(&self) -> anyhow::Result<PartialStatusPageData>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -387,6 +389,7 @@ mod tests {
use super::*;
use crate::metric::Metric;
use crate::tests::run_postgres_test;
use crate::BenchmarkJobStatus;
use crate::{tests::run_db_test, BenchmarkRequestType, Commit, CommitType, Date};
use chrono::Utc;
use std::str::FromStr;
Expand Down Expand Up @@ -969,6 +972,142 @@ mod tests {
let completed = db.load_benchmark_request_index().await.unwrap();

assert!(completed.contains_tag("sha-1"));
Ok(ctx)
})
.await;
}

#[tokio::test]
async fn get_status_page_data() {
run_postgres_test(|ctx| async {
let db = ctx.db_client().connection().await;
let benchmark_set = BenchmarkSet(0u32);
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
let tag = "sha-1";
let tag_two = "sha-2";
let collector_name = "collector-1";
let target = Target::X86_64UnknownLinuxGnu;

db.add_collector_config(collector_name, &target, benchmark_set.0, true)
.await
.unwrap();

let benchmark_request = BenchmarkRequest::create_release(tag, time);
db.insert_benchmark_request(&benchmark_request)
.await
.unwrap();

complete_request(&*db, tag, collector_name, benchmark_set.0, &target).await;
// record a couple of errors against the tag
let artifact_id = db.artifact_id(&ArtifactId::Tag(tag.to_string())).await;

db.record_error(artifact_id, "example-1", "This is an error")
.await;
db.record_error(artifact_id, "example-2", "This is another error")
.await;

let benchmark_request_two = BenchmarkRequest::create_release(tag_two, time);
db.insert_benchmark_request(&benchmark_request_two)
.await
.unwrap();

db.enqueue_benchmark_job(
benchmark_request_two.tag().unwrap(),
&target,
&CodegenBackend::Llvm,
&Profile::Opt,
benchmark_set.0,
)
.await
.unwrap();
db.enqueue_benchmark_job(
benchmark_request_two.tag().unwrap(),
&target,
&CodegenBackend::Llvm,
&Profile::Debug,
benchmark_set.0,
)
.await
.unwrap();

db.update_benchmark_request_status(
benchmark_request_two.tag().unwrap(),
BenchmarkRequestStatus::InProgress,
)
.await
.unwrap();

let status_page_data = db.get_status_page_data().await.unwrap();

assert!(status_page_data.completed_requests.len() == 1);
assert_eq!(status_page_data.completed_requests[0].0.tag().unwrap(), tag);
assert!(matches!(
status_page_data.completed_requests[0].0.status(),
BenchmarkRequestStatus::Completed { .. }
));
// can't really test duration
// ensure errors are correct
assert_eq!(
status_page_data.completed_requests[0].2[0],
"This is an error".to_string()
);
assert_eq!(
status_page_data.completed_requests[0].2[1],
"This is another error".to_string()
);

assert!(status_page_data.in_progress.len() == 1);
// we should have 2 jobs
assert!(status_page_data.in_progress[0].1.len() == 2);
// the request should be in progress
assert!(matches!(
status_page_data.in_progress[0].0.status(),
BenchmarkRequestStatus::InProgress
));

// Test the first job
assert!(matches!(
status_page_data.in_progress[0].1[0].target(),
Target::X86_64UnknownLinuxGnu
));
assert!(matches!(
status_page_data.in_progress[0].1[0].status(),
BenchmarkJobStatus::Queued
));
assert!(matches!(
status_page_data.in_progress[0].1[0].backend(),
CodegenBackend::Llvm
));
assert!(matches!(
status_page_data.in_progress[0].1[0].profile(),
Profile::Opt
));
assert_eq!(
status_page_data.in_progress[0].1[0].benchmark_set(),
&benchmark_set
);

// test the second job
assert!(matches!(
status_page_data.in_progress[0].1[1].target(),
Target::X86_64UnknownLinuxGnu
));
assert!(matches!(
status_page_data.in_progress[0].1[1].status(),
BenchmarkJobStatus::Queued
));
assert!(matches!(
status_page_data.in_progress[0].1[1].backend(),
CodegenBackend::Llvm
));
assert!(matches!(
status_page_data.in_progress[0].1[1].profile(),
Profile::Debug
));
assert_eq!(
status_page_data.in_progress[0].1[1].benchmark_set(),
&benchmark_set
);

Ok(ctx)
})
Expand Down
Loading
Loading