Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
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.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",
Expand Down Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
## 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
Expand Down
20 changes: 12 additions & 8 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CounterVec> = 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<CounterVec> = 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
Expand Down