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

[target allocator] Fix flaky server test in targets handler #1457

Merged

Conversation

matej-g
Copy link
Contributor

@matej-g matej-g commented Feb 7, 2023

Signed-off-by: Matej Gera matej.gera@coralogix.com

We were occasionally seeing a failure in TestServer_TargetsHandler/Multiple_entry_target_map_of_same_job_with_label_merge with the following output:

    server_test.go:177: 
        	Error Trace:	/home/runner/work/opentelemetry-operator/opentelemetry-operator/cmd/otel-allocator/server/server_test.go:177
        	Error:      	Not equal: 
        	            	expected: []*target.Item{(*target.Item)(0xc000717d40), (*target.Item)(0xc000717da0)}
        	            	actual  : []*target.Item{(*target.Item)(0xc00017a840), (*target.Item)(0xc00017a8a0)}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,16 @@
        	            	 ([]*target.Item) (len=2) {
        	            	+ (*target.Item)({
        	            	+  JobName: (string) "",
        	            	+  Link: (target.LinkJSON) {
        	            	+   Link: (string) ""
        	            	+  },
        	            	+  TargetURL: ([]string) (len=1) {
        	            	+   (string) (len=9) "test-url2"
        	            	+  },
        	            	+  Labels: (model.LabelSet) (len=1) {
        	            	+   (model.LabelName) (len=10) "test_label": (model.LabelValue) (len=11) "test-value2"
        	            	+  },
        	            	+  CollectorName: (string) "",
        	            	+  hash: (string) ""
        	            	+ }),
        	            	  (*target.Item)({
        	            	@@ -14,16 +28,2 @@
        	            	   hash: (string) ""
        	            	- }),
        	            	- (*target.Item)({
        	            	-  JobName: (string) "",
        	            	-  Link: (target.LinkJSON) {
        	            	-   Link: (string) ""
        	            	-  },
        	            	-  TargetURL: ([]string) (len=1) {
        	            	-   (string) (len=9) "test-url2"
        	            	-  },
        	            	-  Labels: (model.LabelSet) (len=1) {
        	            	-   (model.LabelName) (len=10) "test_label": (model.LabelValue) (len=11) "test-value2"
        	            	-  },
        	            	-  CollectorName: (string) "",
        	            	-  hash: (string) ""
        	            	  })

This is presumable due to nondeterministic order of items, which on some test runs seem to change. Using ElementsMatch method instead of Equal will ensure the order of items is not decisive for passing the test.

Tested locally with -count=100 flag to catch the error and subsequently to test the fix.

cc @jaronoff97

Signed-off-by: Matej Gera <matej.gera@coralogix.com>
@matej-g matej-g requested a review from a team February 7, 2023 21:43
@jaronoff97 jaronoff97 added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Feb 7, 2023
@jaronoff97 jaronoff97 merged commit 3a8b546 into open-telemetry:main Feb 7, 2023
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
Signed-off-by: Matej Gera <matej.gera@coralogix.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants