Skip to content

Commit

Permalink
Use namespaced features
Browse files Browse the repository at this point in the history
  • Loading branch information
topenkoff committed Sep 2, 2022
1 parent 126e7f6 commit b06e7ad
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
default = []

[dev-dependencies]
hitbox = { path = "../hitbox", features = ["derive", "cache-metrics"] }
hitbox = { path = "../hitbox", features = ["derive", "metrics"] }
hitbox-actix = { path = "../hitbox-actix", features = ["redis"]}
actix = "0.13"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion hitbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ metrics-util = "0.14"
default = []

derive = ["hitbox-derive", "serde_qs", "actix/macros"]
cache-metrics = ["metrics", "lazy_static"]
metrics = ["dep:metrics", "lazy_static"]

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 2 additions & 2 deletions hitbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
pub mod cache;
pub mod dev;
pub mod error;
#[cfg(feature = "cache-metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "cache-metrics")))]
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub mod metrics;
pub mod response;
pub mod runtime;
Expand Down
4 changes: 2 additions & 2 deletions hitbox/src/states/cache_polled/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::CacheableResponse;
use crate::runtime::RuntimeAdapter;
use crate::states::finish::Finish;
use crate::CachedValue;
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
use crate::metrics::CACHE_HIT_COUNTER;

/// This state is a variant with actual data from [CachePolled](enum.CachePolled.html).
Expand Down Expand Up @@ -42,7 +42,7 @@ where
/// We have to return actual data.
pub fn finish(self) -> Finish<T> {
trace!("Finish");
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
metrics::increment_counter!(
CACHE_HIT_COUNTER.as_ref(),
"upstream" => self.adapter.upstream_name(),
Expand Down
8 changes: 4 additions & 4 deletions hitbox/src/states/cache_polled/missed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::runtime::RuntimeAdapter;
use crate::states::upstream_polled::{
UpstreamPolled, UpstreamPolledError, UpstreamPolledSuccessful,
};
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
use crate::metrics::{CACHE_MISS_COUNTER, CACHE_UPSTREAM_HANDLING_HISTOGRAM};
use std::fmt;

Expand Down Expand Up @@ -39,17 +39,17 @@ where
A: RuntimeAdapter<UpstreamResult = T>,
T: CacheableResponse,
{
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
let timer = std::time::Instant::now();
let upstream_response = self.adapter.poll_upstream().await;
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
metrics::histogram!(
CACHE_UPSTREAM_HANDLING_HISTOGRAM.as_ref(),
timer.elapsed().as_millis() as f64 / 1000.0,
"upstream" => self.adapter.upstream_name(),
"message" => self.adapter.message_name(),
);
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
metrics::increment_counter!(
CACHE_MISS_COUNTER.as_ref(),
"upstream" => self.adapter.upstream_name(),
Expand Down
6 changes: 3 additions & 3 deletions hitbox/src/states/cache_polled/stale.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tracing::{instrument, trace, warn};

#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
use crate::metrics::{CACHE_HIT_COUNTER, CACHE_STALE_COUNTER};
use crate::runtime::RuntimeAdapter;
use crate::states::finish::Finish;
Expand Down Expand Up @@ -46,13 +46,13 @@ where
A: RuntimeAdapter<UpstreamResult = T>,
{
let upstream_response = self.adapter.poll_upstream().await;
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
metrics::increment_counter!(
CACHE_HIT_COUNTER.as_ref(),
"upstream" => self.adapter.upstream_name(),
"message" => self.adapter.message_name(),
);
#[cfg(feature = "cache-metrics")]
#[cfg(feature = "metrics")]
metrics::increment_counter!(
CACHE_STALE_COUNTER.as_ref(),
"upstream" => self.adapter.upstream_name(),
Expand Down
2 changes: 1 addition & 1 deletion hitbox/tests/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(all(test, feature = "cache-metrics"))]
#[cfg(all(test, feature = "metrics"))]
mod tests {
use hitbox::dev::MockAdapter;
use hitbox::metrics::{CACHE_HIT_COUNTER, CACHE_MISS_COUNTER, CACHE_STALE_COUNTER};
Expand Down

0 comments on commit b06e7ad

Please sign in to comment.