Skip to content
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

feat(run): change verbs tense to continuous #35

Closed
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
6 changes: 4 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{api_client::CodSpeedAPIClient, auth, prelude::*, run};
use crate::{api_client::CodSpeedAPIClient, auth, logger::CODSPEED_U8_COLOR_CODE, prelude::*, run};
use clap::{
builder::{styling, Styles},
Parser, Subcommand,
Expand All @@ -8,7 +8,9 @@ fn create_styles() -> Styles {
styling::Styles::styled()
.header(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
.usage(styling::AnsiColor::Green.on_default() | styling::Effects::BOLD)
.literal(styling::AnsiColor::Magenta.on_default() | styling::Effects::BOLD)
.literal(
styling::Ansi256Color(CODSPEED_U8_COLOR_CODE).on_default() | styling::Effects::BOLD,
)
.placeholder(styling::AnsiColor::Cyan.on_default())
}

Expand Down
29 changes: 26 additions & 3 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ use std::{
time::Duration,
};

use console::Style;
use console::{style, Style};
use indicatif::{ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use log::Log;
use simplelog::SharedLogger;
use std::io::Write;

pub const CODSPEED_U8_COLOR_CODE: u8 = 208; // #FF8700
const BLACK_U8_COLOR_CODE: u8 = 16; // #000

/// This target is used exclusively to handle group events.
pub const GROUP_TARGET: &str = "codspeed::group";
pub const OPENED_GROUP_TARGET: &str = "codspeed::group::opened";
Expand Down Expand Up @@ -135,11 +138,24 @@ impl Log for LocalLogger {
if let Some(group_event) = get_group_event(record) {
match group_event {
GroupEvent::Start(name) | GroupEvent::StartOpened(name) => {
println!(
" {}",
style(format!(" {} ", name.to_uppercase()))
.bold()
.color256(BLACK_U8_COLOR_CODE)
.on_color256(CODSPEED_U8_COLOR_CODE)
);
println!();

if *IS_TTY {
let spinner = ProgressBar::new_spinner();
spinner.set_style(
ProgressStyle::with_template(
" {spinner:>.cyan} {wide_msg:.cyan.bold}",
format!(
" {{spinner:>.{}}} {{wide_msg:.{}.bold}}",
CODSPEED_U8_COLOR_CODE, CODSPEED_U8_COLOR_CODE
)
.as_str(),
)
.unwrap(),
);
Expand All @@ -155,10 +171,10 @@ impl Log for LocalLogger {
let mut spinner = SPINNER.lock().unwrap();
if let Some(spinner) = spinner.as_mut() {
spinner.finish_and_clear();
// Separate groups with a newline
println!();
}
}
println!();
}
}

Expand Down Expand Up @@ -213,3 +229,10 @@ impl SharedLogger for LocalLogger {
pub fn get_local_logger() -> Box<dyn SharedLogger> {
Box::new(LocalLogger::new())
}

pub fn clean_logger() {
let mut spinner = SPINNER.lock().unwrap();
if let Some(spinner) = spinner.as_mut() {
spinner.finish_and_clear();
}
}
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod prelude;
mod request_client;
mod run;

use console::style;
use prelude::*;

use log::log_enabled;
Expand All @@ -21,16 +22,18 @@ async fn main() {
if let Err(err) = res {
for cause in err.chain() {
if log_enabled!(log::Level::Error) {
error!("Error {}", cause);
error!("{} {}", style("Error:").bold().red(), style(cause).red());
} else {
eprintln!("Error {}", cause);
eprintln!("Error: {}", cause);
}
}
if log_enabled!(log::Level::Debug) {
for e in err.chain().skip(1) {
debug!("Caused by: {}", e);
}
}
logger::clean_logger();

std::process::exit(1);
}
}
8 changes: 5 additions & 3 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ pub async fn run(args: RunArgs, api_client: &CodSpeedAPIClient) -> Result<()> {
let codspeed_config = CodSpeedConfig::load()?;
let logger = Logger::new(&provider)?;

show_banner();
if provider.get_provider_slug() != "local" {
show_banner();
}
debug!("config: {:#?}", config);

if provider.get_provider_slug() == "local" {
Expand All @@ -123,13 +125,13 @@ pub async fn run(args: RunArgs, api_client: &CodSpeedAPIClient) -> Result<()> {
let run_data = runner::run(&config, &system_info).await?;

if !config.skip_upload {
start_group!("Upload the results");
start_group!("Uploading performance data");
logger.persist_log_to_profile_folder(&run_data)?;
let upload_result = uploader::upload(&config, &system_info, &provider, &run_data).await?;
end_group!();

if provider.get_provider_slug() == "local" {
start_group!("Fetch the results");
start_group!("Fetching the results");
poll_results::poll_results(&config, api_client, &provider, upload_result.run_id)
.await?;
end_group!();
Expand Down
4 changes: 2 additions & 2 deletions src/run/poll_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub async fn poll_results(
.next()
.ok_or_else(|| anyhow!("No head report found in the run report"))?;

info!("Report completed, here are the results:");
if let Some(impact) = report.impact {
let rounded_impact = (impact * 100.0).round();
let impact_text = if impact > 0.0 {
Expand All @@ -73,8 +72,9 @@ pub async fn poll_results(
impact_text,
(response.allowed_regression * 100.0).round()
);
} else {
info!("No impact detected, reason: {}", report.conclusion);
}
info!("Conclusion: {}", report.conclusion);

let mut report_url = Url::parse(config.frontend_url.as_str())?;
report_url.set_path(format!("{}/{}/runs/{}", owner, name, response.run.id).as_str());
Expand Down
4 changes: 2 additions & 2 deletions src/run/runner/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub struct RunData {

pub async fn run(config: &Config, system_info: &SystemInfo) -> Result<RunData> {
if !config.skip_setup {
start_group!("Prepare the environment");
start_group!("Preparing the environment");
setup(system_info, config).await?;
end_group!();
}
//TODO: add valgrind version check
start_opened_group!("Run the benchmarks");
start_opened_group!("Running the benchmarks");
let profile_folder = create_profile_folder()?;
let mongo_tracer = if let Some(mongodb_config) = &config.instruments.mongodb {
let mut mongo_tracer = MongoTracer::try_from(&profile_folder, mongodb_config)?;
Expand Down
37 changes: 25 additions & 12 deletions src/run/runner/valgrind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ lazy_static! {
};
}

fn get_bench_command(config: &Config) -> String {
let bench_command = &config.command;
bench_command
fn get_bench_command(config: &Config) -> Result<String> {
let bench_command = &config.command.trim();

if bench_command.is_empty() {
bail!("The bench command is empty");
}

Ok(bench_command
// Fixes a compatibility issue with cargo 1.66+ running directly under valgrind <3.20
.replace("cargo codspeed", "cargo-codspeed")
.replace("cargo codspeed", "cargo-codspeed"))
}

pub const VALGRIND_EXECUTION_TARGET: &str = "valgrind::execution";
Expand All @@ -75,8 +80,8 @@ fn run_command_with_log_pipe(mut cmd: Command) -> Result<ExitStatus> {
}
suspend_progress_bar(|| {
writer.write_all(&buffer[..bytes_read]).unwrap();
trace!(target: VALGRIND_EXECUTION_TARGET, "{}{}", prefix, String::from_utf8_lossy(&buffer[..bytes_read]));
});
trace!(target: VALGRIND_EXECUTION_TARGET, "{}{}", prefix, String::from_utf8_lossy(&buffer[..bytes_read]));
}
Ok(())
}
Expand Down Expand Up @@ -137,7 +142,7 @@ pub fn measure(
.arg(format!("--log-file={}", log_path.to_str().unwrap()).as_str());

// Set the command to execute
cmd.args(["sh", "-c", get_bench_command(config).as_str()]);
cmd.args(["sh", "-c", get_bench_command(config)?.as_str()]);

// TODO: refactor and move this to the `Instrumentation` trait
if let Some(mongo_tracer) = mongo_tracer {
Expand All @@ -158,13 +163,23 @@ pub fn measure(
mod tests {
use super::*;

#[test]
fn test_get_bench_command_empty() {
let config = Config::test();
assert!(get_bench_command(&config).is_err());
assert_eq!(
get_bench_command(&config).unwrap_err().to_string(),
"The bench command is empty"
);
}

#[test]
fn test_get_bench_command_cargo() {
let config = Config {
command: "cargo codspeed bench".into(),
..Config::test()
};
assert_eq!(get_bench_command(&config), "cargo-codspeed bench");
assert_eq!(get_bench_command(&config).unwrap(), "cargo-codspeed bench");
}

#[test]
Expand All @@ -180,12 +195,10 @@ pytest tests/ --codspeed
..Config::test()
};
assert_eq!(
get_bench_command(&config),
r#"
cargo-codspeed bench --features "foo bar"
get_bench_command(&config).unwrap(),
r#"cargo-codspeed bench --features "foo bar"
pnpm vitest bench "my-app"
pytest tests/ --codspeed
"#
pytest tests/ --codspeed"#
);
}
}
19 changes: 15 additions & 4 deletions src/run/uploader/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::run::{
use crate::{prelude::*, request_client::REQUEST_CLIENT};
use async_compression::tokio::write::GzipEncoder;
use base64::{engine::general_purpose, Engine as _};
use console::style;
use tokio::io::AsyncWriteExt;
use tokio_tar::Builder;

Expand Down Expand Up @@ -48,9 +49,11 @@ async fn retrieve_upload_data(
.map(|body| body.error)
.unwrap_or(text);
bail!(
"Failed to retrieve upload data: {}\n{}",
"Failed to retrieve upload data: {}\n -> {} {}",
status,
error_message
style("Reason:").bold(),
// !!! we have to manually apply `.red()` this because the `.red()` from the logger is not applied to everything that follows the first `style()` call, for some reasons 🤷‍♂️🤷‍♂️🤷‍♂️
style(error_message).red()
);
}

Expand Down Expand Up @@ -94,6 +97,14 @@ pub async fn upload(

let upload_metadata = provider.get_upload_metadata(config, system_info, &archive_hash)?;
debug!("Upload metadata: {:#?}", upload_metadata);
info!(
"Repository {} detected\n",
style(format!(
"{}/{}",
upload_metadata.provider_metadata.owner, upload_metadata.provider_metadata.repository
))
.bold(),
);
if upload_metadata.tokenless {
let hash = upload_metadata.get_hash();
info!("CodSpeed Run Hash: \"{}\"", hash);
Expand All @@ -103,10 +114,10 @@ pub async fn upload(
let upload_data = retrieve_upload_data(config, &upload_metadata).await?;
debug!("runId: {}", upload_data.run_id);

info!("Uploading profile data...");
info!("Uploading performance data...");
debug!("Uploading {} bytes...", archive_buffer.len());
upload_archive_buffer(&upload_data, archive_buffer, &archive_hash).await?;
info!("Results uploaded.");
info!("Performance data uploaded");

Ok(UploadResult {
run_id: upload_data.run_id,
Expand Down
Loading