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

Fix flaky TestConsumeMetricsWithOTelRemapper #312

Merged
merged 2 commits into from
Jul 4, 2024

Conversation

lahsivjar
Copy link
Contributor

The flakiness in the test TestConsumeMetricsWithOTelRemapper was introduced in #309 when we added another scope in the metric.

The root cause of the flakiness is the function eventsMatch. This function sorts the APMEvents by converting it into strings and later compares them at which point it uses protocmp.SortRepeated for metricset samples. The metricsets are created using maps (ref) which makes the order of metricsets undefined. While the tests use sorting on the metricset samples to get around this we still end up in an indeterministic state since the first sort doesn't sort on metricset samples (ref).

We can fix the eventsMatch function by first sorting the samples in each APMEvent and then sorting the APMEvent's themselves and this is what the PR does. In addition the PR also refactors the test TestConsumeMetricsWithOTelRemapper which would avoid the special issue anyway.

@lahsivjar lahsivjar requested a review from a team as a code owner July 4, 2024 16:02
@obltmachine obltmachine added the safe-to-test Changes are safe to run in the CI label Jul 4, 2024
@lahsivjar lahsivjar requested a review from carsonip July 4, 2024 16:02
Comment on lines -865 to -883
// Configure scope for hostmetrics receiver
sm.Scope().SetName("otelcol/hostmetricsreceiver/load")

// Add a datapoint for a metric produced by hostmetrics receiver
metric := sm.Metrics().AppendEmpty()
metric.SetName("system.cpu.load_average.1m")
dp := metric.SetEmptyGauge().DataPoints().AppendEmpty()
dp.SetTimestamp(pcommon.NewTimestampFromTime(ts))
dp.SetDoubleValue(0.7)

// process metric
sm = rm.ScopeMetrics().AppendEmpty()
sm.Scope().SetName("otelcol/hostmetricsreceiver/process")
metric = sm.Metrics().AppendEmpty()
metric.SetName("process.memory.usage")
dp = metric.SetEmptySum().DataPoints().AppendEmpty()
dp.SetTimestamp(pcommon.NewTimestampFromTime(ts))
dp.SetStartTimestamp(pcommon.NewTimestampFromTime(startTs))
dp.SetIntValue(1024)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[For reviewers] There should be no change in the tests. The tests just divides the load and the process scope into two separate tests.

@lahsivjar lahsivjar enabled auto-merge (squash) July 4, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe-to-test Changes are safe to run in the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants