Skip to content

Fix vector.dev's histograms representation #3691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 8 additions & 55 deletions src/metrics/log_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ fn families_to_json_events(families: &[MetricFamily]) -> Vec<VectorEvent<'_>> {
// We need to convert from cumulative counts (used by the Prometheus library)
// to plain counts (used by Vector).
let mut buckets = Vec::new();
let mut counts = Vec::new();
let mut last_cumulative_count = 0;
for bucket in histogram.get_bucket() {
buckets.push(VectorHistogramBucket {
upper_limit: bucket.get_upper_bound(),
count: bucket.get_cumulative_count() - last_cumulative_count,
});
buckets.push(bucket.get_upper_bound());
counts.push(bucket.get_cumulative_count() - last_cumulative_count);
last_cumulative_count = bucket.get_cumulative_count();
}

VectorMetricData::AggregatedHistogram {
count: histogram.get_sample_count(),
sum: histogram.get_sample_sum(),
buckets,
counts,
}
}
other => {
Expand Down Expand Up @@ -191,7 +191,8 @@ struct VectorMetric<'a> {
#[serde(rename_all = "snake_case")]
enum VectorMetricData {
AggregatedHistogram {
buckets: Vec<VectorHistogramBucket>,
buckets: Vec<f64>,
counts: Vec<u64>,
count: u64,
sum: f64,
},
Expand All @@ -203,12 +204,6 @@ enum VectorMetricData {
},
}

#[derive(Serialize, Debug, PartialEq)]
struct VectorHistogramBucket {
upper_limit: f64,
count: u64,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -304,51 +299,9 @@ mod tests {
metric: VectorMetric {
data: VectorMetricData::AggregatedHistogram {
buckets: vec![
VectorHistogramBucket {
upper_limit: 0.005,
count: 6,
},
VectorHistogramBucket {
upper_limit: 0.01,
count: 4,
},
VectorHistogramBucket {
upper_limit: 0.025,
count: 15,
},
VectorHistogramBucket {
upper_limit: 0.05,
count: 25,
},
VectorHistogramBucket {
upper_limit: 0.1,
count: 50,
},
VectorHistogramBucket {
upper_limit: 0.25,
count: 150,
},
VectorHistogramBucket {
upper_limit: 0.5,
count: 250,
},
VectorHistogramBucket {
upper_limit: 1.0,
count: 500,
},
VectorHistogramBucket {
upper_limit: 2.5,
count: 1501,
},
VectorHistogramBucket {
upper_limit: 5.0,
count: 2499,
},
VectorHistogramBucket {
upper_limit: 10.0,
count: 5001,
},
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
],
counts: vec![6, 4, 15, 25, 50, 150, 250, 500, 1501, 2499, 5001,],
count: 11001,
sum: 60505.50000000138,
},
Expand Down