Skip to content

Commit a56fc2f

Browse files
authored
Derive Debug trait for all structs and enums (#504)
1 parent 55273f0 commit a56fc2f

File tree

30 files changed

+128
-17
lines changed

30 files changed

+128
-17
lines changed

metrics-exporter-prometheus/src/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub enum BuildError {
8080
ZeroBucketDuration,
8181
}
8282

83+
#[derive(Debug)]
8384
pub struct Snapshot {
8485
pub counters: HashMap<String, HashMap<Vec<String>, u64>>,
8586
pub gauges: HashMap<String, HashMap<Vec<String>, f64>>,

metrics-exporter-prometheus/src/distribution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const DEFAULT_SUMMARY_BUCKET_COUNT: NonZeroU32 = match NonZeroU32::new(3) {
1515
const DEFAULT_SUMMARY_BUCKET_DURATION: Duration = Duration::from_secs(20);
1616

1717
/// Distribution type.
18-
#[derive(Clone)]
18+
#[derive(Clone, Debug)]
1919
pub enum Distribution {
2020
/// A Prometheus histogram.
2121
///
@@ -137,14 +137,14 @@ impl DistributionBuilder {
137137
}
138138
}
139139

140-
#[derive(Clone)]
140+
#[derive(Clone, Debug)]
141141
struct Bucket {
142142
begin: Instant,
143143
summary: Summary,
144144
}
145145

146146
/// A `RollingSummary` manages a list of [Summary] so that old results can be expired.
147-
#[derive(Clone)]
147+
#[derive(Clone, Debug)]
148148
pub struct RollingSummary {
149149
// Buckets are ordered with the latest buckets first. The buckets are kept in alignment based
150150
// on the instant of the first added bucket and the bucket_duration. There may be gaps in the

metrics-exporter-prometheus/src/exporter/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use super::ExporterConfig;
3333
use super::ExporterFuture;
3434

3535
/// Builder for creating and installing a Prometheus recorder/exporter.
36+
#[derive(Debug)]
3637
pub struct PrometheusBuilder {
3738
#[cfg_attr(not(any(feature = "http-listener", feature = "push-gateway")), allow(dead_code))]
3839
exporter_config: ExporterConfig,

metrics-exporter-prometheus/src/exporter/http_listener.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum ListenerType {
3232
}
3333

3434
/// Error type for HTTP listening.
35+
#[derive(Debug)]
3536
pub enum HttpListeningError {
3637
Hyper(hyper::Error),
3738
Io(std::io::Error),

metrics-exporter-prometheus/src/exporter/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use hyper::Uri;
1414

1515
/// Error types possible from an exporter
1616
#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
17+
#[derive(Debug)]
1718
pub enum ExporterError {
1819
#[cfg(feature = "http-listener")]
1920
HttpListener(HttpListeningError),
@@ -24,14 +25,14 @@ pub enum ExporterError {
2425
pub type ExporterFuture = Pin<Box<dyn Future<Output = Result<(), ExporterError>> + Send + 'static>>;
2526

2627
#[cfg(feature = "http-listener")]
27-
#[derive(Clone)]
28+
#[derive(Clone, Debug)]
2829
enum ListenDestination {
2930
Tcp(SocketAddr),
3031
#[cfg(feature = "uds-listener")]
3132
Uds(std::path::PathBuf),
3233
}
3334

34-
#[derive(Clone)]
35+
#[derive(Clone, Debug)]
3536
enum ExporterConfig {
3637
// Run an HTTP listener on the given `listen_address`.
3738
#[cfg(feature = "http-listener")]

metrics-exporter-prometheus/src/recorder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::formatting::{
1515
};
1616
use crate::registry::GenerationalAtomicStorage;
1717

18+
#[derive(Debug)]
1819
pub(crate) struct Inner {
1920
pub registry: Registry<Key, GenerationalAtomicStorage>,
2021
pub recency: Recency<Key>,
@@ -214,6 +215,7 @@ impl Inner {
214215
/// Most users will not need to interact directly with the recorder, and can simply deal with the
215216
/// builder methods on [`PrometheusBuilder`](crate::PrometheusBuilder) for building and installing
216217
/// the recorder/exporter.
218+
#[derive(Debug)]
217219
pub struct PrometheusRecorder {
218220
inner: Arc<Inner>,
219221
}
@@ -275,7 +277,7 @@ impl Recorder for PrometheusRecorder {
275277
/// handled directly by the HTTP listener, or push gateway background task. [`PrometheusHandle`]
276278
/// allows rendering a snapshot of the current metrics stored by an installed [`PrometheusRecorder`]
277279
/// as a payload conforming to the Prometheus exposition format.
278-
#[derive(Clone)]
280+
#[derive(Clone, Debug)]
279281
pub struct PrometheusHandle {
280282
inner: Arc<Inner>,
281283
}

metrics-exporter-prometheus/src/registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use quanta::Instant;
77
pub type GenerationalAtomicStorage = GenerationalStorage<AtomicStorage>;
88

99
/// Atomic metric storage for the prometheus exporter.
10+
#[derive(Debug)]
1011
pub struct AtomicStorage;
1112

1213
impl<K> metrics_util::registry::Storage<K> for AtomicStorage {
@@ -28,6 +29,7 @@ impl<K> metrics_util::registry::Storage<K> for AtomicStorage {
2829
}
2930

3031
/// An `AtomicBucket` newtype wrapper that tracks the time of value insertion.
32+
#[derive(Debug)]
3133
pub struct AtomicBucketInstant<T> {
3234
inner: AtomicBucket<(T, Instant)>,
3335
}

metrics-exporter-tcp/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl std::error::Error for Error {
137137
}
138138
}
139139

140+
#[derive(Debug)]
140141
struct State {
141142
client_count: AtomicUsize,
142143
should_send: AtomicBool,
@@ -188,6 +189,7 @@ impl State {
188189
}
189190
}
190191

192+
#[derive(Debug)]
191193
struct Handle {
192194
key: Key,
193195
state: Arc<State>,
@@ -230,11 +232,13 @@ impl HistogramFn for Handle {
230232
}
231233

232234
/// A TCP recorder.
235+
#[derive(Debug)]
233236
pub struct TcpRecorder {
234237
state: Arc<State>,
235238
}
236239

237240
/// Builder for creating and installing a TCP recorder/exporter.
241+
#[derive(Debug)]
238242
pub struct TcpBuilder {
239243
listen_addr: SocketAddr,
240244
buffer_size: Option<usize>,

metrics-tracing-context/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ use tracing_integration::Map;
114114
pub use tracing_integration::{Labels, MetricsLayer};
115115

116116
/// [`TracingContextLayer`] provides an implementation of a [`Layer`] for [`TracingContext`].
117+
#[derive(Debug)]
117118
pub struct TracingContextLayer<F> {
118119
label_filter: F,
119120
}
@@ -156,6 +157,7 @@ where
156157
}
157158

158159
/// [`TracingContext`] is a [`metrics::Recorder`] that injects labels from [`tracing::Span`]s.
160+
#[derive(Debug)]
159161
pub struct TracingContext<R, F> {
160162
inner: R,
161163
label_filter: F,

metrics-tracing-context/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ fn test_nested_spans() {
522522
);
523523
}
524524

525-
#[derive(Clone)]
525+
#[derive(Clone, Debug)]
526526
struct OnlyUser;
527527

528528
impl LabelFilter for OnlyUser {

metrics-util/src/debugging.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl CompositeKeyName {
3636
}
3737

3838
/// A point-in-time snapshot of all metrics in [`DebuggingRecorder`].
39+
#[derive(Debug)]
3940
pub struct Snapshot(Vec<(CompositeKey, Option<Unit>, Option<SharedString>, DebugValue)>);
4041

4142
impl Snapshot {
@@ -67,6 +68,7 @@ pub enum DebugValue {
6768
Histogram(Vec<OrderedFloat<f64>>),
6869
}
6970

71+
#[derive(Debug)]
7072
struct Inner {
7173
registry: Registry<Key, AtomicStorage>,
7274
seen: Mutex<IndexMap<CompositeKey, ()>>,
@@ -84,7 +86,7 @@ impl Inner {
8486
}
8587

8688
/// Captures point-in-time snapshots of [`DebuggingRecorder`].
87-
#[derive(Clone)]
89+
#[derive(Clone, Debug)]
8890
pub struct Snapshotter {
8991
inner: Arc<Inner>,
9092
}
@@ -138,6 +140,7 @@ impl Snapshotter {
138140
///
139141
/// Callers can easily take snapshots of the metrics at any given time and get access
140142
/// to the raw values.
143+
#[derive(Debug)]
141144
pub struct DebuggingRecorder {
142145
inner: Arc<Inner>,
143146
}

metrics-util/src/layers/fanout.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use std::sync::Arc;
1+
use std::{fmt, sync::Arc};
22

33
use metrics::{
44
Counter, CounterFn, Gauge, GaugeFn, Histogram, HistogramFn, Key, KeyName, Metadata, Recorder,
55
SharedString, Unit,
66
};
77

8+
#[derive(Debug)]
89
struct FanoutCounter {
910
counters: Vec<Counter>,
1011
}
@@ -35,6 +36,7 @@ impl From<FanoutCounter> for Counter {
3536
}
3637
}
3738

39+
#[derive(Debug)]
3840
struct FanoutGauge {
3941
gauges: Vec<Gauge>,
4042
}
@@ -71,6 +73,7 @@ impl From<FanoutGauge> for Gauge {
7173
}
7274
}
7375

76+
#[derive(Debug)]
7477
struct FanoutHistogram {
7578
histograms: Vec<Histogram>,
7679
}
@@ -100,6 +103,14 @@ pub struct Fanout {
100103
recorders: Vec<Box<dyn Recorder>>,
101104
}
102105

106+
impl fmt::Debug for Fanout {
107+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108+
f.debug_struct("Fanout")
109+
.field("recorders_len", &self.recorders.len())
110+
.finish_non_exhaustive()
111+
}
112+
}
113+
103114
impl Recorder for Fanout {
104115
fn describe_counter(&self, key_name: KeyName, unit: Option<Unit>, description: SharedString) {
105116
for recorder in &self.recorders {
@@ -155,6 +166,14 @@ pub struct FanoutBuilder {
155166
recorders: Vec<Box<dyn Recorder>>,
156167
}
157168

169+
impl fmt::Debug for FanoutBuilder {
170+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171+
f.debug_struct("FanoutBuilder")
172+
.field("recorders_len", &self.recorders.len())
173+
.finish_non_exhaustive()
174+
}
175+
}
176+
158177
impl FanoutBuilder {
159178
/// Adds a recorder to the fanout list.
160179
pub fn add_recorder<R>(mut self, recorder: R) -> FanoutBuilder

metrics-util/src/layers/filter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, Share
55
/// Filters and discards metrics matching certain name patterns.
66
///
77
/// More information on the behavior of the layer can be found in [`FilterLayer`].
8+
#[derive(Debug)]
89
pub struct Filter<R> {
910
inner: R,
1011
automaton: AhoCorasick,
@@ -73,7 +74,7 @@ impl<R: Recorder> Recorder for Filter<R> {
7374
/// DFA, or case sensitivity.
7475
///
7576
/// [ahocorasick]: https://en.wikipedia.org/wiki/Aho–Corasick_algorithm
76-
#[derive(Default)]
77+
#[derive(Default, Debug)]
7778
pub struct FilterLayer {
7879
patterns: Vec<String>,
7980
case_insensitive: bool,

metrics-util/src/layers/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! # use metrics::NoopRecorder as BasicRecorder;
1313
//! # use metrics_util::layers::{Layer, Stack, PrefixLayer};
1414
//! // A simple layer that denies any metrics that have "stairway" or "heaven" in their name.
15-
//! #[derive(Default)]
15+
//! #[derive(Default, Debug)]
1616
//! pub struct StairwayDeny<R>(pub(crate) R);
1717
//!
1818
//! impl<R> StairwayDeny<R> {
@@ -75,7 +75,7 @@
7575
//! }
7676
//! }
7777
//!
78-
//! #[derive(Default)]
78+
//! #[derive(Debug, Default)]
7979
//! pub struct StairwayDenyLayer;
8080
//!
8181
//! impl<R> Layer<R> for StairwayDenyLayer {
@@ -137,6 +137,7 @@ pub trait Layer<R> {
137137
}
138138

139139
/// Builder for composing layers together in a top-down/inside-out order.
140+
#[derive(Debug)]
140141
pub struct Stack<R> {
141142
inner: R,
142143
}

metrics-util/src/layers/prefix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, Share
44
/// Applies a prefix to every metric key.
55
///
66
/// Keys will be prefixed in the format of `<prefix>.<remaining>`.
7+
#[derive(Debug)]
78
pub struct Prefix<R> {
89
prefix: SharedString,
910
inner: R,
@@ -64,6 +65,7 @@ impl<R: Recorder> Recorder for Prefix<R> {
6465
/// A layer for applying a prefix to every metric key.
6566
///
6667
/// More information on the behavior of the layer can be found in [`Prefix`].
68+
#[derive(Debug)]
6769
pub struct PrefixLayer(&'static str);
6870

6971
impl PrefixLayer {

metrics-util/src/layers/router.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use metrics::{Counter, Gauge, Histogram, Key, KeyName, Metadata, Recorder, SharedString, Unit};
24
use radix_trie::{Trie, TrieCommon};
35

@@ -15,6 +17,17 @@ pub struct Router {
1517
histogram_routes: Trie<String, usize>,
1618
}
1719

20+
impl fmt::Debug for Router {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
f.debug_struct("Router")
23+
.field("global_mask", &self.global_mask)
24+
.field("targets_len", &self.targets.len())
25+
.field("counter_routes", &self.counter_routes)
26+
.field("gauge_routes", &self.gauge_routes)
27+
.field("histogram_routes", &self.histogram_routes)
28+
.finish_non_exhaustive()
29+
}
30+
}
1831
impl Router {
1932
fn route(
2033
&self,
@@ -87,6 +100,18 @@ pub struct RouterBuilder {
87100
histogram_routes: Trie<String, usize>,
88101
}
89102

103+
impl fmt::Debug for RouterBuilder {
104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105+
f.debug_struct("RouterBuilder")
106+
.field("global_mask", &self.global_mask)
107+
.field("targets_len", &self.targets.len())
108+
.field("counter_routes", &self.counter_routes)
109+
.field("gauge_routes", &self.gauge_routes)
110+
.field("histogram_routes", &self.histogram_routes)
111+
.finish_non_exhaustive()
112+
}
113+
}
114+
90115
impl RouterBuilder {
91116
/// Creates a [`RouterBuilder`] from a [`Recorder`].
92117
///
@@ -175,6 +200,7 @@ mod tests {
175200
};
176201

177202
mock! {
203+
#[derive(Debug)]
178204
pub TestRecorder {
179205
}
180206

0 commit comments

Comments
 (0)