-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[testbed] Detect and fix data race at testbed integration test #30549
Merged
Conversation
This file contains 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
Signed-off-by: James Ryans <[email protected]>
Signed-off-by: James Ryans <[email protected]>
Signed-off-by: James Ryans <[email protected]>
Signed-off-by: James Ryans <[email protected]>
Signed-off-by: James Ryans <[email protected]>
james-ryans
requested review from
MovieStoreGuy and
andrzej-stencel
as code owners
January 14, 2024 07:22
github-actions
bot
added
receiver/opencensus
receiver/zipkin
Zipkin receiver
testbed
labels
Jan 14, 2024
4 tasks
djaglowski
approved these changes
Jan 16, 2024
cparkins
pushed a commit
to AmadeusITGroup/opentelemetry-collector-contrib
that referenced
this pull request
Feb 1, 2024
…telemetry#30549) **Description:** Fixing a bug - The Testbed module has many data race warnings when tested with `go test -race`, especially for traces. I've listed the data race issues and fixes below: 1. Add mutex to MockBackend `startedAt` variable Because `tc := testbed.NewTestCase()` starts a `logStats()` goroutine which calls `MockBackend.GetStats()` that uses the `startedAt` variable, a data race occurs when we later execute `tc.StartBackend()`. This is because `tc.StartBackend()` writes to the `startedAt` variable. 2. Add mutex to LoadGenerator `startedAt` variable The reason is similar to MockBackend. 3. Move MockBackend `numSpansReceived` addition after `ConsumeTraces()` Because `tc.numSpansReceived.Add(uint64(td.SpanCount()))` will make `tc.LoadGenerator.DataItemsSent()` equals to `tc.MockBackend.DataItemsReceived()` which the test case will assume MockBackend already received all the spans and lead to `tc.ValidateData()` while MockBackend is actually consuming the traces. 4. Get `td.SpanCount()` before `batchprocessor` consumes the spans at `opencensusreceiver` and `zipkinreceiver` With the `batchprocessor` pipeline, there's a step that it moves the source `td.ResourceSpans()` to the batched one and that is why the `td.SpanCount()` line while `batchprocessor` consuming the traces will cause data race. **Testing:** Add `-race` args to `testbed/runtests.sh` at line 22 where `go test` takes place. Run `TESTS_DIR=correctnesstests/traces make e2e-test` --------- Signed-off-by: James Ryans <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
receiver/opencensus
receiver/zipkin
Zipkin receiver
Skip Changelog
PRs that do not require a CHANGELOG.md entry
testbed
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.
Description:
Fixing a bug - The Testbed module has many data race warnings when tested with
go test -race
, especially for traces. I've listed the data race issues and fixes below:startedAt
variableBecause
tc := testbed.NewTestCase()
starts alogStats()
goroutine which callsMockBackend.GetStats()
that uses thestartedAt
variable, a data race occurs when we later executetc.StartBackend()
. This is becausetc.StartBackend()
writes to thestartedAt
variable.startedAt
variableThe reason is similar to MockBackend.
numSpansReceived
addition afterConsumeTraces()
Because
tc.numSpansReceived.Add(uint64(td.SpanCount()))
will maketc.LoadGenerator.DataItemsSent()
equals totc.MockBackend.DataItemsReceived()
which the test case will assume MockBackend already received all the spans and lead totc.ValidateData()
while MockBackend is actually consuming the traces.td.SpanCount()
beforebatchprocessor
consumes the spans atopencensusreceiver
andzipkinreceiver
With the
batchprocessor
pipeline, there's a step that it moves the sourcetd.ResourceSpans()
to the batched one and that is why thetd.SpanCount()
line whilebatchprocessor
consuming the traces will cause data race.Testing:
Add
-race
args totestbed/runtests.sh
at line 22 wherego test
takes place.Run
TESTS_DIR=correctnesstests/traces make e2e-test