Skip to content

Commit 0884c8c

Browse files
authored
Validation framework fix equivalence check for metrics (#2776)
# Change Summary This adds additional validation tests to check that all signals are preserved through otlp/otap receiver/exporters. Adds canonicalize_buckets fn to set values from None to Some(Buckets {offset: 0, bucket_counts: vec![]}). Before the validation tests involving metrics and otap receiver/exporters would fail, but now they are succeeding ## What issue does this PR close? * Closes #2786 ## How are these changes tested? validation test ## Are there any user-facing changes? no
1 parent 42ae9be commit 0884c8c

7 files changed

Lines changed: 415 additions & 6 deletions

File tree

rust/otap-dataflow/crates/pdata/src/testing/equiv/metrics.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use crate::proto::opentelemetry::metrics::v1::{
77
ExponentialHistogram, ExponentialHistogramDataPoint, Gauge, Histogram, HistogramDataPoint,
88
Metric, MetricsData, NumberDataPoint, ResourceMetrics, ScopeMetrics, Sum, Summary,
9-
SummaryDataPoint, metric,
9+
SummaryDataPoint, exponential_histogram_data_point::Buckets, metric,
1010
};
1111
use crate::testing::equiv::canonical::{
1212
assert_equivalent, canonicalize_any_value, canonicalize_resource, canonicalize_scope,
@@ -249,6 +249,22 @@ fn canonicalize_histogram_data_point(dp: &mut HistogramDataPoint) {
249249
});
250250
}
251251

252+
/// Normalize absent buckets to the default Buckets struct.
253+
/// The OTAP Arrow encoding cannot distinguish `None` from
254+
/// `Some(Buckets { offset: 0, bucket_counts: [] })` because
255+
/// `BucketsRecordBatchBuilder` stores both as a non-null struct
256+
/// with default values. Canonicalize `None` -> `Some(default)` so
257+
/// the equivalence check is not affected by this known
258+
/// encode/decode limitation.
259+
fn canonicalize_buckets(buckets: &mut Option<Buckets>) {
260+
if buckets.is_none() {
261+
*buckets = Some(Buckets {
262+
offset: 0,
263+
bucket_counts: vec![],
264+
});
265+
}
266+
}
267+
252268
fn canonicalize_exp_histogram_data_point(dp: &mut ExponentialHistogramDataPoint) {
253269
canonicalize_vec(&mut dp.attributes, |attr| {
254270
if let Some(value) = &mut attr.value {
@@ -262,6 +278,9 @@ fn canonicalize_exp_histogram_data_point(dp: &mut ExponentialHistogramDataPoint)
262278
}
263279
});
264280
});
281+
282+
canonicalize_buckets(&mut dp.positive);
283+
canonicalize_buckets(&mut dp.negative);
265284
}
266285

267286
fn canonicalize_summary_data_point(dp: &mut SummaryDataPoint) {

0 commit comments

Comments
 (0)