Skip to content

Commit

Permalink
feat: macros 💀
Browse files Browse the repository at this point in the history
  • Loading branch information
xDarksome committed Jul 2, 2024
1 parent 0e8e64e commit eb668b8
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 33 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ analytics = { path = "./crates/analytics", optional = true }
collections = { path = "./crates/collections", optional = true }
future = { path = "./crates/future", optional = true }
geoip = { path = "./crates/geoip", optional = true }
metrics = { path = "./crates/metrics", optional = true }
metrics = { package = "wc_metrics", path = "./crates/metrics", optional = true }
rate_limit = { path = "./crates/rate_limit", optional = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ profiler = ["dep:dhat", "dep:tokio"]
metrics = ["dep:metrics"]

[dependencies]
metrics = { path = "../metrics", optional = true }
metrics = { package = "wc_metrics", path = "../metrics", optional = true }
tikv-jemallocator = { version = "0.5", features = ["stats"] }
tikv-jemalloc-ctl = { version = "0.5", features = ["use_std"] }
serde = { version = "1", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "metrics"
name = "wc_metrics"
version = "0.1.0"
edition = "2021"

Expand All @@ -8,7 +8,7 @@ default = ["future"]
future = ["dep:pin-project"]

[dependencies]
backend = { package = "metrics", version = "0.23" }
metrics = "0.23"
smallvec = "1"
parking_lot = "0.12"
enum-ordinalize = "4.3"
Expand Down
12 changes: 10 additions & 2 deletions crates/metrics/src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
//! Usage:
//!
//! ```
//! use metrics::{label_name, BoolLabel, FutureExt, FutureMetrics, LabeledFutureMetrics2, Lazy};
//! use wc_metrics::{
//! self as metrics,
//! label_name,
//! BoolLabel,
//! FutureExt,
//! FutureMetrics,
//! LabeledFutureMetrics2,
//! Lazy,
//! };
//!
//! type MyBoolLabelA = BoolLabel<{ label_name("my_bool_label_a") }>;
//! type MyBoolLabelB = BoolLabel<{ label_name("my_bool_label_b") }>;
Expand All @@ -25,7 +33,7 @@ use {
sealed::{Attrs, Metric},
Lazy,
},
backend::{counter, gauge, histogram, Counter, Gauge, Histogram, Label},
metrics::{counter, gauge, histogram, Counter, Gauge, Histogram, Label},
std::{
future::Future,
pin::Pin,
Expand Down
6 changes: 3 additions & 3 deletions crates/metrics/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use {
Metric,
},
arc_swap::ArcSwap,
backend::Label,
enum_ordinalize::Ordinalize,
metrics::Label,
parking_lot::Mutex,
smallvec::SmallVec,
std::{borrow::Borrow, collections::HashMap, marker::PhantomData, sync::Arc},
Expand Down Expand Up @@ -157,7 +157,7 @@ where
/// name should be specified using the following hack:
///
/// ```
/// use metrics::{label_name, BoolLabel};
/// use wc_metrics::{label_name, BoolLabel};
///
/// type MyLabel = BoolLabel<{ label_name("my_label") }>;
/// ```
Expand Down Expand Up @@ -229,7 +229,7 @@ where
/// name should be specified using the following hack:
///
/// ```
/// use metrics::{label_name, StringLabel};
/// use wc_metrics::{label_name, StringLabel};
///
/// type MyLabel = StringLabel<{ label_name("my_label") }>;
/// ```
Expand Down
2 changes: 1 addition & 1 deletion crates/metrics/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
Metric,
StaticAttrs,
},
backend::{Counter, Gauge, Histogram, IntoF64},
metrics::{Counter, Gauge, Histogram, IntoF64},
std::sync::OnceLock,
};

Expand Down
21 changes: 14 additions & 7 deletions crates/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@
//! hurting the code ergonomics.
//!
//! A trivial atomic counter increment MUST NOT allocate stuff on the heap
//! (looking at you [`metrics::counter`]) and it SHOULD NOT acquire locks or
//! do [`HashMap`](std::collections::HashMap) lookups unless absolutely
//! necessary.
//! (looking at you [`metrics::counter`] and it SHOULD NOT acquire locks or do
//! [`HashMap`](std::collections::HashMap) lookups unless absolutely necessary.
//!
//! If your metric is only being used once, or you can cache it somewhere
//! consider using [`counter`], [`gauge`] or [`histogram`] convinience macros.
//! The macros are completely optional and the machinery can be used
//! as is without them.
//!
//! # Usage
//!
//! ```
//! use metrics::{
//! backend::{Counter, Gauge, Histogram},
//! use wc_metrics::{
//! self as metrics,
//! enum_ordinalize::Ordinalize,
//! label_name,
//! BoolLabel,
//! Counter,
//! Enum,
//! EnumLabel,
//! Gauge,
//! Histogram,
//! LabeledCounter2,
//! LabeledGauge3,
//! LabeledHistogram,
Expand Down Expand Up @@ -77,19 +83,20 @@
//! ```
pub use {
backend,
enum_ordinalize,
label::{label_name, BoolLabel, Enum, EnumLabel, LabelName, Optional, StringLabel, WithLabel},
lazy::Lazy,
metrics::{self as backend, Counter, Gauge, Histogram},
};
use {
backend::{Counter, Gauge, Histogram, IntoF64, Label},
label::{DynamicLabels, Labeled, Labeled2, Labeled3, Labeled4, StaticLabels},
metrics::{IntoF64, Label},
sealed::{Attrs, Decrement, Execute, Increment, Metric, Record, Set},
};

mod label;
mod lazy;
mod macros;

#[cfg(feature = "future")]
pub mod future;
Expand Down
Loading

0 comments on commit eb668b8

Please sign in to comment.