Skip to content
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

Test successful collection by PeriodicReader #1521

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

izquierdo
Copy link
Contributor

@izquierdo izquierdo commented Feb 8, 2024

Changes

Add a success scenario test for PeriodicReader as suggested in #1481 (comment)

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

Copy link

codecov bot commented Feb 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (49f1be6) 61.9% compared to head (4b8f83e) 62.8%.

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1521     +/-   ##
=======================================
+ Coverage   61.9%   62.8%   +0.9%     
=======================================
  Files        144     144             
  Lines      19862   19891     +29     
=======================================
+ Hits       12303   12502    +199     
+ Misses      7559    7389    -170     

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

@izquierdo izquierdo changed the title [WIP] Test successful collection by PeriodicReader Test successful collection by PeriodicReader Feb 9, 2024
@izquierdo izquierdo marked this pull request as ready for review February 9, 2024 21:25
@izquierdo izquierdo requested a review from a team February 9, 2024 21:25
use std::sync::mpsc;

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn registration_triggers_collection() {
Copy link
Member

Choose a reason for hiding this comment

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

not sure I follow the name of the test, as the trigger for collection is the time interval only...
The test is validating that, during collection, triggered by time interval, the observable's callback(s) are invoked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The aim is to test that creating the SdkMeterProvider instance triggers the start of the worker that will periodically collect (and export) metrics. This is the line being tested:

        let meter_provider = SdkMeterProvider::builder().with_reader(reader).build();

Perhaps a better name would be registration_triggers_worker?

Using the observable callback is a roundabout way to confirm that the worker thread is running. Maybe better to use meter_provider.force_flush() and exporter.get_finished_metrics() instead, as in other tests? I also want to avoid test flakiness here.

Copy link
Member

Choose a reason for hiding this comment

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

calling force_flush() would anyway flush the metric, even without the worker starting?... I need check in detail, but this testing logic sounds good to me.

Copy link
Member

Choose a reason for hiding this comment

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

builder_triggers_periodicreader_worker - as alternative suggestion. Or you can just add a code comment with your comment, as that was good explanation.

Copy link
Member

@lalitb lalitb Feb 14, 2024

Choose a reason for hiding this comment

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

Using the observable callback is a roundabout way to confirm that the worker thread is running.

I believe this test looks good to validate the periodic exporter metric collection cycle through the mpsc channel. We don't need to validate the measurements and their aggregation, as there are other tests for the same.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Thanks. Left a suggestion about rename and/or leaving a code comment to make it clear what are we testing with this particular test, given it may not be very obvious.

@hdost hdost merged commit 87153d3 into open-telemetry:main Feb 14, 2024
14 checks passed
@izquierdo izquierdo deleted the issue-1244-tests branch February 14, 2024 20:32
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.

4 participants