Skip to content

Commit

Permalink
replace increment_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber committed Sep 2, 2023
1 parent 8be5fea commit 724e78c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 52 deletions.
11 changes: 0 additions & 11 deletions metrics-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ pub fn register_histogram(input: TokenStream) -> TokenStream {
get_register_and_op_code::<bool>(target, level, "histogram", key, labels, None).into()
}

#[proc_macro]
pub fn increment_counter(input: TokenStream) -> TokenStream {
let WithoutExpression { target, level, key, labels } =
parse_macro_input!(input as WithoutExpression);

let op_value = quote! { 1 };

get_register_and_op_code(target, level, "counter", key, labels, Some(("increment", op_value)))
.into()
}

#[proc_macro]
pub fn increment_gauge(input: TokenStream) -> TokenStream {
let WithExpression { target, level, key, op_value, labels } =
Expand Down
41 changes: 0 additions & 41 deletions metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,47 +434,6 @@ pub use metrics_macros::register_gauge;
/// ```
pub use metrics_macros::register_histogram;

/// Increments a counter by one.
///
/// Counters represent a single monotonic value, which means the value can only be incremented, not
/// decremented, and always starts out with an initial value of zero.
///
/// Metric names are shown below using string literals, but they can also be owned `String` values,
/// which includes using macros such as `format!` directly at the callsite. String literals are
/// preferred for performance where possible.
///
/// # Example
/// ```
/// # use metrics::{increment_counter, Level};
/// # fn main() {
/// // A basic increment:
/// increment_counter!("some_metric_name");
///
/// // A basic increment with level and target specified:
/// increment_counter!(target: "specific_target", level: Level::DEBUG, "some_metric_name");
///
/// // Specifying labels inline, including using constants for either the key or value:
/// increment_counter!("some_metric_name", "service" => "http");
///
/// const SERVICE_LABEL: &'static str = "service";
/// const SERVICE_HTTP: &'static str = "http";
/// increment_counter!("some_metric_name", SERVICE_LABEL => SERVICE_HTTP);
///
/// // We can also pass labels by giving a vector or slice of key/value pairs:
/// let dynamic_val = "woo";
/// let labels = [("dynamic_key", format!("{}!", dynamic_val))];
/// increment_counter!("some_metric_name", &labels);
///
/// // As mentioned in the documentation, metric names also can be owned strings, including ones
/// // generated at the callsite via things like `format!`:
/// let name = String::from("some_owned_metric_name");
/// increment_counter!(name);
///
/// increment_counter!(format!("{}_via_format", "name"));
/// # }
/// ```
pub use metrics_macros::increment_counter;

/// Updates a gauge.
///
/// Gauges represent a single value that can go up or down over time, and always starts out with an
Expand Down
8 changes: 8 additions & 0 deletions metrics/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ macro_rules! absolute_counter {
handle.absolute($op_val);
}};
}

/// TODO
#[macro_export]
macro_rules! increment_counter {
($(target: $target:expr,)? $(level: $level:expr,)? $name:expr $(, $label_key:expr $(=> $label_value:expr)?)* $(,)?) => {{
$crate::counter!($(target: $target,)? $(level: $level,)? $name, 1 $(, $label_key $(=> $label_value)?)*);
}};
}

0 comments on commit 724e78c

Please sign in to comment.