Skip to content

Conversation

@cijothomas
Copy link
Member

PeriodicReader was unnecessarily creating a new empty ResourceMetrics during every collect. This PR modifies periodic reader to create once at startup, and re-use it throughout. Of course, the actual contents change for each collect, but the backing arrays for vectors will be re-used.

@cijothomas cijothomas requested a review from a team as a code owner May 14, 2025 01:30
@codecov
Copy link

codecov bot commented May 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.5%. Comparing base (8fe3dcc) to head (a3b56f1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2963   +/-   ##
=====================================
  Coverage   81.4%   81.5%           
=====================================
  Files        126     126           
  Lines      24305   24303    -2     
=====================================
+ Hits       19808   19816    +8     
+ Misses      4497    4487   -10     

☔ 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.

@hdost hdost force-pushed the cijothomas/reuse-metric branch from 2e1b749 to 9a785be Compare May 14, 2025 04:42
Copy link
Contributor

@hdost hdost left a comment

Choose a reason for hiding this comment

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

Please fix the lint otherwise good 👍

fn collect_and_export(&self, rm: &mut ResourceMetrics) -> OTelSdkResult {
let current_time = Instant::now();
let collect_result = self.collect(&mut rm);
let collect_result = self.collect(rm);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this still works without the need to clear the scope_metrics vec within the ResourceMetrics. I'm not sure if we have tests for this already but we need to ensure that clearing is not required by verifying that subsequent collects don't continue to show the old data from the previous collect (in case of Delta).

@cijothomas cijothomas merged commit 82e5ed4 into open-telemetry:main May 14, 2025
27 checks passed
@cijothomas cijothomas deleted the cijothomas/reuse-metric branch May 14, 2025 14:29
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.

3 participants