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: Update chunk/cache/mock to have a GetKeys() function #12122

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

paul1r
Copy link
Collaborator

@paul1r paul1r commented Mar 4, 2024

The new GetKeys() function will prevent a data race found.

What this PR does / why we need it:

Before the fix:

==================
WARNING: DATA RACE
Read at 0x00c000315140 by goroutine 111:
  github.com/grafana/loki/pkg/storage/chunk/fetcher.makeChunksFromMap()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher_test.go:344 +0x34
  github.com/grafana/loki/pkg/storage/chunk/fetcher.Test.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher_test.go:207 +0xf7c
  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

Previous write at 0x00c000315140 by goroutine 132:
  runtime.mapaccess2_faststr()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/runtime/map_faststr.go:108 +0x42c
  github.com/grafana/loki/pkg/storage/chunk/cache.(*mockCache).Store()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/cache/mock.go:28 +0x1bc
  github.com/grafana/loki/pkg/storage/chunk/fetcher.(*Fetcher).WriteBackCache()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher.go:318 +0xac4
  github.com/grafana/loki/pkg/storage/chunk/fetcher.(*Fetcher).asyncWriteBackCacheQueueProcessLoop()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher.go:136 +0x118
  github.com/grafana/loki/pkg/storage/chunk/fetcher.New.func2()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher.go:115 +0x34

Goroutine 111 (running) created at:
  testing.(*T).Run()
      /opt/homebrew/Cellar/go/1.21.6/libexec/src/testing/testing.go:1648 +0x5e8
  github.com/grafana/loki/pkg/storage/chunk/fetcher.Test()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher_test.go:156 +0x2990
  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 132 (running) created at:
  github.com/grafana/loki/pkg/storage/chunk/fetcher.New()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher.go:115 +0x3bc
  github.com/grafana/loki/pkg/storage/chunk/fetcher.Test.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/storage/chunk/fetcher/fetcher_test.go:196 +0xde4
  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

After the fix:

fetcher % go test . -count=50 -race
ok  	github.com/grafana/loki/pkg/storage/chunk/fetcher	154.566s

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 4, 2024 20:05
@paul1r paul1r changed the title Test: Update chunk/cache/mock to have a GetKeys() function test: Update chunk/cache/mock to have a GetKeys() function Mar 4, 2024
Copy link
Contributor

@JordanRushing JordanRushing left a comment

Choose a reason for hiding this comment

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

LGTM

@paul1r paul1r enabled auto-merge (squash) March 4, 2024 20:14
@paul1r paul1r merged commit 97ae790 into main Mar 4, 2024
13 checks passed
@paul1r paul1r deleted the paul1r/fetcher_data_race branch March 4, 2024 20:14
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