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

Add global labels value regression tests #191

Merged
merged 12 commits into from
Aug 20, 2024
Merged

Add global labels value regression tests #191

merged 12 commits into from
Aug 20, 2024

Conversation

endorama
Copy link
Member

Provide tests to ensure no regression will happen in handling global labels Values field.

Closes #189

A basic test to verify the converted bug in handling tags.
Refactor to allow running the same test logic with different inputs and
expected results.
Add an e2e test for global labels values with multiple events.

A batch of 2 events in input with different labels Values but
same key should produce in output events with all different
Values added to the same key.
Fix unrelated typos found while exploring the code.
@endorama
Copy link
Member Author

endorama commented Aug 14, 2024

This PR adds 2 tests to catch a bug in Global Labels values marshalling/unmarshalling:

  1. a test in converter_tests.go where a bug was found just by marshalling and unmarshalling 2 global labels would result in data override
  2. an e2e test in aggregators_test.go with the goal to ensure processing of Global Labels values is consistent and expected.

I expect test 1 to not fail in this branch, as the bug should have been fixed.

What is puzzling me and I don't yet have an answer for is test 2 because:

  • it fails
  • it does not fail consistently: from my test runs sometimes asd,qwe are reported missing, sometimes rty,fgh, sometimes none
  • metricset names seems to differ in ordering between expected and computed results, but we order them in the diff comparator

I investigated a bit where this bug may be but haven't found it yet.

aggregators/aggregator_test.go Outdated Show resolved Hide resolved
aggregators/aggregator_test.go Outdated Show resolved Hide resolved
We only retain the latest tags in a batch of events.
TestAggregateAndHarvest sort logic only used Metricset.Name.
The latest test added to it s flappy with such a logic, as we are
evaluating the same Metricset.Names in 2 different events with
global labels with equal key and different values.

Enhance the sorting logic to account for equal Metricset.Name and
leverage labels (keys, Value and Values) in the lessFn.
When 2 events in a batch have the same service name but
different tags we output 2 different sets of metrics,
one for each tag set. This was not considered in the
previous expected values.
@endorama endorama marked this pull request as ready for review August 14, 2024 16:37
@endorama endorama requested a review from a team as a code owner August 14, 2024 16:37
Comment on lines 1132 to 1139
if akeys[i] != bkeys[i] {
return akeys[i] < bkeys[i]
}

akey := akeys[i]
if a.Labels[akey].Value != "" && a.Labels[akey].Value != b.Labels[akey].Value {
return a.Labels[akey].Value < b.Labels[akey].Value
}
Copy link
Member Author

Choose a reason for hiding this comment

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

For reviewers: these tests are not directly used with the current tests. I added them anyway to make this sorting function more robust and prevent unexpected failures in the future if we update the test cases.

This reverts commit 49d0906.

The same test is covered by TestMarshalEventGlobalLabelsRace,
which also test for a possible race condition.
return a.Metricset.Name < b.Metricset.Name
}

// otherwise sort by sorted labels
Copy link
Member

Choose a reason for hiding this comment

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

nit: not sure if it ever can manifest, but probably worth checking that both a and b Labels slices have the same size, otherwise this sorting can panic if slices are not equal.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a guard clause to prevent this, what do you think? 3b3a56b (#191)

1pkg
1pkg previously approved these changes Aug 14, 2024
There was a typo, this loop should have iterated over b.Labels
but was iterating over a.Labels
The previous implementation could panic if len(b) > len(a). Add
a guard clause that limit iterating over label based on len(b).

If len(a.Labels) > len(b.Labels), everything else equal we
conclude that a > b.
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

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

thanks for the test. One comment about the big sort func.

aggregators/aggregator_test.go Show resolved Hide resolved
Leverage a string comparison as a sort function, as
used in https://github.com/elastic/apm-data/blob/81d77648a3b17d4e52859110e233e40683fcdfe3/input/otlp/metrics_test.go#L1146-L1148

Adds an additional tag to the test case to ensure
expected results.
@endorama endorama merged commit d11999d into main Aug 20, 2024
5 checks passed
@endorama endorama deleted the global-labels-test branch August 20, 2024 16:57
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.

Add tests for multi-valued global labels
3 participants