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 23, 2024
1 parent 0a24606 commit 6512941
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 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
23 changes: 16 additions & 7 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,15 @@ 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
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
25 changes: 14 additions & 11 deletions cli/tests/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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,
GetQuarantineBulkTestStatusRequest, Repo,
BundleMeta, CreateRepoRequest, FileSetType, GetQuarantineBulkTestStatusRequest, Repo,
};

mod test_utils;
Expand Down Expand Up @@ -72,17 +71,21 @@ async fn upload_bundle() {
})
);

let upload_request = assert_matches!(requests_iter.next().unwrap(), RequestPayload::CreateBundleUpload(ur) => ur);
assert_eq!(
requests_iter.next().unwrap(),
RequestPayload::CreateBundleUpload(CreateBundleUploadRequest {
repo: Repo {
host: String::from("github.com"),
owner: String::from("trunk-io"),
name: String::from("analytics-cli"),
},
org_url_slug: String::from("test-org"),
})
upload_request.repo,
Repo {
host: String::from("github.com"),
owner: String::from("trunk-io"),
name: String::from("analytics-cli"),
}
);
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="));

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

0 comments on commit 6512941

Please sign in to comment.