From 87444d59cd35c01ea2ecbb9836e900f64434924c Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 4 Dec 2024 11:40:19 +0100 Subject: [PATCH] ref(proguard): Use `Chunked` for proguard upload --- src/utils/chunks/types.rs | 13 +++++++++ src/utils/proguard/mapping.rs | 16 +++++++++- src/utils/proguard/upload.rs | 55 ++++++----------------------------- 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/utils/chunks/types.rs b/src/utils/chunks/types.rs index cbd56e5926..76536335d4 100644 --- a/src/utils/chunks/types.rs +++ b/src/utils/chunks/types.rs @@ -94,6 +94,19 @@ where } } +impl Assemblable for &T +where + T: Assemblable, +{ + fn name(&self) -> Cow { + (*self).name() + } + + fn debug_id(&self) -> Option { + (*self).debug_id() + } +} + impl Assemblable for Chunked where T: Assemblable, diff --git a/src/utils/proguard/mapping.rs b/src/utils/proguard/mapping.rs index 10c58edd76..b9bb44e512 100644 --- a/src/utils/proguard/mapping.rs +++ b/src/utils/proguard/mapping.rs @@ -1,7 +1,11 @@ -use symbolic::common::ByteView; +use std::borrow::Cow; + +use symbolic::common::{ByteView, DebugId}; use thiserror::Error; use uuid::Uuid; +use crate::utils::chunks::Assemblable; + #[derive(Debug, Error)] pub enum ProguardMappingError { #[error("Proguard mapping does not contain line information")] @@ -62,3 +66,13 @@ impl AsRef<[u8]> for ProguardMapping<'_> { self.bytes.as_ref() } } + +impl Assemblable for ProguardMapping<'_> { + fn name(&self) -> Cow { + format!("proguard/{}.txt", self.uuid).into() + } + + fn debug_id(&self) -> Option { + None + } +} diff --git a/src/utils/proguard/upload.rs b/src/utils/proguard/upload.rs index d62073e0a8..5a1feda6e5 100644 --- a/src/utils/proguard/upload.rs +++ b/src/utils/proguard/upload.rs @@ -4,17 +4,15 @@ //! Proguard mappings, while we work on a more permanent solution, which will //! work for all different types of debug files. -use std::borrow::Cow; use std::thread; use std::time::{Duration, Instant}; use anyhow::Result; use indicatif::ProgressStyle; -use sha1_smol::Digest; -use crate::api::{Api, ChunkUploadOptions, ChunkedDifRequest, ChunkedFileState}; -use crate::utils::chunks::{self, Chunk}; -use crate::utils::fs::get_sha1_checksums; +use crate::api::{Api, ChunkUploadOptions, ChunkedFileState}; +use crate::utils::chunks; +use crate::utils::chunks::Chunked; use crate::utils::proguard::ProguardMapping; /// How often to poll the server for the status of the assembled mappings. @@ -25,43 +23,6 @@ const ASSEMBLE_POLL_INTERVAL: Duration = Duration::from_secs(1); // usually was almost instantaneous, so this should probably be enough time. const ASSEMBLE_POLL_TIMEOUT: Duration = Duration::from_secs(120); -struct ChunkedMapping { - raw_data: Vec, - hash: Digest, - chunk_hashes: Vec, - file_name: String, - chunk_size: usize, -} - -impl ChunkedMapping { - fn try_from_mapping(mapping: &ProguardMapping, chunk_size: u64) -> Result { - let raw_data = mapping.as_ref().to_vec(); - let file_name = format!("/proguard/{}.txt", mapping.uuid()); - - let (hash, chunk_hashes) = get_sha1_checksums(&raw_data, chunk_size as usize)?; - Ok(Self { - raw_data, - hash, - chunk_hashes, - file_name, - chunk_size: chunk_size.try_into()?, - }) - } - - fn chunks(&self) -> impl Iterator> { - self.raw_data - .chunks(self.chunk_size) - .zip(self.chunk_hashes.iter()) - .map(|(chunk, hash)| Chunk((*hash, chunk))) - } -} - -impl<'a> From<&'a ChunkedMapping> for ChunkedDifRequest<'a> { - fn from(value: &'a ChunkedMapping) -> Self { - ChunkedDifRequest::new(Cow::from(&value.file_name), &value.chunk_hashes, value.hash) - } -} - /// Uploads a set of Proguard mappings to Sentry. /// Blocks until the mappings have been assembled (up to ASSEMBLE_POLL_TIMEOUT). /// Returns an error if the mappings fail to assemble, or if the timeout is reached. @@ -71,17 +32,19 @@ pub fn chunk_upload( org: &str, project: &str, ) -> Result<()> { - let chunked_mappings: Vec = mappings + let chunked_mappings = mappings .iter() - .map(|mapping| ChunkedMapping::try_from_mapping(mapping, chunk_upload_options.chunk_size)) - .collect::>()?; + .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.chunks()); + let chunks = chunked_mappings + .iter() + .flat_map(|mapping| mapping.iter_chunks()); chunks::upload_chunks( &chunks.collect::>(),