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

chore: Add metric integration tests #2424

Closed

Conversation

scottgerring
Copy link
Contributor

@scottgerring scottgerring commented Dec 13, 2024

Contributes to #2401

Changes

Please provide a brief description of the changes here.

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 Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.3%. Comparing base (ce550e3) to head (d8dd69a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2424   +/-   ##
=====================================
  Coverage   79.3%   79.3%           
=====================================
  Files        122     122           
  Lines      21569   21565    -4     
=====================================
  Hits       17114   17114           
+ Misses      4455    4451    -4     

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

meter_provider
}

pub async fn metrics() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
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 actual meters we're pushing through for the test

@@ -0,0 +1,133 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as metrics.json but with minor changes to validate that our comparison is working.

@@ -6,114 +6,128 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was already here, but was seemingly unused, so i've repurposed it to match the style of the other tests

@scottgerring
Copy link
Contributor Author

@cijothomas i've fleshed out the basic pattern to add metrics integration coverage here; it still needs to cover the rest of the meters, and I need to deal with the windows build issues.

I don't need a proper review yet, but if you have a second to glance over it let me know if anything seems fundamentally different to what you expect.

@@ -7,7 +7,7 @@ publish = false

[dependencies]
opentelemetry = { path = "../../../opentelemetry", features = ["metrics", "logs"] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "logs", "testing"] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "logs", "testing", "metrics"] }
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can remove logs,metrics features as they are anyway by default added.

let mut result_scope_metrics = &mut result_resource_metrics.scope_metrics;
let mut expected_scope_metrics = &mut expected_resource_metrics.scope_metrics;

// Zero out all the timestamps so we can usual the default comparisons
Copy link
Member

Choose a reason for hiding this comment

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

this is good! Thanks.

let meter_provider = init_metrics();

let meter = meter_provider.meter("meter");
let counter = meter.u64_counter("counter_u64").build();
Copy link
Member

Choose a reason for hiding this comment

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

please add one observable instrument like observable counter .

// wait for file to flush to disks
// ideally we should use volume mount but otel collector file exporter doesn't handle permission too well
// bind mount mitigate the issue by set up the permission correctly on host system
tokio::time::sleep(Duration::from_secs(5)).await;
Copy link
Member

Choose a reason for hiding this comment

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

while this test is important, we also need to add one where we rely on shutdown to push the metrics, instead of using a ultra-low interval for pushing metrics.

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.

Looks good overall, no concerns with the approach.
After an initial working version, we can add more combinations.

@cijothomas cijothomas added the integration tests Run integration tests label Dec 13, 2024
@@ -54,6 +54,7 @@ impl TestSuite {
async fn integration_tests() {
trace_integration_tests().await;
logs_integration_tests().await;
metrics_integration_tests().await;
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion for future follow-up PR: While this works fine for now, using a shared collector setup across signals could improve efficiency and maintainability. Currently, the collector is started and stopped separately for each signal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That’s a good point - I’ll change it while I’m here, I don’t think it should be a problem as they are collecting separate signals anyhow.

@lalitb
Copy link
Member

lalitb commented Dec 13, 2024

Looks good overall, no concerns with the approach. After an initial working version, we can add more combinations.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration tests Run integration tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants