Skip to content

Commit d77697c

Browse files
rcohjlizen
andauthored
Add #[derive(Debug)] to TimestampValue (#200)
✍️ *Description of changes:* Missing debug impls caused breaking changes 🔏 *By submitting this pull request* - [x] I confirm that I've made a best effort attempt to update all relevant documentation. - [x] I confirm that my contribution is made under the terms of the Apache 2.0 license. Co-authored-by: Jess Izen <44884346+jlizen@users.noreply.github.com>
1 parent b88a88b commit d77697c

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

metrique-writer-core/src/value/dimensions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ impl<V, const N: usize> WithDimensions<V, N> {
273273
}
274274
}
275275

276+
#[derive(Debug)]
276277
struct Wrapper<'a, V> {
277278
value: V,
278279
dimensions: &'a [(CowStr, CowStr)],

metrique-writer-core/src/value/formatter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ where
149149

150150
#[doc(hidden)]
151151
/// A wrapper for a value that formats using a [ValueFormatter]
152+
#[derive(Debug)]
152153
pub struct FormattedValue<'a, V, VF, L = Lifted>(PhantomData<(VF, L)>, &'a V);
153154

154155
impl<'a, V, VF, L> FormattedValue<'a, V, VF, L> {

metrique/src/timers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl Default for Timestamp {
100100
/// stop: TimestampOnClose
101101
/// }
102102
/// ```
103+
#[derive(Debug)]
103104
pub struct TimestampOnClose {
104105
time_source: TimeSource,
105106
}
@@ -130,7 +131,7 @@ pub type EpochMillis = TimestampFormat<Millisecond>;
130131
pub type EpochMicros = TimestampFormat<Microsecond>;
131132

132133
/// The type returned when `Timestamp` types are closed
133-
#[derive(Copy, Clone)]
134+
#[derive(Copy, Clone, Debug)]
134135
pub struct TimestampValue {
135136
duration_since_epoch: Duration,
136137
}

metrique/tests/debug-impls.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
use std::time::UNIX_EPOCH;
2+
13
use assert2::check;
2-
use metrique::{OnParentDrop, Slot};
4+
use metrique::{
5+
OnParentDrop, Slot,
6+
timers::{EpochMicros, Timestamp, TimestampOnClose},
7+
};
38
use metrique_macro::metrics;
9+
use metrique_timesource::{TimeSource, set_time_source};
410
use metrique_writer::sink::DevNullSink;
511

612
#[metrics(rename_all = "PascalCase")]
@@ -13,10 +19,13 @@ struct Metrics {
1319
c: Slot<AnotherNested>,
1420
}
1521

16-
#[metrics(subfield)]
17-
#[derive(Default, Clone, Debug)]
22+
#[metrics(subfield_owned)]
23+
#[derive(Default, Debug)]
1824
struct Nested {
1925
inner_value: usize,
26+
timer: TimestampOnClose,
27+
#[metrics(format = EpochMicros)]
28+
formatted: Timestamp,
2029
}
2130

2231
#[metrics(subfield)]
@@ -25,11 +34,16 @@ struct AnotherNested {
2534
another_value: usize,
2635
}
2736

28-
#[tokio::test]
37+
#[tokio::test(start_paused = true)]
2938
async fn debug_slot_closed() {
39+
let _mock_time = set_time_source(TimeSource::tokio(UNIX_EPOCH));
3040
let mut metrics = Metrics {
3141
a: 42,
32-
b: Slot::new(Nested { inner_value: 123 }),
42+
b: Slot::new(Nested {
43+
inner_value: 123,
44+
timer: TimestampOnClose::default(),
45+
formatted: Timestamp::default(),
46+
}),
3347
c: Slot::new(AnotherNested { another_value: 456 }),
3448
};
3549

@@ -42,15 +56,20 @@ async fn debug_slot_closed() {
4256
metrics.b.wait_for_data().await;
4357
check!(
4458
format!("{:?}", metrics.b)
45-
== "Slot { open: true, has_data: true, data: Some(NestedEntry { inner_value: 1000 }) }"
59+
== "Slot { open: true, has_data: true, data: Some(NestedEntry { inner_value: 1000, timer: TimestampValue { duration_since_epoch: 0ns }, formatted: TimestampValue { duration_since_epoch: 0ns } }) }"
4660
);
4761
}
4862

4963
#[test]
5064
fn debug_slot_open() {
65+
let _mock_time = set_time_source(TimeSource::tokio(UNIX_EPOCH));
5166
let mut metrics = Metrics {
5267
a: 99,
53-
b: Slot::new(Nested { inner_value: 200 }),
68+
b: Slot::new(Nested {
69+
inner_value: 200,
70+
timer: TimestampOnClose::default(),
71+
formatted: Timestamp::default(),
72+
}),
5473
c: Slot::new(AnotherNested { another_value: 300 }),
5574
};
5675

@@ -71,23 +90,28 @@ fn debug_slot_open() {
7190
);
7291
}
7392

74-
#[test]
75-
fn debug_slot_guard() {
93+
#[tokio::test(start_paused = true)]
94+
async fn debug_slot_guard() {
95+
let _mock_time = set_time_source(TimeSource::tokio(UNIX_EPOCH));
7696
let mut metrics = Metrics {
7797
a: 1,
78-
b: Slot::new(Nested { inner_value: 777 }),
98+
b: Slot::new(Nested {
99+
inner_value: 777,
100+
timer: TimestampOnClose::default(),
101+
formatted: Timestamp::default(),
102+
}),
79103
c: Slot::new(AnotherNested { another_value: 888 }),
80104
};
81105

82106
let guard_b = metrics.b.open(OnParentDrop::Discard).unwrap();
83107

84108
check!(
85109
format!("{:?}", guard_b)
86-
== "SlotGuard { value: Nested { inner_value: 777 }, parent_is_closed: false, parent_drop_mode: Discard }"
110+
== "SlotGuard { value: Nested { inner_value: 777, timer: TimestampOnClose { time_source: TimeSource::Custom(...) }, formatted: Timestamp { time: SystemTime { tv_sec: 0, tv_nsec: 0 } } }, parent_is_closed: false, parent_drop_mode: Discard }"
87111
);
88112
drop(metrics);
89113
check!(
90114
format!("{:?}", guard_b)
91-
== "SlotGuard { value: Nested { inner_value: 777 }, parent_is_closed: true, parent_drop_mode: Discard }"
115+
== "SlotGuard { value: Nested { inner_value: 777, timer: TimestampOnClose { time_source: TimeSource::Custom(...) }, formatted: Timestamp { time: SystemTime { tv_sec: 0, tv_nsec: 0 } } }, parent_is_closed: true, parent_drop_mode: Discard }"
92116
);
93117
}

0 commit comments

Comments
 (0)