Skip to content

Commit 623bc09

Browse files
author
tresendiz
committed
update some ddsketch fields from histogram
1 parent dbc805a commit 623bc09

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/vector-core/src/metrics/ddsketch.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ impl AgentDDSketch {
779779
/// ## Errors
780780
///
781781
/// Returns an error if a bucket size is greater that `u32::MAX`.
782+
#[allow(clippy::cast_possible_truncation)]
783+
#[allow(clippy::cast_precision_loss)]
782784
pub fn transform_to_sketch(mut metric: Metric) -> Result<Metric, &'static str> {
783785
let sketch = match metric.data_mut().value_mut() {
784786
MetricValue::Distribution { samples, .. } => {
@@ -788,10 +790,24 @@ impl AgentDDSketch {
788790
}
789791
Some(sketch)
790792
}
791-
MetricValue::AggregatedHistogram { buckets, .. } => {
793+
MetricValue::AggregatedHistogram {
794+
buckets,
795+
sum,
796+
count,
797+
..
798+
} => {
792799
let delta_buckets = mem::take(buckets);
793800
let mut sketch = AgentDDSketch::with_agent_defaults();
794801
sketch.insert_interpolate_buckets(delta_buckets)?;
802+
803+
let orig_sum = *sum;
804+
let orig_count = *count;
805+
if orig_count > 0 {
806+
sketch.sum = orig_sum;
807+
sketch.count = orig_count as u32;
808+
sketch.avg = orig_sum / orig_count as f64;
809+
}
810+
795811
Some(sketch)
796812
}
797813
// We can't convert from any other metric value.

0 commit comments

Comments
 (0)