Skip to content

Commit

Permalink
Modernize some crate dependencies (#1325)
Browse files Browse the repository at this point in the history
This replaces the `lazy_static` and `parking_lot` crates with `once_cell` and `std` types.

Also does a `cargo update` for good measure.
  • Loading branch information
Swatinem authored Oct 17, 2023
1 parent 32f71a5 commit 35150ee
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 222 deletions.
246 changes: 119 additions & 127 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/symbolicator-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ apple-crash-report-parser = "0.5.1"
async-trait = "0.1.53"
chrono = { version = "0.4.19", features = ["serde"] }
futures = "0.3.12"
lazy_static = "1.4.0"
minidump = "0.18.0"
minidump-processor = "0.18.0"
minidump-unwind = "0.18.0"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.18.0"
regex = "1.5.5"
sentry = { version = "0.31.7", features = ["tracing"] }
serde = { version = "1.0.137", features = ["derive", "rc"] }
Expand Down
9 changes: 5 additions & 4 deletions crates/symbolicator-native/src/symbolication/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use apple_crash_report_parser::AppleCrashReport;
use chrono::{DateTime, Utc};
use once_cell::sync::Lazy;
use regex::Regex;
use symbolic::common::{Arch, CodeId, DebugId};
use symbolicator_service::types::{RawObjectInfo, Scope, ScrapingConfig};
Expand Down Expand Up @@ -136,10 +137,10 @@ impl SymbolicationActor {
}
}

lazy_static::lazy_static! {
/// Format sent by Unreal Engine on macOS
static ref OS_MACOS_REGEX: Regex = Regex::new(r"^Mac OS X (?P<version>\d+\.\d+\.\d+)( \((?P<build>[a-fA-F0-9]+)\))?$").unwrap();
}
/// Format sent by Unreal Engine on macOS
static OS_MACOS_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^Mac OS X (?P<version>\d+\.\d+\.\d+)( \((?P<build>[a-fA-F0-9]+)\))?$").unwrap()
});

#[derive(Debug)]
struct AppleCrashReportState {
Expand Down
4 changes: 1 addition & 3 deletions crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ humantime-serde = "1.1.1"
idna = "0.4.0"
ipnetwork = "0.20.0"
jsonwebtoken = "8.1.0"
lazy_static = "1.4.0"
moka = { version = "0.12.1", features = ["future", "sync"] }
once_cell = "1.17.1"
parking_lot = "0.12.0"
rand = "0.8.5"
reqwest = { version = "0.11.0", features = ["gzip", "brotli", "deflate", "json", "stream", "trust-dns"] }
sentry = { version = "0.31.7", features = ["tracing"] }
Expand All @@ -46,7 +44,7 @@ tracing = "0.1.34"
url = { version = "2.2.0", features = ["serde"] }
uuid = { version = "1.0.0", features = ["v4", "serde"] }
zip = { version = "0.6.4", default-features = false, features = ["deflate"] }
zstd = "0.12.1"
zstd = "0.13.0"

[dev-dependencies]
sha-1 = "0.10.0"
Expand Down
7 changes: 3 additions & 4 deletions crates/symbolicator-service/src/caching/memory.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::collections::HashSet;
use std::path::Path;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

use futures::future::BoxFuture;
use parking_lot::Mutex;
use sentry::{Hub, SentryFutureExt};
use symbolic::common::ByteView;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -372,7 +371,7 @@ impl<T: CacheItemRequest> Cacher<T> {
fn spawn_refresh(&self, cache_key: CacheKey, request: T) {
let name = self.config.name();

let mut refreshes = self.refreshes.lock();
let mut refreshes = self.refreshes.lock().unwrap();
if refreshes.contains(&cache_key) {
return;
}
Expand All @@ -391,7 +390,7 @@ impl<T: CacheItemRequest> Cacher<T> {
let refreshes = Arc::clone(&self.refreshes);
CallOnDrop::new(move || {
max_lazy_refreshes.fetch_add(1, Ordering::Relaxed);
refreshes.lock().remove(&key);
refreshes.lock().unwrap().remove(&key);
})
};

Expand Down
33 changes: 11 additions & 22 deletions crates/symbolicator-service/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
//! Provides access to the metrics sytem.
use std::collections::BTreeMap;
use std::net::ToSocketAddrs;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use std::ops::Deref;
use std::sync::OnceLock;

use cadence::{Metric, MetricBuilder, StatsdClient, UdpMetricSink};
use parking_lot::RwLock;

lazy_static::lazy_static! {
static ref METRICS_CLIENT: RwLock<Option<Arc<MetricsClient>>> = RwLock::new(None);
}
static METRICS_CLIENT: OnceLock<MetricsClient> = OnceLock::new();

thread_local! {
static CURRENT_CLIENT: Option<Arc<MetricsClient>> = METRICS_CLIENT.read().clone();
static CURRENT_CLIENT: Option<&'static MetricsClient> = METRICS_CLIENT.get();
}

/// The metrics prelude that is necessary to use the client.
Expand Down Expand Up @@ -50,17 +47,6 @@ impl Deref for MetricsClient {
}
}

impl DerefMut for MetricsClient {
fn deref_mut(&mut self) -> &mut StatsdClient {
&mut self.statsd_client
}
}

/// Set a new statsd client.
pub fn set_client(client: MetricsClient) {
*METRICS_CLIENT.write() = Some(Arc::new(client));
}

/// Tell the metrics system to report to statsd.
pub fn configure_statsd<A: ToSocketAddrs>(prefix: &str, host: A, tags: BTreeMap<String, String>) {
let addrs: Vec<_> = host.to_socket_addrs().unwrap().collect();
Expand All @@ -71,10 +57,13 @@ pub fn configure_statsd<A: ToSocketAddrs>(prefix: &str, host: A, tags: BTreeMap<
socket.set_nonblocking(true).unwrap();
let sink = UdpMetricSink::from(&addrs[..], socket).unwrap();
let statsd_client = StatsdClient::from_sink(prefix, sink);
set_client(MetricsClient {
statsd_client,
tags,
});

METRICS_CLIENT
.set(MetricsClient {
statsd_client,
tags,
})
.unwrap();
}

/// Invoke a callback with the current statsd client.
Expand Down
30 changes: 23 additions & 7 deletions crates/symbolicator-service/src/utils/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@ use std::net::IpAddr;
use std::time::Duration;

use ipnetwork::Ipv4Network;
use once_cell::sync::Lazy;
use reqwest::Url;

use crate::config::Config;

lazy_static::lazy_static! {
static ref RESERVED_IP_BLOCKS: Vec<Ipv4Network> = vec![
static RESERVED_IP_BLOCKS: Lazy<Vec<Ipv4Network>> = Lazy::new(|| {
[
// https://en.wikipedia.org/wiki/Reserved_IP_addresses#IPv4
"0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12",
"192.0.0.0/29", "192.0.2.0/24", "192.88.99.0/24", "192.168.0.0/16", "198.18.0.0/15",
"198.51.100.0/24", "224.0.0.0/4", "240.0.0.0/4", "255.255.255.255/32",
].into_iter().map(|x| x.parse().unwrap()).collect();
}
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/29",
"192.0.2.0/24",
"192.88.99.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"224.0.0.0/4",
"240.0.0.0/4",
"255.255.255.255/32",
]
.into_iter()
.map(|x| x.parse().unwrap())
.collect()
});

fn is_external_ip(ip: std::net::IpAddr) -> bool {
let addr = match ip {
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ license = "MIT"
anyhow = "1.0.68"
aws-types = "0.56.0"
glob = "0.3.0"
lazy_static = "1.4.0"
serde = { version = "1.0.137", features = ["derive", "rc"] }
symbolic = "12.4.0"
url = { version = "2.2.0", features = ["serde"] }

[dev-dependencies]
insta = { version = "1.18.0", features = ["redactions", "yaml"] }
once_cell = "1.18.0"
serde_yaml = "0.9.14"
68 changes: 34 additions & 34 deletions crates/symbolicator-sources/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,40 +581,40 @@ pub fn matches_path_patterns(object_id: &ObjectId, patterns: &[Glob]) -> bool {
mod tests {
use super::*;

lazy_static::lazy_static! {
static ref PE_OBJECT_ID: ObjectId = ObjectId {
code_id: Some("5ab380779000".parse().unwrap()),
code_file: Some("C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe".into()),
debug_id: Some("3249d99d-0c40-4931-8610-f4e4fb0b6936-1".parse().unwrap()),
debug_file: Some("C:\\projects\\breakpad-tools\\windows\\Release\\crash.pdb".into()),
debug_checksum: None,
object_type: ObjectType::Pe,
};
static ref MACHO_OBJECT_ID: ObjectId = ObjectId {
code_id: None,
code_file: Some("/Users/travis/build/getsentry/breakpad-tools/macos/build/./crash".into()),
debug_id: Some("67e9247c-814e-392b-a027-dbde6748fcbf".parse().unwrap()),
debug_file: Some("crash".into()),
debug_checksum: None,
object_type: ObjectType::Macho,
};
static ref ELF_OBJECT_ID: ObjectId = ObjectId {
code_id: Some("dfb85de42daffd09640c8fe377d572de3e168920".parse().unwrap()),
code_file: Some("/lib/x86_64-linux-gnu/libm-2.23.so".into()),
debug_id: Some("e45db8df-af2d-09fd-640c-8fe377d572de".parse().unwrap()),
debug_file: Some("/lib/x86_64-linux-gnu/libm-2.23.so".into()),
debug_checksum: None,
object_type: ObjectType::Elf,
};
static ref WASM_OBJECT_ID: ObjectId = ObjectId {
code_id: Some("67e9247c814e392ba027dbde6748fcbf".parse().unwrap()),
code_file: None,
debug_id: Some("67e9247c-814e-392b-a027-dbde6748fcbf".parse().unwrap()),
debug_file: Some("file://foo.invalid/demo.wasm".into()),
debug_checksum: None,
object_type: ObjectType::Wasm,
};
}
use once_cell::sync::Lazy;

static PE_OBJECT_ID: Lazy<ObjectId> = Lazy::new(|| ObjectId {
code_id: Some("5ab380779000".parse().unwrap()),
code_file: Some("C:\\projects\\breakpad-tools\\windows\\Release\\crash.exe".into()),
debug_id: Some("3249d99d-0c40-4931-8610-f4e4fb0b6936-1".parse().unwrap()),
debug_file: Some("C:\\projects\\breakpad-tools\\windows\\Release\\crash.pdb".into()),
debug_checksum: None,
object_type: ObjectType::Pe,
});
static MACHO_OBJECT_ID: Lazy<ObjectId> = Lazy::new(|| ObjectId {
code_id: None,
code_file: Some("/Users/travis/build/getsentry/breakpad-tools/macos/build/./crash".into()),
debug_id: Some("67e9247c-814e-392b-a027-dbde6748fcbf".parse().unwrap()),
debug_file: Some("crash".into()),
debug_checksum: None,
object_type: ObjectType::Macho,
});
static ELF_OBJECT_ID: Lazy<ObjectId> = Lazy::new(|| ObjectId {
code_id: Some("dfb85de42daffd09640c8fe377d572de3e168920".parse().unwrap()),
code_file: Some("/lib/x86_64-linux-gnu/libm-2.23.so".into()),
debug_id: Some("e45db8df-af2d-09fd-640c-8fe377d572de".parse().unwrap()),
debug_file: Some("/lib/x86_64-linux-gnu/libm-2.23.so".into()),
debug_checksum: None,
object_type: ObjectType::Elf,
});
static WASM_OBJECT_ID: Lazy<ObjectId> = Lazy::new(|| ObjectId {
code_id: Some("67e9247c814e392ba027dbde6748fcbf".parse().unwrap()),
code_file: None,
debug_id: Some("67e9247c-814e-392b-a027-dbde6748fcbf".parse().unwrap()),
debug_file: Some("file://foo.invalid/demo.wasm".into()),
debug_checksum: None,
object_type: ObjectType::Wasm,
});

fn pattern(x: &str) -> Glob {
Glob(x.parse().unwrap())
Expand Down
4 changes: 2 additions & 2 deletions crates/symsorter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ anyhow = "1.0.57"
chrono = { version = "0.4.19", default-features = false, features = ["clock", "serde", "std"] }
clap = { version = "4.3.2", features = ["derive"] }
console = "0.15.0"
lazy_static = "1.4.0"
once_cell = "1.18.0"
rayon = "1.5.2"
regex = "1.5.5"
serde = { version = "1.0.137", features = ["derive"] }
Expand All @@ -19,4 +19,4 @@ symbolic = { version = "12.4.0", features = ["debuginfo-serde"] }
walkdir = "2.3.1"
# NOTE: zip:0.6 by default depends on a version of zstd which conflicts with our other dependencies
zip = { version = "0.6.2", default-features = false, features = ["deflate", "bzip2"] }
zstd = "0.12.1"
zstd = "0.13.0"
20 changes: 7 additions & 13 deletions crates/symsorter/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use lazy_static::lazy_static;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::OnceLock;

lazy_static! {
static ref CONFIG: Mutex<Arc<RunConfig>> = Mutex::new(Arc::new(Default::default()));
}
static CONFIG: OnceLock<RunConfig> = OnceLock::new();

#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Default, Clone)]
pub struct RunConfig {
Expand All @@ -19,17 +16,14 @@ pub struct RunConfig {
}

impl RunConfig {
pub fn get() -> Arc<RunConfig> {
CONFIG.lock().unwrap().clone()
pub fn get() -> &'static RunConfig {
CONFIG.get_or_init(RunConfig::default)
}

pub fn configure<F: FnOnce(&mut Self) -> R, R>(f: F) -> R {
let mut config = RunConfig::get();
let rv = {
let mutable_config = Arc::make_mut(&mut config);
f(mutable_config)
};
*CONFIG.lock().unwrap() = config;
let mut config = RunConfig::default();
let rv = f(&mut config);
CONFIG.set(config).unwrap();
rv
}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/symsorter/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use std::io::Cursor;
use std::path::{Path, PathBuf};

use anyhow::{anyhow, bail, Result};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use symbolic::common::ByteView;
use symbolic::debuginfo::sourcebundle::{SourceBundleWriter, SourceFileDescriptor};
use symbolic::debuginfo::{Archive, FileEntry, FileFormat, Object, ObjectKind};

lazy_static! {
static ref BAD_CHARS_RE: Regex = Regex::new(r"[^a-zA-Z0-9.,-]+").unwrap();
}
static BAD_CHARS_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[^a-zA-Z0-9.,-]+").unwrap());

/// Console logging for the symsorter app.
#[macro_export]
Expand Down

0 comments on commit 35150ee

Please sign in to comment.