Skip to content

Commit

Permalink
Update Axum & deps, Split LTO into separate profile (#1344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem authored Jan 9, 2024
1 parent acca94b commit 2d643e8
Show file tree
Hide file tree
Showing 16 changed files with 606 additions and 547 deletions.
1,024 changes: 546 additions & 478 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ default-members = ["crates/symbolicator", "crates/symbolicli", "crates/symsorter
[profile.release]
# For release builds, we do want line-only debug information to be able to symbolicate panic stack traces.
debug = 1

[profile.release-lto]
inherits = "release"
codegen-units = 1
lto = true

Expand Down
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ ENV RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=/usr/bin/mold"
COPY --from=symbolicator-planner /work/recipe.json recipe.json

# Build only the dependencies identified in the `symbolicator-planner` image
RUN cargo chef cook --release --features=${SYMBOLICATOR_FEATURES} --recipe-path recipe.json
RUN cargo chef cook --profile release-lto --features=${SYMBOLICATOR_FEATURES} --recipe-path recipe.json

COPY . .
RUN git update-index --skip-worktree $(git status | grep deleted | awk '{print $2}')
RUN cargo build -p symbolicator --release --features=${SYMBOLICATOR_FEATURES}
RUN cp target/release/symbolicator target/release/symbolicator.debug \
&& objcopy --strip-debug --strip-unneeded target/release/symbolicator \
&& objcopy --add-gnu-debuglink target/release/symbolicator target/release/symbolicator.debug \
&& cp ./target/release/symbolicator /usr/local/bin \
&& zip /opt/symbolicator-debug.zip target/release/symbolicator.debug
RUN cargo build -p symbolicator --profile release-lto --features=${SYMBOLICATOR_FEATURES}
RUN cp target/release-lto/symbolicator target/release-lto/symbolicator.debug \
&& objcopy --strip-debug --strip-unneeded target/release-lto/symbolicator \
&& objcopy --add-gnu-debuglink target/release-lto/symbolicator target/release-lto/symbolicator.debug \
&& cp ./target/release-lto/symbolicator /usr/local/bin \
&& zip /opt/symbolicator-debug.zip target/release-lto/symbolicator.debug

COPY --from=sentry-cli /bin/sentry-cli /bin/sentry-cli
RUN sentry-cli --version \
&& SOURCE_BUNDLE="$(sentry-cli difutil bundle-sources ./target/release/symbolicator.debug)" \
&& SOURCE_BUNDLE="$(sentry-cli difutil bundle-sources ./target/release-lto/symbolicator.debug)" \
&& mv "$SOURCE_BUNDLE" /opt/symbolicator.src.zip

#############################################
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-crash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ publish = false
[dependencies]

[build-dependencies]
bindgen = "0.68.1"
bindgen = "0.69.1"
cmake = { version = "0.1.46" }
2 changes: 1 addition & 1 deletion crates/symbolicator-crash/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {

let bindings = bindgen::Builder::default()
.header("sentry-native/include/sentry.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");

Expand Down
11 changes: 9 additions & 2 deletions crates/symbolicator-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ humantime = "2.1.0"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
regex = "1.5.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
reqwest = { version = "0.11.0", features = [
"gzip",
"brotli",
"deflate",
"json",
"stream",
"trust-dns",
] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
sha2 = "0.10.6"
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ minidump-unwind = "0.19.1"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.18.0"
regex = "1.5.5"
sentry = { version = "0.31.7", features = ["tracing"] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
symbolic = { version = "12.7.1", features = ["cfi", "common-serde", "debuginfo", "demangle", "symcache", "il2cpp", "ppdb"] }
symbolicator-service = { path = "../symbolicator-service" }
Expand Down
6 changes: 3 additions & 3 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ aws-config = { version = "1.0.1", features = ["behavior-version-latest"] }
aws-credential-types = { version = "1.0.1", features = ["hardcoded-credentials"] }
aws-sdk-s3 = "1.4.0"
aws-types = "1.0.1"
cadence = "0.29.0"
cadence = "1.0.0"
chrono = { version = "0.4.19", features = ["serde"] }
filetime = "0.2.16"
flate2 = "1.0.23"
futures = "0.3.12"
gcp_auth = "0.9.0"
gcp_auth = "0.10.0"
humantime = "2.1.0"
humantime-serde = "1.1.1"
idna = "0.5.0"
Expand All @@ -29,7 +29,7 @@ moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
rand = "0.8.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
sentry = { version = "0.32.1", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
serde_yaml = "0.9.14"
Expand Down
4 changes: 1 addition & 3 deletions crates/symbolicator-service/src/caching/cache_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ impl CacheKeyBuilder {
/// Finalize the [`CacheKey`].
pub fn build(self) -> CacheKey {
let hash = Sha256::digest(&self.metadata);
// FIXME: `sha2` should really adopt const generics, this is such a pain right now
let hash = <[u8; 32]>::try_from(hash).expect("sha256 outputs 32 bytes");

CacheKey {
metadata: self.metadata.into(),
hash,
hash: hash.into(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/symbolicator-stress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2021"

[dependencies]
anyhow = "1.0.57"
axum = "0.6.10"
axum = "0.7.2"
clap = { version = "4.3.2", features = ["derive"] }
futures = "0.3.12"
humantime = "2.0.1"
sentry = { version = "0.31.7", features = ["anyhow", "debug-images", "tracing"] }
sentry = { version = "0.32.1", features = ["anyhow", "debug-images", "tracing"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
serde_yaml = "0.9.14"
Expand Down
8 changes: 4 additions & 4 deletions crates/symbolicator-stress/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ pub fn init(config: Config) -> Guard {
if config.sentry {
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
let listener = TcpListener::bind(addr).unwrap();
listener.set_nonblocking(true).unwrap();
let socket = listener.local_addr().unwrap();

guard.sentry_server = Some(Box::pin(async move {
async fn ok() -> &'static str {
"OK"
}
use axum::handler::HandlerWithoutStateExt;
let server = axum::Server::from_tcp(listener)
.unwrap()
.serve(ok.into_make_service());
server.await.unwrap()

let listener = tokio::net::TcpListener::from_std(listener).unwrap();
axum::serve(listener, ok.into_make_service()).await.unwrap();
}));

let dsn = format!("http://[email protected]:{}/1234", socket.port());
Expand Down
4 changes: 2 additions & 2 deletions crates/symbolicator-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT"

[dependencies]
axum = "0.6.10"
axum = "0.7.2"
humantime = "2.0.1"
insta = { version = "1.18.0", features = ["redactions", "yaml"] }
regex = "1.5.5"
Expand All @@ -16,5 +16,5 @@ serde_json = "1.0.94"
symbolicator-sources = { path = "../symbolicator-sources" }
tempfile = "3.2.0"
tokio = { version = "1.26.0", features = ["rt", "macros", "fs"] }
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
tower-http = { version = "0.5.0", features = ["fs", "trace"] }
tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] }
16 changes: 9 additions & 7 deletions crates/symbolicator-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
//! HTTP connections.
use std::collections::BTreeMap;
use std::net::SocketAddr;
use std::net::{SocketAddr, TcpListener};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};

use axum::http::StatusCode;
use axum::response::{IntoResponse, Redirect};
use axum::routing::{get, get_service};
use axum::{extract, Json};
use axum::{middleware, Router};
use reqwest::{StatusCode, Url};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;
use tower_http::services::ServeDir;
Expand Down Expand Up @@ -179,7 +180,7 @@ impl Server {

let hitcounter = {
let hits = hits.clone();
move |extract::OriginalUri(uri), req, next: middleware::Next<_>| {
move |extract::OriginalUri(uri), req, next: middleware::Next| {
let hits = hits.clone();
async move {
{
Expand All @@ -196,12 +197,13 @@ impl Server {
let router = router.layer(middleware::from_fn(hitcounter));

let addr = SocketAddr::from(([127, 0, 0, 1], 0));

let server = axum::Server::bind(&addr).serve(router.into_make_service());
let socket = server.local_addr();
let listener = TcpListener::bind(addr).unwrap();
listener.set_nonblocking(true).unwrap();
let socket = listener.local_addr().unwrap();

let handle = tokio::spawn(async move {
server.await.unwrap();
let listener = tokio::net::TcpListener::from_std(listener).unwrap();
axum::serve(listener, router).await.unwrap();
});

Self {
Expand Down
6 changes: 3 additions & 3 deletions crates/symbolicator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ https = ["axum-server/tls-rustls", "symbolicator-service/https"]

[dependencies]
anyhow = "1.0.57"
axum = { version = "0.6.10", features = ["multipart"] }
axum-server = "0.5.1"
axum = { version = "0.7.2", features = ["multipart"] }
axum-server = "0.6.0"
clap = { version = "4.3.2", features = ["derive"] }
console = "0.15.0"
futures = "0.3.12"
hostname = "0.3.1"
sentry = { version = "0.31.7", features = ["anyhow", "debug-images", "tracing", "tower", "tower-http"] }
sentry = { version = "0.32.1", features = ["anyhow", "debug-images", "tracing", "tower", "tower-http"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
serde_json = "1.0.81"
symbolic = "12.7.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator/src/endpoints/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub async fn proxy_symstore_request(
}

let bytes = Cursor::new(data);
Ok(response.body(Body::wrap_stream(tokio_util::io::ReaderStream::new(bytes)))?)
Ok(response.body(Body::from_stream(tokio_util::io::ReaderStream::new(bytes)))?)
}

#[cfg(test)]
Expand Down
43 changes: 12 additions & 31 deletions crates/symbolicator/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum_server::Handle;
#[cfg(feature = "https")]
use std::fs::read;
use std::net::SocketAddr;
use std::net::TcpListener;
#[cfg(feature = "https")]
use std::path::PathBuf;

Expand Down Expand Up @@ -56,50 +56,31 @@ pub fn run(config: Config) -> Result<()> {

let svc = endpoints::create_app(service).into_make_service();

let handle_http = Handle::new();
let socket_http = config.bind.parse::<SocketAddr>()?;
let socket_http = TcpListener::bind(config.bind.parse::<SocketAddr>()?)?;
let local_addr = socket_http.local_addr()?;
tracing::info!("Starting HTTP server on {}", local_addr);

#[allow(clippy::redundant_clone)] // we need `svc` for the https case below
let server_http = axum_server::bind(socket_http)
.handle(handle_http.clone())
.serve(svc.clone());
let server_http = axum_server::from_tcp(socket_http).serve(svc.clone());
servers.push(Box::pin(server_http));

let listening_http = async move {
if let Some(local_addr) = handle_http.listening().await {
tracing::info!("Starting HTTP server on {}", local_addr);
} else {
panic!("Unable to listen on HTTP port");
}
Ok(())
};
servers.push(Box::pin(listening_http));

#[cfg(feature = "https")]
if let Some(ref bind_str) = config.bind_https {
let handle_https = Handle::new();
let https_conf = match config.server_config.https {
None => panic!("Need HTTPS config"),
Some(ref conf) => conf,
};
let socket_https = bind_str.parse::<SocketAddr>()?;
let socket_https = TcpListener::bind(bind_str.parse::<SocketAddr>()?)?;
let local_addr = socket_https.local_addr()?;
tracing::info!("Starting HTTPS server on {}", local_addr);

let certificate = read_pem_file(&https_conf.certificate_path)?;
let key = read_pem_file(&https_conf.key_path)?;
let tls_config =
web_pool.block_on(async { RustlsConfig::from_pem(certificate, key).await })?;
let server_https = axum_server::bind_rustls(socket_https, tls_config)
.handle(handle_https.clone())
.serve(svc);
servers.push(Box::pin(server_https));

let listening_https = async move {
if let Some(local_addr) = handle_https.listening().await {
tracing::info!("Starting HTTPS server on {}", local_addr);
} else {
panic!("Unable to listen on HTTPS port");
}
Ok(())
};
servers.push(Box::pin(listening_https));
let server_https = axum_server::from_tcp_rustls(socket_https, tls_config).serve(svc);
servers.push(Box::pin(server_https));
}

web_pool.block_on(try_join_all(servers))?;
Expand Down

0 comments on commit 2d643e8

Please sign in to comment.