Skip to content

ref(proguard): Use existing chunked upload logic #2318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion src/commands/upload_proguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
Expand Down
9 changes: 6 additions & 3 deletions src/utils/chunks/upload.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -201,8 +204,8 @@ where

if chunks_missing {
anyhow::bail!(
"Some uploaded files are now missing on the server. Please retry by running \
`sentry-cli upload-dif` again. If this problem persists, please report a bug.",
"Some uploaded files are now missing on the server. Please try rerunning \
the command. If this problem persists, please report a bug.",
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils/proguard/mapping.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::fmt::{Display, Formatter, Result as FmtResult};

use symbolic::common::{ByteView, DebugId};
use thiserror::Error;
Expand Down Expand Up @@ -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)
}
}
62 changes: 11 additions & 51 deletions src/utils/proguard/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<()> {
Expand All @@ -37,48 +31,14 @@ pub fn chunk_upload(
.map(|mapping| Chunked::from(mapping, chunk_upload_options.chunk_size as usize))
.collect::<Result<Vec<_>>>()?;

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::<Vec<_>>(),
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::<Result<Vec<_>>>()?
.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.")
}
Loading