Skip to content

Commit

Permalink
Include the client version in BundleUploads
Browse files Browse the repository at this point in the history
Summary:

Adding client version information for upload bundles will allow
us to help Flaky Test users who may be using outdated versions
of the Analytics CLI.

If a user is running into an old bug, we can direct them to update
their tooling version. Should help with onboarding.


Closes TRUNK-12763
  • Loading branch information
matt-fff committed Sep 19, 2024
1 parent 0a24606 commit 24c9118
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 2 additions & 0 deletions cli/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub async fn get_bundle_upload_location(
api_token: &str,
org_slug: &str,
repo: &Repo,
client_version: &str,
) -> anyhow::Result<Option<BundleUploadLocation>> {
let client = reqwest::Client::new();
let resp = match client
Expand All @@ -63,6 +64,7 @@ pub async fn get_bundle_upload_location(
.json(&CreateBundleUploadRequest {
org_url_slug: org_slug.to_owned(),
repo: repo.clone(),
client_version: client_version.to_owned(),
})
.send()
.await
Expand Down
22 changes: 14 additions & 8 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,18 @@ async fn run_upload(

let envs = EnvScanner::scan_env();
let os_info: String = env::consts::OS.to_string();

let cli_version = format!(
"cargo={} git={} rustc={}",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA"),
env!("VERGEN_RUSTC_SEMVER")
);
let meta = BundleMeta {
version: META_VERSION.to_string(),
cli_version: format!(
"cargo={} git={} rustc={}",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA"),
env!("VERGEN_RUSTC_SEMVER")
),
org: org_url_slug.clone(),
repo: repo.clone(),
cli_version: cli_version.clone(),
tags,
file_sets,
envs,
Expand Down Expand Up @@ -279,8 +281,12 @@ async fn run_upload(
bundler.make_tarball(&bundle_time_file)?;
log::info!("Flushed temporary tarball to {:?}", bundle_time_file);


let client_version = format!("trunk-analytics-cli {}", cli_version);
let upload_op = Retry::spawn(default_delay(), || {
get_bundle_upload_location(&api_address, &token, &org_url_slug, &repo.repo)
get_bundle_upload_location(
&api_address, &token, &org_url_slug, &repo.repo, &client_version
)
})
.await?;

Expand Down Expand Up @@ -447,4 +453,4 @@ fn setup_logger() -> anyhow::Result<()> {
}
builder.init();
Ok(())
}
}
2 changes: 2 additions & 0 deletions cli/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub struct CreateBundleUploadRequest {
pub repo: Repo,
#[serde(rename = "orgUrlSlug")]
pub org_url_slug: String,
#[serde(rename = "clientVersion")]
pub client_version: String,
}

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
Expand Down
24 changes: 15 additions & 9 deletions cli/tests/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tempfile::tempdir;
use test_utils::mock_git_repo::setup_repo_with_commit;
use test_utils::mock_server::{spawn_mock_server, RequestPayload};
use trunk_analytics_cli::types::{
BundleMeta, CreateBundleUploadRequest, CreateRepoRequest, FileSetType,
BundleMeta, CreateRepoRequest, FileSetType,
GetQuarantineBulkTestStatusRequest, Repo,
};

Expand Down Expand Up @@ -72,17 +72,23 @@ async fn upload_bundle() {
})
);

assert_eq!(
requests_iter.next().unwrap(),
RequestPayload::CreateBundleUpload(CreateBundleUploadRequest {
repo: Repo {
let request = requests_iter.next().unwrap();
if let RequestPayload::CreateBundleUpload(upload_request) = request {
assert_eq!(
upload_request.repo,
Repo {
host: String::from("github.com"),
owner: String::from("trunk-io"),
name: String::from("analytics-cli"),
},
org_url_slug: String::from("test-org"),
})
);
}
);
assert_eq!(upload_request.org_url_slug, String::from("test-org"));
assert!(upload_request.client_version.starts_with("trunk-analytics-cli cargo="));
assert!(upload_request.client_version.contains(" git="));
assert!(upload_request.client_version.contains(" rustc="));
} else {
panic!("Expected CreateBundleUpload request, got {:?}", request);
}

let tar_extract_directory =
assert_matches!(requests_iter.next().unwrap(), RequestPayload::S3Upload(d) => d);
Expand Down

0 comments on commit 24c9118

Please sign in to comment.