From e74c8687f523073d113b1009699853a00e057b8c Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Thu, 24 Oct 2024 15:31:04 -0700 Subject: [PATCH] drop dependency on once-cell --- Cargo.lock | 1 - Cargo.toml | 1 - src/config.rs | 6 +++--- src/observability.rs | 14 +++++++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3c2baa4..1f6f9c36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -888,7 +888,6 @@ dependencies = [ "lru-cache", "nix", "num_cpus", - "once_cell", "opentelemetry", "opentelemetry-jaeger-propagator", "opentelemetry-otlp", diff --git a/Cargo.toml b/Cargo.toml index e989f459..dfd7e7f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,6 @@ image = { version = "0.25.2", default-features = false, features = ["jpeg", "png jsonwebtoken = "9.3.0" lru-cache = "0.1.2" num_cpus = "1.16.0" -once_cell = "1.19.0" opentelemetry = "0.24.0" opentelemetry-jaeger-propagator = "0.3.0" opentelemetry-otlp = "0.17.0" diff --git a/src/config.rs b/src/config.rs index 54ef0e79..a440a455 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,9 +4,9 @@ use std::{ fmt::{self, Display}, net::{IpAddr, Ipv4Addr}, path::{Path, PathBuf}, + sync::LazyLock, }; -use once_cell::sync::Lazy; use reqwest::Url; use ruma::{ api::federation::discovery::OldVerifyKey, OwnedServerName, @@ -24,8 +24,8 @@ pub(crate) use env_filter_clone::EnvFilterClone; use proxy::ProxyConfig; /// The default configuration file path -pub(crate) static DEFAULT_PATH: Lazy = - Lazy::new(|| [env!("CARGO_PKG_NAME"), "config.toml"].iter().collect()); +pub(crate) static DEFAULT_PATH: LazyLock = + LazyLock::new(|| [env!("CARGO_PKG_NAME"), "config.toml"].iter().collect()); #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Deserialize)] diff --git a/src/observability.rs b/src/observability.rs index f0baee1c..f2503f61 100644 --- a/src/observability.rs +++ b/src/observability.rs @@ -1,7 +1,12 @@ //! Facilities for observing runtime behavior #![warn(missing_docs, clippy::missing_docs_in_private_items)] -use std::{collections::HashSet, fs::File, io::BufWriter, sync::Arc}; +use std::{ + collections::HashSet, + fs::File, + io::BufWriter, + sync::{Arc, LazyLock}, +}; use axum::{ extract::{MatchedPath, Request}, @@ -9,7 +14,6 @@ use axum::{ response::Response, }; use http::Method; -use once_cell::sync::Lazy; use opentelemetry::{metrics::MeterProvider, trace::TracerProvider, KeyValue}; use opentelemetry_otlp::WithExportConfig; use opentelemetry_sdk::{ @@ -34,7 +38,7 @@ use crate::{ }; /// Globally accessible metrics state -pub(crate) static METRICS: Lazy = Lazy::new(Metrics::new); +pub(crate) static METRICS: LazyLock = LazyLock::new(Metrics::new); /// Cleans up resources relating to observability when [`Drop`]ped pub(crate) struct Guard { @@ -385,8 +389,8 @@ impl Metrics { /// Track HTTP metrics by converting this into an [`axum`] layer pub(crate) async fn http_metrics_layer(req: Request, next: Next) -> Response { /// Routes that should not be included in the metrics - static IGNORED_ROUTES: Lazy> = - Lazy::new(|| [(&Method::GET, "/metrics")].into_iter().collect()); + static IGNORED_ROUTES: LazyLock> = + LazyLock::new(|| [(&Method::GET, "/metrics")].into_iter().collect()); let matched_path = req.extensions().get::().map(|x| x.as_str().to_owned());