Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pelikan-net: make metrics opt-in #130

Merged
merged 6 commits into from
Jul 2, 2024
Merged

Conversation

brayniac
Copy link
Collaborator

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

brayniac added 3 commits June 12, 2024 12:03
Changes the way metrics are included in pelikan-net, moving them
behind a feature flag to make them opt-in.
@swlynch99
Copy link
Contributor

@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
Copy link
Collaborator Author

@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!

src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/tls_tcp/boringssl.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/tls_tcp/boringssl.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/tls_tcp/openssl.rs Fixed Show fixed Hide fixed
src/net/src/lib.rs Fixed Show fixed Hide fixed
src/net/src/tls_tcp/openssl.rs Fixed Show fixed Hide fixed
@brayniac brayniac requested a review from swlynch99 July 1, 2024 23:10
Copy link
Contributor

@swlynch99 swlynch99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@brayniac brayniac merged commit 13a6cd8 into pelikan-io:main Jul 2, 2024
21 checks passed
@brayniac brayniac deleted the net-metrics branch July 2, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants