Skip to content

fix: Fix validation in Metric stream #2991

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 5 commits into from
May 22, 2025

Conversation

cijothomas
Copy link
Member

Most copy-pasted from instrument creation validation for now. A future refactor can move this to a common place and fully address #2986

@cijothomas cijothomas requested a review from a team as a code owner May 22, 2025 05:58
Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 89.28571% with 24 lines in your changes missing coverage. Please review.

Project coverage is 81.5%. Comparing base (8c29ca7) to head (5550cf2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-sdk/src/metrics/instrument.rs 89.2% 24 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main   #2991    +/-   ##
======================================
  Coverage   81.4%   81.5%            
======================================
  Files        126     126            
  Lines      24573   24796   +223     
======================================
+ Hits       20008   20213   +205     
- Misses      4565    4583    +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

result.err()
);
} else {
let err = result.err().unwrap();
Copy link
Contributor

@utpilla utpilla May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You could use unwrap_err() and possibly even get rid of the err.to_string() check below.

Suggested change
let err = result.err().unwrap();
let err = result.unwrap_err();

if let Some(limit) = self.cardinality_limit {
if limit == 0 {
return Err("Cardinality limit must be greater than 0".into());
}
}

// If the aggregation is set to ExplicitBucketHistogram, validate the bucket boundaries.
// Validate bucket boundaries if using ExplicitBucketHistogram
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are doing the validation while building the stream, we could get rid of this code:

#[cfg(feature = "spec_unstable_metrics_views")]
{
// TODO: When views are used, validate this upfront
bounds.retain(|v| !v.is_nan());
bounds.sort_by(|a, b| a.partial_cmp(b).expect("NaNs filtered out"));
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will tackle it soon.

@cijothomas cijothomas merged commit 2018959 into open-telemetry:main May 22, 2025
27 checks passed
@cijothomas cijothomas deleted the cijothomas/nits103 branch May 22, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants