Fix flaky TestConsumeMetricsWithOTelRemapper - #312
Merged
Conversation
lahsivjar
commented
Jul 4, 2024
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) |
Contributor
Author
There was a problem hiding this comment.
[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
enabled auto-merge (squash)
July 4, 2024 16:10
kruskall
approved these changes
Jul 4, 2024
This was referenced Jul 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The flakiness in the test
TestConsumeMetricsWithOTelRemapperwas 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 usesprotocmp.SortRepeatedfor 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
eventsMatchfunction by first sorting the samples in eachAPMEventand then sorting theAPMEvent's themselves and this is what the PR does. In addition the PR also refactors the testTestConsumeMetricsWithOTelRemapperwhich would avoid the special issue anyway.