Skip to content

Commit

Permalink
Remove update bundle upload status call (#432)
Browse files Browse the repository at this point in the history
This is handled elsewhere now.
  • Loading branch information
gnalh authored Feb 21, 2025
1 parent e1afe34 commit 87cbfee
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 144 deletions.
41 changes: 0 additions & 41 deletions api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,47 +220,6 @@ impl ApiClient {
.call_api()
.await
}

pub async fn update_bundle_upload(
&self,
request: &message::UpdateBundleUploadRequest,
) -> anyhow::Result<message::UpdateBundleUploadResponse> {
CallApi {
action: || async {
let response = self
.trunk_client
.patch(format!("{}{}/metrics/updateBundleUpload", self.host, self.version_path_prefix))
.json(request)
.send()
.await?;

let response = status_code_help(
response,
CheckUnauthorized::Check,
CheckNotFound::Check,
|_| {
format!(
"Failed to update bundle upload status to {:#?}",
request.upload_status
)
},
)?;

response
.json::<message::UpdateBundleUploadResponse>()
.await
.context("Failed to get response body as json.")
},
log_progress_message: |time_elapsed, _| {
format!("Communicating with Trunk services is taking longer than expected. It has taken {} seconds so far.", time_elapsed.as_secs())
},
report_slow_progress_message: |time_elapsed| {
format!("Updating a bundle upload status is taking longer than {} seconds", time_elapsed.as_secs())
},
}
.call_api()
.await
}
}

#[derive(Debug, Clone, Copy)]
Expand Down
22 changes: 0 additions & 22 deletions api/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ use bundle::Test;
use context::repo::RepoUrlParts;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub enum BundleUploadStatus {
#[serde(rename = "PENDING")]
Pending,
#[serde(rename = "UPLOAD_COMPLETE")]
UploadComplete,
#[serde(rename = "UPLOAD_FAILED")]
UploadFailed,
#[serde(rename = "DRY_RUN")]
DryRun,
}

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct CreateBundleUploadRequest {
pub repo: RepoUrlParts,
Expand Down Expand Up @@ -61,16 +49,6 @@ pub struct CreateRepoRequest {
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct CreateRepoResponse {}

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct UpdateBundleUploadRequest {
pub id: String,
#[serde(rename = "uploadStatus")]
pub upload_status: BundleUploadStatus,
}

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct UpdateBundleUploadResponse {}

#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
pub struct CreateBundleUploadIntentRequest {
pub repo: RepoUrlParts,
Expand Down
9 changes: 2 additions & 7 deletions cli-tests/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn test_command_fails_with_no_junit_files_no_quarantine_successful_upload(
println!("{assert}");

let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 4);
assert_eq!(requests.len(), 3);
let mut requests_iter = requests.into_iter();

assert!(matches!(
Expand All @@ -115,11 +115,6 @@ async fn test_command_fails_with_no_junit_files_no_quarantine_successful_upload(
bundle_meta.base_props.test_command.unwrap(),
"bash -c exit 128"
);

assert!(matches!(
requests_iter.next().unwrap(),
RequestPayload::UpdateBundleUpload(..)
));
}

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -191,7 +186,7 @@ async fn test_command_succeeds_with_bundle_using_bep() {
.failure();

let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 5);
assert_eq!(requests.len(), 4);

let tar_extract_directory = assert_matches!(&requests[3], RequestPayload::S3Upload(d) => d);

Expand Down
20 changes: 6 additions & 14 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::{Arc, Mutex};
use std::{fs, io::BufReader};

use api::message::{
BundleUploadStatus, CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest,
GetQuarantineConfigRequest, GetQuarantineConfigResponse, UpdateBundleUploadRequest,
CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest,
GetQuarantineConfigRequest, GetQuarantineConfigResponse,
};
use assert_matches::assert_matches;
use axum::{extract::State, Json};
Expand Down Expand Up @@ -45,7 +45,7 @@ async fn upload_bundle() {
.failure();

let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 5);
assert_eq!(requests.len(), 4);
let mut requests_iter = requests.into_iter();

let quarantine_request = requests_iter.next().unwrap();
Expand Down Expand Up @@ -177,14 +177,6 @@ async fn upload_bundle() {
assert_eq!(bundled_file.owners, ["@user"]);
assert_eq!(bundled_file.team, None);

assert_eq!(
requests_iter.next().unwrap(),
RequestPayload::UpdateBundleUpload(UpdateBundleUploadRequest {
id: "test-bundle-upload-id".to_string(),
upload_status: BundleUploadStatus::UploadComplete
}),
);

assert!(debug_props.command_line.ends_with(
&command_builder
.build_args()
Expand Down Expand Up @@ -212,7 +204,7 @@ async fn upload_bundle_using_bep() {
.failure();

let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 5);
assert_eq!(requests.len(), 4);

let tar_extract_directory = assert_matches!(&requests[3], RequestPayload::S3Upload(d) => d);

Expand Down Expand Up @@ -268,7 +260,7 @@ async fn upload_bundle_success_status_code() {

// No quarantine request
let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 4);
assert_eq!(requests.len(), 3);

// HINT: View CLI output with `cargo test -- --nocapture`
println!("{assert}");
Expand Down Expand Up @@ -307,7 +299,7 @@ async fn upload_bundle_success_timestamp_status_code() {

// No quarantine request
let requests = state.requests.lock().unwrap().clone();
assert_eq!(requests.len(), 4);
assert_eq!(requests.len(), 3);

// HINT: View CLI output with `cargo test -- --nocapture`
println!("{assert}");
Expand Down
29 changes: 1 addition & 28 deletions cli/src/upload_command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use api::{client::ApiClient, message::BundleUploadStatus};
use api::client::ApiClient;
use bundle::{BundleMeta, BundlerUtil};
use clap::{ArgAction, Args};
use constants::EXIT_SUCCESS;
Expand Down Expand Up @@ -222,38 +222,11 @@ async fn upload_bundle(
tracing::info!("Flushed temporary tarball to {:?}", bundle_temp_file);

if no_upload {
if let Err(e) = api_client
.update_bundle_upload(&api::message::UpdateBundleUploadRequest {
id: upload.id.clone(),
upload_status: BundleUploadStatus::DryRun,
})
.await
{
tracing::warn!("{}", e);
} else {
tracing::debug!("Updated bundle upload status to DRY_RUN");
}
tracing::info!("Skipping upload.");
} else {
api_client
.put_bundle_to_s3(&upload.url, &bundle_temp_file)
.await?;

if let Err(e) = api_client
.update_bundle_upload(&api::message::UpdateBundleUploadRequest {
id: upload.id.clone(),
upload_status: BundleUploadStatus::UploadComplete,
})
.await
{
tracing::warn!("{}", e)
} else {
tracing::debug!(
"Updated bundle upload status to {:#?}",
BundleUploadStatus::UploadComplete
)
}

if exit_code == EXIT_SUCCESS {
tracing::info!("Done");
} else {
Expand Down
2 changes: 1 addition & 1 deletion test_report/tests/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn publish_test_report() {
thread_join_handle.join().unwrap();

let requests = state.requests.lock().unwrap().clone();
assert!(requests.len() == 4);
assert!(requests.len() == 3);
let tar_extract_directory = assert_matches!(&requests[2], RequestPayload::S3Upload(d) => d);
let file = fs::File::open(tar_extract_directory.join("meta.json")).unwrap();
let reader = BufReader::new(file);
Expand Down
34 changes: 3 additions & 31 deletions test_utils/src/mock_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ use std::{

use api::message::{
CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest, CreateRepoResponse,
GetQuarantineConfigRequest, GetQuarantineConfigResponse, UpdateBundleUploadRequest,
UpdateBundleUploadResponse,
GetQuarantineConfigRequest, GetQuarantineConfigResponse,
};
use axum::{
body::Bytes,
extract::State,
handler::Handler,
http::StatusCode,
response::Response,
routing::{any, patch, post, put, MethodRouter},
routing::{any, post, put, MethodRouter},
Json, Router,
};
use tempfile::tempdir;
Expand All @@ -26,7 +25,6 @@ use tokio::{net::TcpListener, spawn};
pub enum RequestPayload {
CreateRepo(CreateRepoRequest),
CreateBundleUpload(CreateBundleUploadRequest),
UpdateBundleUpload(UpdateBundleUploadRequest),
GetQuarantineBulkTestStatus(GetQuarantineConfigRequest),
S3Upload(PathBuf),
}
Expand All @@ -43,7 +41,6 @@ pub struct MockServerBuilder {
create_bundle_handler: MethodRouter<SharedMockServerState>,
get_quarantining_config_handler: MethodRouter<SharedMockServerState>,
s3_upload_handler: MethodRouter<SharedMockServerState>,
update_bundle_handler: MethodRouter<SharedMockServerState>,
}

impl MockServerBuilder {
Expand All @@ -53,7 +50,6 @@ impl MockServerBuilder {
create_bundle_handler: post(create_bundle_handler),
get_quarantining_config_handler: post(get_quarantining_config_handler),
s3_upload_handler: put(s3_upload_handler),
update_bundle_handler: patch(update_bundle_handler),
}
}

Expand Down Expand Up @@ -89,14 +85,6 @@ impl MockServerBuilder {
self.s3_upload_handler = put(handler);
}

pub fn set_update_bundle_handler<H, T>(&mut self, handler: H)
where
H: Handler<T, SharedMockServerState>,
T: 'static,
{
self.update_bundle_handler = patch(handler);
}

/// Mock server spawned in a new thread.
pub async fn spawn_mock_server(self) -> SharedMockServerState {
let listener = TcpListener::bind("localhost:0").await.unwrap();
Expand All @@ -115,8 +103,7 @@ impl MockServerBuilder {
"/v1/metrics/getQuarantineConfig",
self.get_quarantining_config_handler,
)
.route("/s3upload", self.s3_upload_handler)
.route("/v1/metrics/updateBundleUpload", self.update_bundle_handler);
.route("/s3upload", self.s3_upload_handler);

app = app.route(
"/*rest",
Expand Down Expand Up @@ -182,21 +169,6 @@ pub async fn create_bundle_handler(
})
}

#[axum::debug_handler]
pub async fn update_bundle_handler(
State(state): State<SharedMockServerState>,
Json(update_bundle_upload_request): Json<UpdateBundleUploadRequest>,
) -> Json<UpdateBundleUploadResponse> {
state
.requests
.lock()
.unwrap()
.push(RequestPayload::UpdateBundleUpload(
update_bundle_upload_request,
));
Json(UpdateBundleUploadResponse {})
}

#[axum::debug_handler]
pub async fn get_quarantining_config_handler(
State(state): State<SharedMockServerState>,
Expand Down

0 comments on commit 87cbfee

Please sign in to comment.