From 9f9ab789d09b17cb5023db54901abc3867851038 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Mon, 19 Aug 2024 05:48:52 -0700 Subject: [PATCH] Derive Debug trait for all structs and enums This allows all the structs and enums to easily be placed in a struct which derives Debug itself. --- metrics-exporter-prometheus/src/common.rs | 1 + .../src/distribution.rs | 6 ++--- .../src/exporter/builder.rs | 1 + .../src/exporter/http_listener.rs | 1 + .../src/exporter/mod.rs | 5 ++-- metrics-exporter-prometheus/src/recorder.rs | 4 +++- metrics-exporter-prometheus/src/registry.rs | 2 ++ metrics-exporter-tcp/src/lib.rs | 4 ++++ metrics-tracing-context/src/label_filter.rs | 2 +- metrics-tracing-context/src/lib.rs | 2 ++ metrics-tracing-context/tests/integration.rs | 2 +- metrics-util/src/debugging.rs | 5 +++- metrics-util/src/layers/fanout.rs | 17 ++++++++++++- metrics-util/src/layers/filter.rs | 3 ++- metrics-util/src/layers/mod.rs | 5 ++-- metrics-util/src/layers/prefix.rs | 2 ++ metrics-util/src/layers/router.rs | 24 +++++++++++++++++++ metrics-util/src/recoverable.rs | 9 +++++++ metrics-util/src/registry/mod.rs | 1 + metrics-util/src/registry/recency.rs | 4 +++- metrics-util/src/registry/storage.rs | 1 + metrics-util/src/summary.rs | 7 ++++++ metrics-util/src/test_util.rs | 3 ++- metrics/benches/macros.rs | 2 +- metrics/examples/basic.rs | 3 ++- metrics/src/common.rs | 2 +- metrics/src/cow.rs | 2 +- metrics/src/handles.rs | 20 +++++++++++++++- metrics/src/recorder/cell.rs | 1 + metrics/src/recorder/mod.rs | 1 + metrics/src/recorder/noop.rs | 1 + 31 files changed, 123 insertions(+), 20 deletions(-) diff --git a/metrics-exporter-prometheus/src/common.rs b/metrics-exporter-prometheus/src/common.rs index 94ff6ab6..51f9bad9 100644 --- a/metrics-exporter-prometheus/src/common.rs +++ b/metrics-exporter-prometheus/src/common.rs @@ -80,6 +80,7 @@ pub enum BuildError { ZeroBucketDuration, } +#[derive(Debug)] pub struct Snapshot { pub counters: HashMap, u64>>, pub gauges: HashMap, f64>>, diff --git a/metrics-exporter-prometheus/src/distribution.rs b/metrics-exporter-prometheus/src/distribution.rs index 5a8d0f0b..460ed2e1 100644 --- a/metrics-exporter-prometheus/src/distribution.rs +++ b/metrics-exporter-prometheus/src/distribution.rs @@ -15,7 +15,7 @@ const DEFAULT_SUMMARY_BUCKET_COUNT: NonZeroU32 = match NonZeroU32::new(3) { const DEFAULT_SUMMARY_BUCKET_DURATION: Duration = Duration::from_secs(20); /// Distribution type. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum Distribution { /// A Prometheus histogram. /// @@ -134,14 +134,14 @@ impl DistributionBuilder { } } -#[derive(Clone)] +#[derive(Clone, Debug)] struct Bucket { begin: Instant, summary: Summary, } /// A `RollingSummary` manages a list of [Summary] so that old results can be expired. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct RollingSummary { // Buckets are ordered with the latest buckets first. The buckets are kept in alignment based // on the instant of the first added bucket and the bucket_duration. There may be gaps in the diff --git a/metrics-exporter-prometheus/src/exporter/builder.rs b/metrics-exporter-prometheus/src/exporter/builder.rs index 7565ba2b..ff3ec18e 100644 --- a/metrics-exporter-prometheus/src/exporter/builder.rs +++ b/metrics-exporter-prometheus/src/exporter/builder.rs @@ -33,6 +33,7 @@ use super::ExporterConfig; use super::ExporterFuture; /// Builder for creating and installing a Prometheus recorder/exporter. +#[derive(Debug)] pub struct PrometheusBuilder { #[cfg_attr(not(any(feature = "http-listener", feature = "push-gateway")), allow(dead_code))] exporter_config: ExporterConfig, diff --git a/metrics-exporter-prometheus/src/exporter/http_listener.rs b/metrics-exporter-prometheus/src/exporter/http_listener.rs index e820cec9..43cf74e1 100644 --- a/metrics-exporter-prometheus/src/exporter/http_listener.rs +++ b/metrics-exporter-prometheus/src/exporter/http_listener.rs @@ -32,6 +32,7 @@ enum ListenerType { } /// Error type for HTTP listening. +#[derive(Debug)] pub enum HttpListeningError { Hyper(hyper::Error), Io(std::io::Error), diff --git a/metrics-exporter-prometheus/src/exporter/mod.rs b/metrics-exporter-prometheus/src/exporter/mod.rs index c8acbbac..d10c0336 100644 --- a/metrics-exporter-prometheus/src/exporter/mod.rs +++ b/metrics-exporter-prometheus/src/exporter/mod.rs @@ -14,6 +14,7 @@ use hyper::Uri; /// Error types possible from an exporter #[cfg(any(feature = "http-listener", feature = "push-gateway"))] +#[derive(Debug)] pub enum ExporterError { #[cfg(feature = "http-listener")] HttpListener(HttpListeningError), @@ -24,14 +25,14 @@ pub enum ExporterError { pub type ExporterFuture = Pin> + Send + 'static>>; #[cfg(feature = "http-listener")] -#[derive(Clone)] +#[derive(Clone, Debug)] enum ListenDestination { Tcp(SocketAddr), #[cfg(feature = "uds-listener")] Uds(std::path::PathBuf), } -#[derive(Clone)] +#[derive(Clone, Debug)] enum ExporterConfig { // Run an HTTP listener on the given `listen_address`. #[cfg(feature = "http-listener")] diff --git a/metrics-exporter-prometheus/src/recorder.rs b/metrics-exporter-prometheus/src/recorder.rs index 21b2ea79..7d49f688 100644 --- a/metrics-exporter-prometheus/src/recorder.rs +++ b/metrics-exporter-prometheus/src/recorder.rs @@ -15,6 +15,7 @@ use crate::formatting::{ }; use crate::registry::GenerationalAtomicStorage; +#[derive(Debug)] pub(crate) struct Inner { pub registry: Registry, pub recency: Recency, @@ -214,6 +215,7 @@ impl Inner { /// Most users will not need to interact directly with the recorder, and can simply deal with the /// builder methods on [`PrometheusBuilder`](crate::PrometheusBuilder) for building and installing /// the recorder/exporter. +#[derive(Debug)] pub struct PrometheusRecorder { inner: Arc, } @@ -275,7 +277,7 @@ impl Recorder for PrometheusRecorder { /// handled directly by the HTTP listener, or push gateway background task. [`PrometheusHandle`] /// allows rendering a snapshot of the current metrics stored by an installed [`PrometheusRecorder`] /// as a payload conforming to the Prometheus exposition format. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PrometheusHandle { inner: Arc, } diff --git a/metrics-exporter-prometheus/src/registry.rs b/metrics-exporter-prometheus/src/registry.rs index c6001743..ea5b470a 100644 --- a/metrics-exporter-prometheus/src/registry.rs +++ b/metrics-exporter-prometheus/src/registry.rs @@ -7,6 +7,7 @@ use quanta::Instant; pub type GenerationalAtomicStorage = GenerationalStorage; /// Atomic metric storage for the prometheus exporter. +#[derive(Debug)] pub struct AtomicStorage; impl metrics_util::registry::Storage for AtomicStorage { @@ -28,6 +29,7 @@ impl metrics_util::registry::Storage for AtomicStorage { } /// An `AtomicBucket` newtype wrapper that tracks the time of value insertion. +#[derive(Debug)] pub struct AtomicBucketInstant { inner: AtomicBucket<(T, Instant)>, } diff --git a/metrics-exporter-tcp/src/lib.rs b/metrics-exporter-tcp/src/lib.rs index 7a81e44d..4cc27625 100644 --- a/metrics-exporter-tcp/src/lib.rs +++ b/metrics-exporter-tcp/src/lib.rs @@ -137,6 +137,7 @@ impl std::error::Error for Error { } } +#[derive(Debug)] struct State { client_count: AtomicUsize, should_send: AtomicBool, @@ -188,6 +189,7 @@ impl State { } } +#[derive(Debug)] struct Handle { key: Key, state: Arc, @@ -230,11 +232,13 @@ impl HistogramFn for Handle { } /// A TCP recorder. +#[derive(Debug)] pub struct TcpRecorder { state: Arc, } /// Builder for creating and installing a TCP recorder/exporter. +#[derive(Debug)] pub struct TcpBuilder { listen_addr: SocketAddr, buffer_size: Option, diff --git a/metrics-tracing-context/src/label_filter.rs b/metrics-tracing-context/src/label_filter.rs index fa42fc80..139f7716 100644 --- a/metrics-tracing-context/src/label_filter.rs +++ b/metrics-tracing-context/src/label_filter.rs @@ -1,6 +1,6 @@ //! Label filtering. -use std::collections::HashSet; +use std::{collections::HashSet, fmt::Debug}; use metrics::{KeyName, Label}; diff --git a/metrics-tracing-context/src/lib.rs b/metrics-tracing-context/src/lib.rs index 5ea0efc6..b68d4c1b 100644 --- a/metrics-tracing-context/src/lib.rs +++ b/metrics-tracing-context/src/lib.rs @@ -114,6 +114,7 @@ use tracing_integration::Map; pub use tracing_integration::{Labels, MetricsLayer}; /// [`TracingContextLayer`] provides an implementation of a [`Layer`] for [`TracingContext`]. +#[derive(Debug)] pub struct TracingContextLayer { label_filter: F, } @@ -156,6 +157,7 @@ where } /// [`TracingContext`] is a [`metrics::Recorder`] that injects labels from [`tracing::Span`]s. +#[derive(Debug)] pub struct TracingContext { inner: R, label_filter: F, diff --git a/metrics-tracing-context/tests/integration.rs b/metrics-tracing-context/tests/integration.rs index ccceed30..14d6e50c 100644 --- a/metrics-tracing-context/tests/integration.rs +++ b/metrics-tracing-context/tests/integration.rs @@ -522,7 +522,7 @@ fn test_nested_spans() { ); } -#[derive(Clone)] +#[derive(Clone, Debug)] struct OnlyUser; impl LabelFilter for OnlyUser { diff --git a/metrics-util/src/debugging.rs b/metrics-util/src/debugging.rs index d17a222f..2e5650ea 100644 --- a/metrics-util/src/debugging.rs +++ b/metrics-util/src/debugging.rs @@ -36,6 +36,7 @@ impl CompositeKeyName { } /// A point-in-time snapshot of all metrics in [`DebuggingRecorder`]. +#[derive(Debug)] pub struct Snapshot(Vec<(CompositeKey, Option, Option, DebugValue)>); impl Snapshot { @@ -67,6 +68,7 @@ pub enum DebugValue { Histogram(Vec>), } +#[derive(Debug)] struct Inner { registry: Registry, seen: Mutex>, @@ -84,7 +86,7 @@ impl Inner { } /// Captures point-in-time snapshots of [`DebuggingRecorder`]. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Snapshotter { inner: Arc, } @@ -138,6 +140,7 @@ impl Snapshotter { /// /// Callers can easily take snapshots of the metrics at any given time and get access /// to the raw values. +#[derive(Debug)] pub struct DebuggingRecorder { inner: Arc, } diff --git a/metrics-util/src/layers/fanout.rs b/metrics-util/src/layers/fanout.rs index 430b61d6..2c344510 100644 --- a/metrics-util/src/layers/fanout.rs +++ b/metrics-util/src/layers/fanout.rs @@ -1,10 +1,11 @@ -use std::sync::Arc; +use std::{fmt, sync::Arc}; use metrics::{ Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, KeyName, Metadata, Recorder, SharedString, Unit, }; +#[derive(Debug)] struct FanoutCounter { counters: Vec, } @@ -35,6 +36,7 @@ impl From for Counter { } } +#[derive(Debug)] struct FanoutGauge { gauges: Vec, } @@ -71,6 +73,7 @@ impl From for Gauge { } } +#[derive(Debug)] struct FanoutHistogram { histograms: Vec, } @@ -100,6 +103,12 @@ pub struct Fanout { recorders: Vec>, } +impl fmt::Debug for Fanout { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Fanout").finish_non_exhaustive() + } +} + impl Recorder for Fanout { fn describe_counter(&self, key_name: KeyName, unit: Option, description: SharedString) { for recorder in &self.recorders { @@ -155,6 +164,12 @@ pub struct FanoutBuilder { recorders: Vec>, } +impl fmt::Debug for FanoutBuilder { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FanoutBuilder").finish_non_exhaustive() + } +} + impl FanoutBuilder { /// Adds a recorder to the fanout list. pub fn add_recorder(mut self, recorder: R) -> FanoutBuilder diff --git a/metrics-util/src/layers/filter.rs b/metrics-util/src/layers/filter.rs index 4d0db28b..f516ce63 100644 --- a/metrics-util/src/layers/filter.rs +++ b/metrics-util/src/layers/filter.rs @@ -5,6 +5,7 @@ use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, Share /// Filters and discards metrics matching certain name patterns. /// /// More information on the behavior of the layer can be found in [`FilterLayer`]. +#[derive(Debug)] pub struct Filter { inner: R, automaton: AhoCorasick, @@ -73,7 +74,7 @@ impl Recorder for Filter { /// DFA, or case sensitivity. /// /// [ahocorasick]: https://en.wikipedia.org/wiki/Aho–Corasick_algorithm -#[derive(Default)] +#[derive(Default, Debug)] pub struct FilterLayer { patterns: Vec, case_insensitive: bool, diff --git a/metrics-util/src/layers/mod.rs b/metrics-util/src/layers/mod.rs index 30786d4f..94d6c457 100644 --- a/metrics-util/src/layers/mod.rs +++ b/metrics-util/src/layers/mod.rs @@ -12,7 +12,7 @@ //! # use metrics::NoopRecorder as BasicRecorder; //! # use metrics_util::layers::{Layer, Stack, PrefixLayer}; //! // A simple layer that denies any metrics that have "stairway" or "heaven" in their name. -//! #[derive(Default)] +//! #[derive(Default, Debug)] //! pub struct StairwayDeny(pub(crate) R); //! //! impl StairwayDeny { @@ -75,7 +75,7 @@ //! } //! } //! -//! #[derive(Default)] +//! #[derive(Debug, Default)] //! pub struct StairwayDenyLayer; //! //! impl Layer for StairwayDenyLayer { @@ -137,6 +137,7 @@ pub trait Layer { } /// Builder for composing layers together in a top-down/inside-out order. +#[derive(Debug)] pub struct Stack { inner: R, } diff --git a/metrics-util/src/layers/prefix.rs b/metrics-util/src/layers/prefix.rs index 6c4f3829..58d5156f 100644 --- a/metrics-util/src/layers/prefix.rs +++ b/metrics-util/src/layers/prefix.rs @@ -4,6 +4,7 @@ use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, Share /// Applies a prefix to every metric key. /// /// Keys will be prefixed in the format of `.`. +#[derive(Debug)] pub struct Prefix { prefix: SharedString, inner: R, @@ -64,6 +65,7 @@ impl Recorder for Prefix { /// A layer for applying a prefix to every metric key. /// /// More information on the behavior of the layer can be found in [`Prefix`]. +#[derive(Debug)] pub struct PrefixLayer(&'static str); impl PrefixLayer { diff --git a/metrics-util/src/layers/router.rs b/metrics-util/src/layers/router.rs index 867049d1..e8fd26af 100644 --- a/metrics-util/src/layers/router.rs +++ b/metrics-util/src/layers/router.rs @@ -1,3 +1,5 @@ +use std::fmt; + use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, SharedString, Unit}; use radix_trie::{Trie, TrieCommon}; @@ -15,6 +17,16 @@ pub struct Router { histogram_routes: Trie, } +impl fmt::Debug for Router { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Router") + .field("global_mask", &self.global_mask) + .field("counter_routes", &self.counter_routes) + .field("gauge_routes", &self.gauge_routes) + .field("histogram_routes", &self.histogram_routes) + .finish_non_exhaustive() + } +} impl Router { fn route( &self, @@ -87,6 +99,17 @@ pub struct RouterBuilder { histogram_routes: Trie, } +impl fmt::Debug for RouterBuilder { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RouterBuilder") + .field("global_mask", &self.global_mask) + .field("counter_routes", &self.counter_routes) + .field("gauge_routes", &self.gauge_routes) + .field("histogram_routes", &self.histogram_routes) + .finish_non_exhaustive() + } +} + impl RouterBuilder { /// Creates a [`RouterBuilder`] from a [`Recorder`]. /// @@ -175,6 +198,7 @@ mod tests { }; mock! { + #[derive(Debug)] pub TestRecorder { } diff --git a/metrics-util/src/recoverable.rs b/metrics-util/src/recoverable.rs index ac2b311f..6c3b88b2 100644 --- a/metrics-util/src/recoverable.rs +++ b/metrics-util/src/recoverable.rs @@ -5,6 +5,7 @@ use metrics::{ Unit, }; +#[derive(Debug)] pub struct RecoveryHandle { handle: Arc, } @@ -51,6 +52,7 @@ impl RecoveryHandle { /// This allows using `RecoveryHandle` as a drop guard, ensuring that by dropping it, the /// recorder itself will be dropped, and any finalization logic implemented for the recorder will be /// run. +#[derive(Debug)] pub struct RecoverableRecorder { handle: Arc, } @@ -88,6 +90,7 @@ impl RecoverableRecorder { } } +#[derive(Debug)] struct WeakRecorder { recorder: Weak, } @@ -149,8 +152,13 @@ mod tests { use super::*; use metrics::{atomics::AtomicU64, CounterFn, GaugeFn, HistogramFn, Key, Recorder}; + #[derive(Debug)] struct CounterWrapper(AtomicU64); + + #[derive(Debug)] struct GaugeWrapper(AtomicU64); + + #[derive(Debug)] struct HistogramWrapper(AtomicU64); impl CounterWrapper { @@ -201,6 +209,7 @@ mod tests { } } + #[derive(Debug)] struct TestRecorder { dropped: Arc, counter: Arc, diff --git a/metrics-util/src/registry/mod.rs b/metrics-util/src/registry/mod.rs index d68cd4be..d7375b49 100644 --- a/metrics-util/src/registry/mod.rs +++ b/metrics-util/src/registry/mod.rs @@ -45,6 +45,7 @@ type RegistryHashMap = HashMap>; /// ## Performance /// /// `Registry` is optimized for reads. +#[derive(Debug)] pub struct Registry where S: Storage, diff --git a/metrics-util/src/registry/recency.rs b/metrics-util/src/registry/recency.rs index 0ccf014a..5a2d436b 100644 --- a/metrics-util/src/registry/recency.rs +++ b/metrics-util/src/registry/recency.rs @@ -54,7 +54,7 @@ pub struct Generation(usize); /// again at a later point in time, it could have changed in between the two observations. It also /// may not have changed, and thus `Generational` provides a way to determine if either of these /// events occurred. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Generational { inner: T, gen: Arc, @@ -157,6 +157,7 @@ where /// /// Tracks the "generation" of a metric, which is used to detect updates to metrics where the value /// otherwise would not be sufficient to be used as an indicator. +#[derive(Debug)] pub struct GenerationalStorage { inner: S, } @@ -215,6 +216,7 @@ impl GenerationalAtomicStorage { /// /// [`Recency`] is separate from [`Registry`] specifically to avoid imposing any slowdowns when /// tracking recency does not matter, despite their otherwise tight coupling. +#[derive(Debug)] pub struct Recency { mask: MetricKindMask, inner: Mutex<(Clock, HashMap)>, diff --git a/metrics-util/src/registry/storage.rs b/metrics-util/src/registry/storage.rs index 0e61cf9a..0e6ca0a5 100644 --- a/metrics-util/src/registry/storage.rs +++ b/metrics-util/src/registry/storage.rs @@ -29,6 +29,7 @@ pub trait Storage { /// /// Utilizes atomics for storing the value(s) of a given metric. Shared access to the actual atomic /// is handling via `Arc`. +#[derive(Debug)] pub struct AtomicStorage; impl Storage for AtomicStorage { diff --git a/metrics-util/src/summary.rs b/metrics-util/src/summary.rs index cd4c5cc2..4e65e104 100644 --- a/metrics-util/src/summary.rs +++ b/metrics-util/src/summary.rs @@ -45,6 +45,13 @@ pub struct Summary { sketch: DDSketch, } +impl fmt::Debug for Summary { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // manual implementation because DDSketch does not implement Debug + f.debug_struct("Summary").finish_non_exhaustive() + } +} + impl Summary { /// Creates a new [`Summary`]. /// diff --git a/metrics-util/src/test_util.rs b/metrics-util/src/test_util.rs index cae3fc1d..455ff165 100644 --- a/metrics-util/src/test_util.rs +++ b/metrics-util/src/test_util.rs @@ -5,7 +5,7 @@ use mockall::{ Predicate, }; -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum RecorderOperation { DescribeCounter(KeyName, Option, SharedString), DescribeGauge(KeyName, Option, SharedString), @@ -67,6 +67,7 @@ impl RecorderOperation { } mock! { + #[derive(Debug)] pub BasicRecorder {} impl Recorder for BasicRecorder { diff --git a/metrics/benches/macros.rs b/metrics/benches/macros.rs index 291d143f..3253584c 100644 --- a/metrics/benches/macros.rs +++ b/metrics/benches/macros.rs @@ -8,7 +8,7 @@ use metrics::{ }; use rand::{thread_rng, Rng}; -#[derive(Default)] +#[derive(Debug, Default)] struct TestRecorder; impl Recorder for TestRecorder { fn describe_counter(&self, _: KeyName, _: Option, _: SharedString) {} diff --git a/metrics/examples/basic.rs b/metrics/examples/basic.rs index 8d638386..b7bdc9d9 100644 --- a/metrics/examples/basic.rs +++ b/metrics/examples/basic.rs @@ -13,6 +13,7 @@ use metrics::{ }; use metrics::{Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, Recorder, Unit}; +#[derive(Clone, Debug)] struct PrintHandle(Key); impl CounterFn for PrintHandle { @@ -45,7 +46,7 @@ impl HistogramFn for PrintHandle { } } -#[derive(Default)] +#[derive(Debug, Default)] struct PrintRecorder; impl Recorder for PrintRecorder { diff --git a/metrics/src/common.rs b/metrics/src/common.rs index e3bdecd0..b97658d9 100644 --- a/metrics/src/common.rs +++ b/metrics/src/common.rs @@ -23,7 +23,7 @@ pub type SharedString = Cow<'static, str>; /// /// For any use-case within a `metrics`-owned or adjacent crate, where hashing of a key is required, /// this is the hasher that will be used. -#[derive(Default)] +#[derive(Debug, Default)] pub struct KeyHasher(AHasher); impl Hasher for KeyHasher { diff --git a/metrics/src/cow.rs b/metrics/src/cow.rs index 2338c220..c510673c 100644 --- a/metrics/src/cow.rs +++ b/metrics/src/cow.rs @@ -412,7 +412,7 @@ unsafe impl Sync for Cow<'_, T> {} unsafe impl Send for Cow<'_, T> {} #[repr(C)] -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Metadata(usize, usize); impl Metadata { diff --git a/metrics/src/handles.rs b/metrics/src/handles.rs index 33dc62d2..ccc7e6ac 100644 --- a/metrics/src/handles.rs +++ b/metrics/src/handles.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{fmt::Debug, sync::Arc}; use crate::IntoF64; @@ -45,6 +45,12 @@ pub struct Counter { inner: Option>, } +impl Debug for Counter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Counter").finish_non_exhaustive() + } +} + /// A gauge. #[derive(Clone)] #[must_use = "gauges do nothing unless you use them"] @@ -52,6 +58,12 @@ pub struct Gauge { inner: Option>, } +impl Debug for Gauge { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Gauge").finish_non_exhaustive() + } +} + /// A histogram. #[derive(Clone)] #[must_use = "histograms do nothing unless you use them"] @@ -59,6 +71,12 @@ pub struct Histogram { inner: Option>, } +impl Debug for Histogram { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Histogram").finish_non_exhaustive() + } +} + impl Counter { /// Creates a no-op `Counter` which does nothing. /// diff --git a/metrics/src/recorder/cell.rs b/metrics/src/recorder/cell.rs index 5450b6f0..a13feb1f 100644 --- a/metrics/src/recorder/cell.rs +++ b/metrics/src/recorder/cell.rs @@ -14,6 +14,7 @@ const INITIALIZING: usize = 1; const INITIALIZED: usize = 2; /// An specialized version of `OnceCell` for `Recorder`. +#[derive(Debug)] pub struct RecorderOnceCell { recorder: UnsafeCell>, state: AtomicUsize, diff --git a/metrics/src/recorder/mod.rs b/metrics/src/recorder/mod.rs index 8470d7cc..0cb0cd4b 100644 --- a/metrics/src/recorder/mod.rs +++ b/metrics/src/recorder/mod.rs @@ -154,6 +154,7 @@ mod tests { // This test simply ensures that if a boxed recorder is handed to us to install, and another // recorder has already been installed, that we drop th new boxed recorder instead of // leaking it. + #[derive(Debug)] struct TrackOnDropRecorder(Arc); impl TrackOnDropRecorder { diff --git a/metrics/src/recorder/noop.rs b/metrics/src/recorder/noop.rs index 8c44fb6b..b7dbcfb0 100644 --- a/metrics/src/recorder/noop.rs +++ b/metrics/src/recorder/noop.rs @@ -4,6 +4,7 @@ use crate::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, SharedS /// /// Used as the default recorder when one has not been installed yet. Useful for acting as the root /// recorder when testing layers. +#[derive(Debug)] pub struct NoopRecorder; impl Recorder for NoopRecorder {