From fd298e693df189442d60fa7c0bca20ba2c5571d3 Mon Sep 17 00:00:00 2001 From: Florentin Dubois Date: Mon, 13 Mar 2023 13:02:21 +0100 Subject: [PATCH 1/2] Update dependencies * Bump hyper to 0.14.25 * Bump serde to 1.0.155 Signed-off-by: Florentin Dubois --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4680fb5..feffd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,13 +26,13 @@ cidr = { version = "^0.2.1", optional = true } crypto-common = { version = "^0.1.6", optional = true } headers = { version = "^0.3.8", optional = true } hmac = { version = "^0.12.1", features = ["std"], optional = true } -hyper = { version = "^0.14.24", default-features = false, optional = true } +hyper = { version = "^0.14.25", default-features = false, optional = true } hyper-tls = { version = "^0.5.0", optional = true } hyper-proxy = { version = "^0.9.1", default-features = false, features = ["tls"], optional = true } lazy_static = { version = "^1.4.0", optional = true } log = { version = "^0.4.17", optional = true } prometheus = { version = "^0.13.3", optional = true } -serde = { version = "^1.0.152", features = ["derive"], optional = true } +serde = { version = "^1.0.155", features = ["derive"], optional = true } serde_json = { version = "^1.0.94", features = [ "preserve_order", "float_roundtrip", From a923f74084afa7de28981a3d00e26c66c5183140 Mon Sep 17 00:00:00 2001 From: Florentin Dubois Date: Mon, 13 Mar 2023 13:03:48 +0100 Subject: [PATCH 2/2] Use `once_cell` instead of `lazy_static` Signed-off-by: Florentin Dubois --- Cargo.toml | 4 ++-- README.md | 4 ++-- src/client/mod.rs | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index feffd54..f541fd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ hmac = { version = "^0.12.1", features = ["std"], optional = true } hyper = { version = "^0.14.25", default-features = false, optional = true } hyper-tls = { version = "^0.5.0", optional = true } hyper-proxy = { version = "^0.9.1", default-features = false, features = ["tls"], optional = true } -lazy_static = { version = "^1.4.0", optional = true } +once_cell = { version = "^1.17.1", optional = true } log = { version = "^0.4.17", optional = true } prometheus = { version = "^0.13.3", optional = true } serde = { version = "^1.0.155", features = ["derive"], optional = true } @@ -68,5 +68,5 @@ client = [ logging = ["log", "tracing/log-always"] trace = ["tracing", "tracing-futures"] tokio = ["tracing-futures/tokio"] -metrics = ["lazy_static", "prometheus"] +metrics = ["once_cell", "prometheus"] proxy = ["cidr", "headers", "hyper-proxy", "url"] diff --git a/README.md b/README.md index f139a53..c3257e7 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,11 @@ async fn main() -> Result<(), Box> { ## Features | name | description | -| ------- | ------------------------------------------------------------------------- | +| ------- |---------------------------------------------------------------------------| | default | Default enable features are `client`, `logging`, `proxy` | | client | The oauth 1.0a client implementation | | logging | Use the `log` facility crate to print logs | -| metrics | Use `lazy_static` and `prometheus` crates to register metrics | +| metrics | Use `once_cell` and `prometheus` crates to register metrics | | proxy | Enable the support of environment variable `http_proxy` and `https_proxy` | ### Metrics diff --git a/src/client/mod.rs b/src/client/mod.rs index f008f83..a96804e 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -27,11 +27,11 @@ use hyper::{ header, Body, Method, StatusCode, }; use hyper_tls::HttpsConnector; -#[cfg(feature = "metrics")] -use lazy_static::lazy_static; #[cfg(feature = "logging")] use log::{error, log_enabled, trace, Level}; #[cfg(feature = "metrics")] +use once_cell::sync::Lazy; +#[cfg(feature = "metrics")] use prometheus::{opts, register_counter_vec, CounterVec}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use sha2::Sha512; @@ -45,21 +45,25 @@ pub mod proxy; // Telemetry #[cfg(feature = "metrics")] -lazy_static! { - static ref CLIENT_REQUEST: CounterVec = register_counter_vec!( +static CLIENT_REQUEST: Lazy = Lazy::new(|| { + register_counter_vec!( opts!("oauth10a_client_request", "number of request on api"), &["endpoint", "method", "status"] ) - .expect("metrics 'oauth10a_client_request' to not be initialized"); - static ref CLIENT_REQUEST_DURATION: CounterVec = register_counter_vec!( + .expect("metrics 'oauth10a_client_request' to not be initialized") +}); + +#[cfg(feature = "metrics")] +static CLIENT_REQUEST_DURATION: Lazy = Lazy::new(|| { + register_counter_vec!( opts!( "oauth10a_client_request_duration", "duration of request on api" ), &["endpoint", "method", "status", "unit"] ) - .expect("metrics 'oauth10a_client_request_duration' to not be initialized"); -} + .expect("metrics 'oauth10a_client_request_duration' to not be initialized") +}); // ----------------------------------------------------------------------------- // Types