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

test: Fix for a few data races #12129

Merged
merged 1 commit into from
Mar 5, 2024
Merged

test: Fix for a few data races #12129

merged 1 commit into from
Mar 5, 2024

Conversation

paul1r
Copy link
Collaborator

@paul1r paul1r commented Mar 5, 2024

What this PR does / why we need it:
Two different races addressed in this PR.


go test . -race -count=50 -run Test_ExitEarly -v   
=== RUN   Test_ExitEarly
--- PASS: Test_ExitEarly (0.00s)
=== RUN   Test_ExitEarly
==================
WARNING: DATA RACE
Write at 0x00c00064e508 by goroutine 115:
  github.com/grafana/loki/pkg/querier/queryrange.Test_ExitEarly.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval_test.go:1779 +0xb4
  github.com/grafana/loki/pkg/querier/queryrange/queryrangebase.HandlerFunc.Do()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/queryrangebase/roundtrip.go:80 +0x50
  github.com/grafana/loki/pkg/querier/queryrange.(*seriesLimiter).Do()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/limits.go:415 +0x7c
  github.com/grafana/loki/pkg/querier/queryrange.(*splitByInterval).loop()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval.go:162 +0x114
  github.com/grafana/loki/pkg/querier/queryrange.(*splitByInterval).Process.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval.go:126 +0x70

Previous read at 0x00c00064e508 by goroutine 113:
  github.com/grafana/loki/pkg/querier/queryrange.Test_ExitEarly()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval_test.go:1855 +0x940
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1595 +0x1b0
  testing.(*T).Run.func1()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1648 +0x40

Goroutine 115 (running) created at:
  github.com/grafana/loki/pkg/querier/queryrange.(*splitByInterval).Process()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval.go:126 +0x140
  github.com/grafana/loki/pkg/querier/queryrange.(*splitByInterval).Do()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval.go:244 +0xb20
  github.com/grafana/loki/pkg/querier/queryrange.Test_ExitEarly()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/queryrange/split_by_interval_test.go:1853 +0x910
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1595 +0x1b0
  testing.(*T).Run.func1()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1648 +0x40

Goroutine 113 (finished) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1648 +0x5e8
  testing.runTests.func1()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:2054 +0x80
  testing.tRunner()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1595 +0x1b0
  testing.runTests()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:2052 +0x6e4
  testing.(*M).Run()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1925 +0x9ec
  main.main()
      _testmain.go:273 +0x294
==================

after fix:

go test . -race -count=50 -run Test_ExitEarly
PASS
ok  	github.com/grafana/loki/pkg/querier/queryrange	1.778s

and

go test -count=10 -race . -run earlyExitOnQuorum
==================
WARNING: DATA RACE
Read at 0x00c00073a248 by goroutine 120:
  github.com/grafana/loki/pkg/querier.TestIngesterQuerier_earlyExitOnQuorum.func5.1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier_test.go:91 +0x128
  github.com/stretchr/testify/mock.(*Mock).MethodCalled()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/mock/mock.go:552 +0xd3c
  github.com/stretchr/testify/mock.(*Mock).Called()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/mock/mock.go:464 +0x140
  github.com/grafana/loki/pkg/querier.(*querierClientMock).Label()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/querier_mock_test.go:69 +0x164
  github.com/grafana/loki/pkg/querier.(*IngesterQuerier).Label.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier.go:145 +0x60
  github.com/grafana/loki/pkg/querier.(*IngesterQuerier).forGivenIngesters.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier.go:91 +0x108
  github.com/grafana/dskit/ring.DoUntilQuorum[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func1()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:218 +0x4c
  github.com/grafana/dskit/ring.DoUntilQuorumWithoutSuccessfulContextCancellation[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func2()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:297 +0xdc
  github.com/grafana/dskit/ring.DoUntilQuorumWithoutSuccessfulContextCancellation[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func5()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:303 +0x44

Previous write at 0x00c00073a248 by goroutine 119:
  github.com/grafana/loki/pkg/querier.TestIngesterQuerier_earlyExitOnQuorum.func5.1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier_test.go:91 +0x138
  github.com/stretchr/testify/mock.(*Mock).MethodCalled()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/mock/mock.go:552 +0xd3c
  github.com/stretchr/testify/mock.(*Mock).Called()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/mock/mock.go:464 +0x140
  github.com/grafana/loki/pkg/querier.(*querierClientMock).Label()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/querier_mock_test.go:69 +0x164
  github.com/grafana/loki/pkg/querier.(*IngesterQuerier).Label.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier.go:145 +0x60
  github.com/grafana/loki/pkg/querier.(*IngesterQuerier).forGivenIngesters.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/querier/ingester_querier.go:91 +0x108
  github.com/grafana/dskit/ring.DoUntilQuorum[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func1()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:218 +0x4c
  github.com/grafana/dskit/ring.DoUntilQuorumWithoutSuccessfulContextCancellation[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func2()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:297 +0xdc
  github.com/grafana/dskit/ring.DoUntilQuorumWithoutSuccessfulContextCancellation[go.shape.struct { github.com/grafana/loki/pkg/querier.addr string; github.com/grafana/loki/pkg/querier.response interface {} }].func5()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/grafana/dskit/ring/replication_set.go:303 +0x44

after fix:

go test -count=50 -race . -run earlyExitOnQuorum
ok  	github.com/grafana/loki/pkg/querier	1.905s

Which issue(s) this PR fixes:
Relates to: #8586

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@paul1r paul1r requested a review from a team as a code owner March 5, 2024 18:25
@paul1r paul1r changed the title Fix for a few data races test: Fix for a few data races Mar 5, 2024
@paul1r paul1r merged commit 0ddf6fc into main Mar 5, 2024
13 checks passed
@paul1r paul1r deleted the paul1r/exit_data_races branch March 5, 2024 22:07
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants