pelikan-io / pelikan

Pelikan is a framework for building local or distributed caches. It comes with a highly extensible architecture, best-in-class performance, and superb operational ergonomics. You can use it to replace most of Memcached or a subset of Redis features.
https://pelikan.io
Apache License 2.0
232 stars 19 forks source link

pelikan-net: make metrics opt-in #130

Closed brayniac closed 4 months ago

brayniac commented 5 months ago

Changes the way metrics are included in pelikan-net, moving them behind a feature flag to make them opt-in.

swlynch99 commented 4 months ago

@thinkingfish pointed me to this PR. Here's a suggestion that lets you cut down on needing to have #[cfg(feature = "metrics")] everywhere. You can define a metric! macro that conditionally expands to either nothing or its input:

#[cfg(feature = "metrics")]
macro_rules! metrics {
    { $( $tt:tt )* } => { $( $tt )* }
}

#[cfg(not(feature = "metrics"))]
macro_rules! metrics {
    { $( $tt:tt)* } => {}
}

Then, later on, instead of using #[cfg(feature = "metrics")] you wrap the metrics-related code in a metrics! macro

metrics! {
    METRIC.increment();
}

You still have to modify all the calls but you don't have to repeat #[cfg] everywhere so it is easier to change in the future if you need to.

brayniac commented 4 months ago

@thinkingfish pointed me to this PR. Here's a suggestion that lets you cut down on needing to have #[cfg(feature = "metrics")] everywhere. You can define a metric! macro that conditionally expands to either nothing or its input:

#[cfg(feature = "metrics")]
macro_rules! metrics {
    { $( $tt:tt )* } => { $( $tt )* }
}

#[cfg(not(feature = "metrics"))]
macro_rules! metrics {
    { $( $tt:tt)* } => {}
}

Then, later on, instead of using #[cfg(feature = "metrics")] you wrap the metrics-related code in a metrics! macro

metrics! {
    METRIC.increment();
}

You still have to modify all the calls but you don't have to repeat #[cfg] everywhere so it is easier to change in the future if you need to.

Not a bad idea!