Skip to content

Commit efd8a8d

Browse files
committed
debugging: add trace logging to show exactly which buckets are being flushed during aggregation
1 parent 77b3384 commit efd8a8d

File tree

7 files changed

+126
-5
lines changed

7 files changed

+126
-5
lines changed

Diff for: lib/saluki-components/src/transforms/aggregate/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,13 @@ impl AggregationState {
533533
// This means we'll always remove all-closed/empty non-counter metrics, and we _may_ remove all-closed/empty
534534
// counters.
535535
if let Some(closed_bucket_values) = am.values.split_at_timestamp(split_timestamp) {
536+
trace!(
537+
metric_name = &**context.name(),
538+
metric_tags = %context.tags(),
539+
points = %closed_bucket_values,
540+
"Flushing closed buckets."
541+
);
542+
536543
// We got some closed bucket values, so flush those out.
537544
transform_and_push_metric(
538545
context.clone(),

Diff for: lib/saluki-context/src/tags/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,22 @@ impl Tagged for TagSet {
368368
}
369369
}
370370

371+
impl fmt::Display for TagSet {
372+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
373+
write!(f, "[")?;
374+
375+
for (i, tag) in self.0.iter().enumerate() {
376+
if i > 0 {
377+
write!(f, ",")?;
378+
}
379+
380+
write!(f, "{}", tag.as_str())?;
381+
}
382+
383+
write!(f, "]")
384+
}
385+
}
386+
371387
/// A shared, read-only set of tags.
372388
#[derive(Clone, Debug)]
373389
pub struct SharedTagSet(Arc<TagSet>);

Diff for: lib/saluki-event/src/metric/value/histogram.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::NonZeroU64;
1+
use std::{fmt, num::NonZeroU64};
22

33
use ordered_float::OrderedFloat;
44
use smallvec::SmallVec;
@@ -291,6 +291,28 @@ impl<'a> IntoIterator for &'a mut HistogramPoints {
291291
}
292292
}
293293

294+
impl fmt::Display for HistogramPoints {
295+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
296+
write!(f, "[")?;
297+
for (i, point) in self.0.values.iter().enumerate() {
298+
if i > 0 {
299+
write!(f, ",")?;
300+
}
301+
302+
let ts = point.timestamp.map(|ts| ts.get()).unwrap_or_default();
303+
write!(f, "({}, [", ts)?;
304+
for (j, sample) in point.value.samples().iter().enumerate() {
305+
if j > 0 {
306+
write!(f, ",")?;
307+
}
308+
write!(f, "{{{} * {}}}", sample.value, sample.weight)?;
309+
}
310+
write!(f, "])")?;
311+
}
312+
write!(f, "]")
313+
}
314+
}
315+
294316
pub struct HistogramIter {
295317
inner: smallvec::IntoIter<[TimestampedValue<Histogram>; 1]>,
296318
}

Diff for: lib/saluki-event/src/metric/value/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod iter;
22

3-
use std::{collections::HashSet, num::NonZeroU64, time::Duration};
3+
use std::{collections::HashSet, fmt, num::NonZeroU64, time::Duration};
44

55
use ddsketch_agent::DDSketch;
66
use ordered_float::OrderedFloat;
@@ -472,6 +472,19 @@ impl MetricValues {
472472
}
473473
}
474474

475+
impl fmt::Display for MetricValues {
476+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
477+
match self {
478+
Self::Counter(points) => write!(f, "{}", points),
479+
Self::Rate(points, interval) => write!(f, "{} over {:?}", points, interval),
480+
Self::Gauge(points) => write!(f, "{}", points),
481+
Self::Set(points) => write!(f, "{}", points),
482+
Self::Histogram(points) => write!(f, "{}", points),
483+
Self::Distribution(points) => write!(f, "{}", points),
484+
}
485+
}
486+
}
487+
475488
fn collapse_scalar_merge(dest: &mut OrderedFloat<f64>, src: &mut OrderedFloat<f64>) {
476489
*dest += *src;
477490
}

Diff for: lib/saluki-event/src/metric/value/scalar.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::NonZeroU64;
1+
use std::{fmt, num::NonZeroU64};
22

33
use ordered_float::OrderedFloat;
44

@@ -145,3 +145,18 @@ impl<'a> IntoIterator for &'a ScalarPoints {
145145
PointsIterRef::scalar(self.0.values.iter())
146146
}
147147
}
148+
149+
impl fmt::Display for ScalarPoints {
150+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151+
write!(f, "[")?;
152+
for (i, (timestamp, value)) in self.into_iter().enumerate() {
153+
if i > 0 {
154+
write!(f, ",")?;
155+
}
156+
157+
let ts = timestamp.map(|ts| ts.get()).unwrap_or_default();
158+
write!(f, "({}, {})", ts, value)?;
159+
}
160+
write!(f, "]")
161+
}
162+
}

Diff for: lib/saluki-event/src/metric/value/set.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, num::NonZeroU64};
1+
use std::{collections::HashSet, fmt, num::NonZeroU64};
22

33
use super::{
44
iter::{PointsIter, PointsIterRef},
@@ -97,3 +97,25 @@ impl<'a> IntoIterator for &'a SetPoints {
9797
PointsIterRef::set(self.0.values.iter())
9898
}
9999
}
100+
101+
impl fmt::Display for SetPoints {
102+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103+
write!(f, "[")?;
104+
for (i, point) in self.0.values.iter().enumerate() {
105+
if i > 0 {
106+
write!(f, ",")?;
107+
}
108+
109+
let ts = point.timestamp.map(|ts| ts.get()).unwrap_or_default();
110+
write!(f, "({}, [", ts)?;
111+
for (j, value) in point.value.iter().enumerate() {
112+
if j > 0 {
113+
write!(f, ",")?;
114+
}
115+
write!(f, "{}", value)?;
116+
}
117+
write!(f, "])")?;
118+
}
119+
write!(f, "]")
120+
}
121+
}

Diff for: lib/saluki-event/src/metric/value/sketch.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::NonZeroU64;
1+
use std::{fmt, num::NonZeroU64};
22

33
use ddsketch_agent::DDSketch;
44

@@ -168,6 +168,32 @@ impl<'a> IntoIterator for &'a SketchPoints {
168168
}
169169
}
170170

171+
impl fmt::Display for SketchPoints {
172+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173+
write!(f, "[")?;
174+
for (i, point) in self.0.values.iter().enumerate() {
175+
if i > 0 {
176+
write!(f, ",")?;
177+
}
178+
179+
let ts = point.timestamp.map(|ts| ts.get()).unwrap_or_default();
180+
let sketch = &point.value;
181+
write!(
182+
f,
183+
"({}, {{cnt={} min={} max={} avg={} sum={} bin_count={}}})",
184+
ts,
185+
sketch.count(),
186+
sketch.min().unwrap_or(0.0),
187+
sketch.max().unwrap_or(0.0),
188+
sketch.avg().unwrap_or(0.0),
189+
sketch.sum().unwrap_or(0.0),
190+
sketch.bin_count(),
191+
)?;
192+
}
193+
write!(f, "]")
194+
}
195+
}
196+
171197
pub struct SketchesIter {
172198
inner: smallvec::IntoIter<[TimestampedValue<DDSketch>; 1]>,
173199
}

0 commit comments

Comments
 (0)