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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.DS_Store
samples
5 changes: 3 additions & 2 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 @@ -31,6 +31,7 @@ url = "2.4.1"
sha256 = "1.4.0"
tokio = { version = "1", features = ["macros", "rt"] }
tokio-tar = "0.3.1"
tokio-util = "0.7.16"
md5 = "0.7.0"
base64 = "0.21.0"
async-compression = { version = "0.4.5", features = ["tokio", "gzip"] }
Expand Down
6 changes: 6 additions & 0 deletions src/request_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ lazy_static! {
ExponentialBackoff::builder().build_with_max_retries(UPLOAD_RETRY_COUNT)
))
.build();

// Client without retry middleware for streaming uploads (can't be cloned)
pub static ref STREAMING_CLIENT: reqwest::Client = ClientBuilder::new()
.user_agent("codspeed-runner")
.build()
.unwrap();
Comment on lines +19 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to find a way to have the retries even when streaming the body

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen in https://github.com/TrueLayer/reqwest-middleware/pull/51/files?w=1#diff-474abab8d90fcf4a3811b4faa74eff00faa8c9c190c9fd2e47991de8b2f4d64eR38-R49, it is not possible out of the box.
We will need to create a middleware manually that implements streaming. I will take a look

}
11 changes: 7 additions & 4 deletions src/run/run_environment/local/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::run::config::RepositoryOverride;
use crate::run::helpers::{GitRemote, parse_git_remote};
use crate::run::run_environment::{RunEnvironment, RunPart};
use crate::run::runner::ExecutorName;
use crate::run::uploader::{Runner, UploadMetadata};
use crate::run::uploader::{
LATEST_UPLOAD_METADATA_VERSION, ProfileArchive, Runner, UploadMetadata,
};
use crate::run::{
config::Config,
helpers::find_repository_root,
Expand Down Expand Up @@ -147,18 +149,19 @@ impl RunEnvironmentProvider for LocalProvider {
&self,
config: &Config,
system_info: &SystemInfo,
archive_hash: &str,
profile_archive: &ProfileArchive,
executor_name: ExecutorName,
) -> Result<UploadMetadata> {
let run_environment_metadata = self.get_run_environment_metadata()?;

Ok(UploadMetadata {
version: Some(6),
version: Some(LATEST_UPLOAD_METADATA_VERSION),
tokenless: config.token.is_none(),
repository_provider: self.get_repository_provider(),
commit_hash: run_environment_metadata.ref_.clone(),
run_environment_metadata,
profile_md5: archive_hash.into(),
profile_md5: profile_archive.hash.clone(),
profile_encoding: profile_archive.content.encoding(),
runner: Runner {
name: "codspeed-runner".into(),
version: crate::VERSION.into(),
Expand Down
11 changes: 7 additions & 4 deletions src/run/run_environment/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::prelude::*;
use crate::run::check_system::SystemInfo;
use crate::run::config::Config;
use crate::run::runner::ExecutorName;
use crate::run::uploader::{Runner, UploadMetadata};
use crate::run::uploader::{
LATEST_UPLOAD_METADATA_VERSION, ProfileArchive, Runner, UploadMetadata,
};

use super::interfaces::{RepositoryProvider, RunEnvironment, RunEnvironmentMetadata, RunPart};

Expand Down Expand Up @@ -66,19 +68,20 @@ pub trait RunEnvironmentProvider {
&self,
config: &Config,
system_info: &SystemInfo,
archive_hash: &str,
profile_archive: &ProfileArchive,
executor_name: ExecutorName,
) -> Result<UploadMetadata> {
let run_environment_metadata = self.get_run_environment_metadata()?;

let commit_hash = get_commit_hash(&run_environment_metadata.repository_root_path)?;

Ok(UploadMetadata {
version: Some(6),
version: Some(LATEST_UPLOAD_METADATA_VERSION),
tokenless: config.token.is_none(),
repository_provider: self.get_repository_provider(),
run_environment_metadata,
profile_md5: archive_hash.into(),
profile_md5: profile_archive.hash.clone(),
profile_encoding: profile_archive.content.encoding(),
commit_hash,
runner: Runner {
name: "codspeed-runner".into(),
Expand Down
3 changes: 3 additions & 0 deletions src/run/uploader/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use crate::run::{
runner::ExecutorName,
};

pub const LATEST_UPLOAD_METADATA_VERSION: u32 = 7;

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UploadMetadata {
pub repository_provider: RepositoryProvider,
pub version: Option<u32>,
pub tokenless: bool,
pub profile_md5: String,
pub profile_encoding: Option<String>,
pub runner: Runner,
pub run_environment: RunEnvironment,
pub run_part: Option<RunPart>,
Expand Down
2 changes: 2 additions & 0 deletions src/run/uploader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod interfaces;
mod profile_archive;
mod upload;
mod upload_metadata;

pub use interfaces::*;
pub use profile_archive::ProfileArchive;
pub use upload::upload;
71 changes: 71 additions & 0 deletions src/run/uploader/profile_archive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use base64::{Engine, engine::general_purpose};

use crate::prelude::*;
use std::path::PathBuf;

#[derive(Debug)]
pub struct ProfileArchive {
pub hash: String,
pub content: ProfileArchiveContent,
}

#[derive(Debug)]
pub enum ProfileArchiveContent {
CompressedInMemory { data: Vec<u8> },
UncompressedOnDisk { path: PathBuf },
}

impl ProfileArchive {
pub fn new_compressed_in_memory(data: Vec<u8>) -> Self {
let hash = general_purpose::STANDARD.encode(md5::compute(&data).0);
ProfileArchive {
hash,
content: ProfileArchiveContent::CompressedInMemory { data },
}
}

pub fn new_uncompressed_on_disk(path: PathBuf) -> Result<Self> {
let metadata = std::fs::metadata(&path)?;
if !metadata.is_file() {
return Err(anyhow!("The provided path is not a file"));
}
let mut file = std::fs::File::open(&path)?;
let mut buffer = Vec::new();
use std::io::Read;
file.read_to_end(&mut buffer)?;
let hash = general_purpose::STANDARD.encode(md5::compute(&buffer).0);
Ok(ProfileArchive {
hash,
content: ProfileArchiveContent::UncompressedOnDisk { path },
})
}
}

impl ProfileArchiveContent {
pub async fn size(&self) -> Result<u64> {
match &self {
ProfileArchiveContent::CompressedInMemory { data } => Ok(data.len() as u64),
ProfileArchiveContent::UncompressedOnDisk { path } => {
let metadata = tokio::fs::metadata(path).await?;
Ok(metadata.len())
}
}
}

pub fn encoding(&self) -> Option<String> {
match self {
ProfileArchiveContent::CompressedInMemory { .. } => Some("gzip".to_string()),
_ => None,
}
}
}

impl Drop for ProfileArchiveContent {
fn drop(&mut self) {
if let ProfileArchiveContent::UncompressedOnDisk { path } = self {
if path.exists() {
let _ = std::fs::remove_file(path);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ expression: upload_metadata
---
{
"repositoryProvider": "GITHUB",
"version": 6,
"version": 7,
"tokenless": true,
"profileMd5": "jp/k05RKuqP3ERQuIIvx4Q==",
"profileEncoding": "gzip",
"runner": {
"name": "codspeed-runner",
"version": "2.1.0",
Expand Down
Loading