Skip to content

Commit fd03512

Browse files
committed
Auto merge of #3691 - pietroalbini:fix-histogram-repr, r=jtgeibel
Fix vector.dev's histograms representation Turns out that the data model used by Lua transforms is different than the data model used for the rest of Vector. r? `@jtgeibel`
2 parents d179227 + 25308d7 commit fd03512

File tree

1 file changed

+8
-55
lines changed

1 file changed

+8
-55
lines changed

src/metrics/log_encoder.rs

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ fn families_to_json_events(families: &[MetricFamily]) -> Vec<VectorEvent<'_>> {
7171
// We need to convert from cumulative counts (used by the Prometheus library)
7272
// to plain counts (used by Vector).
7373
let mut buckets = Vec::new();
74+
let mut counts = Vec::new();
7475
let mut last_cumulative_count = 0;
7576
for bucket in histogram.get_bucket() {
76-
buckets.push(VectorHistogramBucket {
77-
upper_limit: bucket.get_upper_bound(),
78-
count: bucket.get_cumulative_count() - last_cumulative_count,
79-
});
77+
buckets.push(bucket.get_upper_bound());
78+
counts.push(bucket.get_cumulative_count() - last_cumulative_count);
8079
last_cumulative_count = bucket.get_cumulative_count();
8180
}
8281

8382
VectorMetricData::AggregatedHistogram {
8483
count: histogram.get_sample_count(),
8584
sum: histogram.get_sample_sum(),
8685
buckets,
86+
counts,
8787
}
8888
}
8989
other => {
@@ -191,7 +191,8 @@ struct VectorMetric<'a> {
191191
#[serde(rename_all = "snake_case")]
192192
enum VectorMetricData {
193193
AggregatedHistogram {
194-
buckets: Vec<VectorHistogramBucket>,
194+
buckets: Vec<f64>,
195+
counts: Vec<u64>,
195196
count: u64,
196197
sum: f64,
197198
},
@@ -203,12 +204,6 @@ enum VectorMetricData {
203204
},
204205
}
205206

206-
#[derive(Serialize, Debug, PartialEq)]
207-
struct VectorHistogramBucket {
208-
upper_limit: f64,
209-
count: u64,
210-
}
211-
212207
#[cfg(test)]
213208
mod tests {
214209
use super::*;
@@ -304,51 +299,9 @@ mod tests {
304299
metric: VectorMetric {
305300
data: VectorMetricData::AggregatedHistogram {
306301
buckets: vec![
307-
VectorHistogramBucket {
308-
upper_limit: 0.005,
309-
count: 6,
310-
},
311-
VectorHistogramBucket {
312-
upper_limit: 0.01,
313-
count: 4,
314-
},
315-
VectorHistogramBucket {
316-
upper_limit: 0.025,
317-
count: 15,
318-
},
319-
VectorHistogramBucket {
320-
upper_limit: 0.05,
321-
count: 25,
322-
},
323-
VectorHistogramBucket {
324-
upper_limit: 0.1,
325-
count: 50,
326-
},
327-
VectorHistogramBucket {
328-
upper_limit: 0.25,
329-
count: 150,
330-
},
331-
VectorHistogramBucket {
332-
upper_limit: 0.5,
333-
count: 250,
334-
},
335-
VectorHistogramBucket {
336-
upper_limit: 1.0,
337-
count: 500,
338-
},
339-
VectorHistogramBucket {
340-
upper_limit: 2.5,
341-
count: 1501,
342-
},
343-
VectorHistogramBucket {
344-
upper_limit: 5.0,
345-
count: 2499,
346-
},
347-
VectorHistogramBucket {
348-
upper_limit: 10.0,
349-
count: 5001,
350-
},
302+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
351303
],
304+
counts: vec![6, 4, 15, 25, 50, 150, 250, 500, 1501, 2499, 5001,],
352305
count: 11001,
353306
sum: 60505.50000000138,
354307
},

0 commit comments

Comments
 (0)