Skip to content
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sysinfo = { version = "0.33.1", features = ["serde"] }
indicatif = "0.17.8"
console = "0.15.8"
async-trait = "0.1.82"
humantime = "2.2.0"

[dev-dependencies]
temp-env = { version = "0.3.6", features = ["async_closure"] }
Expand Down
51 changes: 27 additions & 24 deletions src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ impl Display for ReportConclusion {

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FetchLocalRunReportHeadReport {
pub struct FetchLocalRunReportRun {
pub id: String,
pub impact: Option<f64>,
pub conclusion: ReportConclusion,
pub status: RunStatus,
pub url: String,
pub head_reports: Vec<FetchLocalRunReportHeadReport>,
pub results: Vec<FetchLocalRunBenchmarkResult>,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RunStatus {
Expand All @@ -121,14 +124,26 @@ pub enum RunStatus {
Pending,
Processing,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct FetchLocalRunReportRun {
pub struct FetchLocalRunReportHeadReport {
pub id: String,
pub status: RunStatus,
pub url: String,
pub head_reports: Vec<FetchLocalRunReportHeadReport>,
pub impact: Option<f64>,
pub conclusion: ReportConclusion,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct FetchLocalRunBenchmarkResult {
pub time: f64,
pub benchmark: FetchLocalRunBenchmark,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct FetchLocalRunBenchmark {
pub name: String,
}

nest! {
#[derive(Debug, Deserialize, Serialize)]*
#[serde(rename_all = "camelCase")]*
Expand All @@ -137,7 +152,7 @@ nest! {
settings: struct FetchLocalRunReportSettings {
allowed_regression: f64,
},
runs: Vec<FetchLocalRunReportRun>,
run: FetchLocalRunReportRun,
}
}
}
Expand Down Expand Up @@ -190,22 +205,10 @@ impl CodSpeedAPIClient {
)
.await;
match response {
Ok(response) => {
let allowed_regression = response.repository.settings.allowed_regression;

match response.repository.runs.into_iter().next() {
Some(run) => Ok(FetchLocalRunReportResponse {
allowed_regression,
run,
}),
None => bail!(
"No runs found for owner: {}, name: {}, run_id: {}",
vars.owner,
vars.name,
vars.run_id
),
}
}
Ok(response) => Ok(FetchLocalRunReportResponse {
allowed_regression: response.repository.settings.allowed_regression,
run: response.repository.run,
}),
Err(err) if err.contains_error_code("UNAUTHENTICATED") => {
bail!("Your session has expired, please login again using `codspeed auth login`")
}
Expand Down
10 changes: 8 additions & 2 deletions src/queries/FetchLocalRunReport.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ query FetchLocalRunReport($owner: String!, $name: String!, $runId: String!) {
settings {
allowedRegression
}
runs(where: { id: { equals: $runId } }) {
id
run(id: $runId) {
id
status
url
headReports {
id
impact
conclusion
}
results {
time
benchmark {
name
}
}
}
}
}
13 changes: 2 additions & 11 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,8 @@ pub async fn run(
end_group!();

if provider.get_run_environment() == RunEnvironment::Local {
start_group!("Fetching the results");
let run_id = upload_result.run_id.clone();
poll_results::poll_results(api_client, &provider, upload_result.run_id).await?;
if output_json {
// TODO: Refactor `log_json` to avoid having to format the json manually
// We could make use of structured logging for this https://docs.rs/log/latest/log/#structured-logging
log_json!(format!(
"{{\"event\": \"run_finished\", \"run_id\": \"{}\"}}",
run_id
));
}
poll_results::poll_results(api_client, &provider, upload_result.run_id, output_json)
.await?;
end_group!();
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/run/poll_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub async fn poll_results(
api_client: &CodSpeedAPIClient,
provider: &Box<dyn RunEnvironmentProvider>,
run_id: String,
output_json: bool,
) -> Result<()> {
let start = Instant::now();
let run_environment_metadata = provider.get_run_environment_metadata()?;
Expand All @@ -29,6 +30,7 @@ pub async fn poll_results(
run_id: run_id.clone(),
};

start_group!("Fetching the results");
let response;
loop {
if start.elapsed() > RUN_PROCESSING_MAX_DURATION {
Expand Down Expand Up @@ -84,5 +86,34 @@ pub async fn poll_results(
style(response.run.url).blue().bold().underlined()
);

if output_json {
// TODO: Refactor `log_json` to avoid having to format the json manually
// We could make use of structured logging for this https://docs.rs/log/latest/log/#structured-logging
log_json!(format!(
"{{\"event\": \"run_finished\", \"run_id\": \"{}\"}}",
run_id
));
}

end_group!();

if !response.run.results.is_empty() {
start_group!("Benchmarks");
for result in response.run.results {
let benchmark_name = result.benchmark.name;
let time: humantime::Duration = Duration::from_secs_f64(result.time).into();
let time_text = style(format!("{}", time)).bold();

if output_json {
log_json!(format!(
"{{\"event\": \"benchmark_ran\", \"name\": \"{}\", \"time\": \"{}\"}}",
benchmark_name, result.time,
));
}
info!("{} - Time: {}", benchmark_name, time_text);
}
end_group!();
}

Ok(())
}
Loading