From 8c4d12641326163ff05daa3b68186477df18ed39 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 5 Dec 2024 15:11:50 +0100 Subject: [PATCH] ref(proguard): Use existing chunked upload logic Use the existing chunked upload logic (already used for DIFs) when chunked-uploading Proguard mappings. Closes #2195, #2196 --- src/commands/upload_proguard.rs | 2 +- src/utils/chunks/upload.rs | 5 ++- src/utils/proguard/mapping.rs | 7 ++++ src/utils/proguard/upload.rs | 62 ++++++--------------------------- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/src/commands/upload_proguard.rs b/src/commands/upload_proguard.rs index 3b441a9064..e41080165f 100644 --- a/src/commands/upload_proguard.rs +++ b/src/commands/upload_proguard.rs @@ -211,7 +211,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { }) })?; - proguard::chunk_upload(&mappings, &chunk_upload_options, &org, &project)?; + proguard::chunk_upload(&mappings, chunk_upload_options, &org, &project)?; } else { if mappings.is_empty() && matches.get_flag("require_one") { println!(); diff --git a/src/utils/chunks/upload.rs b/src/utils/chunks/upload.rs index 9e396c44d1..43f8fbb7b2 100644 --- a/src/utils/chunks/upload.rs +++ b/src/utils/chunks/upload.rs @@ -1,4 +1,7 @@ -use std::{collections::BTreeMap, fmt::Display, thread, time::Instant}; +use std::collections::BTreeMap; +use std::fmt::Display; +use std::thread; +use std::time::Instant; use anyhow::Result; use indicatif::ProgressStyle; diff --git a/src/utils/proguard/mapping.rs b/src/utils/proguard/mapping.rs index 3179786fd3..7f4561c9b8 100644 --- a/src/utils/proguard/mapping.rs +++ b/src/utils/proguard/mapping.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::fmt::{Display, Formatter, Result as FmtResult}; use symbolic::common::{ByteView, DebugId}; use thiserror::Error; @@ -76,3 +77,9 @@ impl Assemblable for ProguardMapping<'_> { None } } + +impl Display for ProguardMapping<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + write!(f, "{} (Proguard mapping)", self.uuid) + } +} diff --git a/src/utils/proguard/upload.rs b/src/utils/proguard/upload.rs index bf7909a263..94a20a254f 100644 --- a/src/utils/proguard/upload.rs +++ b/src/utils/proguard/upload.rs @@ -4,20 +4,14 @@ //! Proguard mappings, while we work on a more permanent solution, which will //! work for all different types of debug files. -use std::thread; -use std::time::{Duration, Instant}; +use std::time::Duration; use anyhow::Result; -use indicatif::ProgressStyle; -use crate::api::{Api, ChunkServerOptions, ChunkedFileState}; -use crate::utils::chunks; -use crate::utils::chunks::Chunked; +use crate::api::ChunkServerOptions; +use crate::utils::chunks::{upload_chunked_objects, ChunkOptions, Chunked}; use crate::utils::proguard::ProguardMapping; -/// How often to poll the server for the status of the assembled mappings. -const ASSEMBLE_POLL_INTERVAL: Duration = Duration::from_secs(1); - /// How long to wait for the server to assemble the mappings before giving up. // 120 seconds was chosen somewhat arbitrarily, but in my testing, assembly // usually was almost instantaneous, so this should probably be enough time. @@ -28,7 +22,7 @@ const ASSEMBLE_POLL_TIMEOUT: Duration = Duration::from_secs(120); /// Returns an error if the mappings fail to assemble, or if the timeout is reached. pub fn chunk_upload( mappings: &[ProguardMapping<'_>], - chunk_upload_options: &ChunkServerOptions, + chunk_upload_options: ChunkServerOptions, org: &str, project: &str, ) -> Result<()> { @@ -37,48 +31,14 @@ pub fn chunk_upload( .map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize)) .collect::>>()?; - let progress_style = ProgressStyle::default_bar().template( - "Uploading Proguard mappings...\ - \n{wide_bar} {bytes}/{total_bytes} ({eta})", - ); - - let chunks = chunked_mappings - .iter() - .flat_map(|mapping| mapping.iter_chunks()); - - chunks::upload_chunks( - &chunks.collect::>(), - chunk_upload_options, - progress_style, - )?; + let options = + ChunkOptions::new(chunk_upload_options, org, project).with_max_wait(ASSEMBLE_POLL_TIMEOUT); - println!("Waiting for server to assemble uploaded mappings..."); + let (_, has_processing_errors) = upload_chunked_objects(&chunked_mappings, options)?; - let assemble_request = chunked_mappings.iter().collect(); - let start = Instant::now(); - while Instant::now().duration_since(start) < ASSEMBLE_POLL_TIMEOUT { - let all_assembled = Api::current() - .authenticated()? - .assemble_difs(org, project, &assemble_request)? - .values() - .map(|response| match response.state { - ChunkedFileState::Error => anyhow::bail!("Error: {response:?}"), - ChunkedFileState::NotFound => anyhow::bail!("File not found: {response:?}"), - ChunkedFileState::Ok | ChunkedFileState::Created | ChunkedFileState::Assembling => { - Ok(response) - } - }) - .collect::>>()? - .iter() - .all(|response| matches!(response.state, ChunkedFileState::Ok)); - - if all_assembled { - println!("Server finished assembling mappings."); - return Ok(()); - } - - thread::sleep(ASSEMBLE_POLL_INTERVAL); + if has_processing_errors { + Err(anyhow::anyhow!("Some symbols did not process correctly")) + } else { + Ok(()) } - - anyhow::bail!("Timed out waiting for server to assemble uploaded mappings.") }