From d092ddf5997b379174cfb292c2c38a771da2fe8c Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Fri, 3 May 2024 16:05:50 -0700 Subject: [PATCH] cleanup old macros (#251) Remove old macros since we now use the attribute macros everywhere. --- src/common/mod.rs | 132 ---------------------------------------------- src/main.rs | 9 +++- 2 files changed, 8 insertions(+), 133 deletions(-) diff --git a/src/common/mod.rs b/src/common/mod.rs index 9437b1b4..ac1891c1 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -49,138 +49,6 @@ impl Counter { } } -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized -/// `metriken::Counter` given an identifier, name, and optional description. -macro_rules! counter { - ($ident:ident, $name:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: Lazy = metriken::Lazy::new(|| { - metriken::Counter::new() - }); - }; - ($ident:ident, $name:tt, $description:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: Lazy = metriken::Lazy::new(|| { - metriken::Counter::new() - }); - }; -} - -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized -/// `metriken::Gauge` given an identifier, name, and optional description. -macro_rules! gauge { - ($ident:ident, $name:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: Lazy = metriken::Lazy::new(|| { - metriken::Gauge::new() - }); - }; - ($ident:ident, $name:tt, $description:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: Lazy = metriken::Lazy::new(|| { - metriken::Gauge::new() - }); - }; -} - -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized -/// `metriken::AtomicHistogram` given an identifier, name, and optional -/// description. -/// -/// The histogram configuration used here can record counts for all 64bit -/// integer values with a maximum error of 0.78%. -macro_rules! histogram { - ($ident:ident, $name:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: metriken::AtomicHistogram = metriken::AtomicHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64); - }; - ($ident:ident, $name:tt, $description:tt) => { - #[metriken::metric( - name = $name, - description = $description, - crate = metriken - )] - pub static $ident: metriken::AtomicHistogram = metriken::AtomicHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64); - }; -} - -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized -/// `metriken::RwLockHistogram` given an identifier, name, and optional -/// description. -/// -/// The histogram configuration used here can record counts for all 64bit -/// integer values with a maximum error of 0.78%. -macro_rules! bpfhistogram { - ($ident:ident, $name:tt) => { - #[metriken::metric( - name = $name, - crate = metriken - )] - pub static $ident: metriken::RwLockHistogram = metriken::RwLockHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64); - }; - ($ident:ident, $name:tt, $description:tt) => { - #[metriken::metric( - name = $name, - description = $description, - crate = metriken - )] - pub static $ident: metriken::RwLockHistogram = metriken::RwLockHistogram::new($crate::common::HISTOGRAM_GROUPING_POWER, 64); - }; -} - -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized counter with a -/// histogram which will track secondly rates for the same counter. -macro_rules! counter_with_histogram { - ($counter:ident, $histogram:ident, $name:tt) => { - self::counter!($counter, $name); - self::histogram!($histogram, $name); - }; - ($counter:ident, $histogram:ident, $name:tt, $description:tt) => { - self::counter!($counter, $name, $description); - self::histogram!($histogram, $name, $description); - } -} - -#[macro_export] -#[rustfmt::skip] -/// A convenience macro for constructing a lazily initialized gauge with a -/// histogram which will track instantaneous readings for the same gauge. -macro_rules! gauge_with_histogram { - ($gauge:ident, $histogram:ident, $name:tt) => { - self::gauge!($gauge, $name); - self::histogram!($histogram, $name); - }; - ($gauge:ident, $histogram:ident, $name:tt, $description:tt) => { - self::gauge!($gauge, $name, $description); - self::histogram!($histogram, $name, $description); - } -} - #[macro_export] #[rustfmt::skip] /// A convenience macro for defining a top-level sampler which will contain diff --git a/src/main.rs b/src/main.rs index 8e087f26..dc64ec42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ +use crate::common::Counter; use backtrace::Backtrace; use clap::{Arg, Command}; use linkme::distributed_slice; +use metriken::metric; use metriken::Lazy; +use metriken::LazyCounter; use metriken_exposition::Histogram; use ringlog::*; use std::collections::HashMap; @@ -92,7 +95,11 @@ pub static PERCENTILES: &[(&str, f64)] = &[ #[distributed_slice] pub static SAMPLERS: [fn(config: &Config) -> Box] = [..]; -counter!(RUNTIME_SAMPLE_LOOP, "runtime/sample/loop"); +#[metric( + name = "runtime/sample/loop", + description = "The total number sampler loops executed" +)] +pub static RUNTIME_SAMPLE_LOOP: LazyCounter = LazyCounter::new(metriken::Counter::default); fn main() { // custom panic hook to terminate whole process after unwinding