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: Add synchronization for fakeTailer responses #12186

Merged
merged 4 commits into from
Mar 13, 2024

Conversation

paul1r
Copy link
Contributor

@paul1r paul1r commented Mar 12, 2024

What this PR does / why we need it:
Data race found. Before the fix:


go test -race -count=10 . -run Test_StructuredMetadata 
==================
WARNING: DATA RACE
Read at 0x00c000c225d0 by goroutine 113:
  github.com/grafana/loki/pkg/ingester.(*fakeTailServer).GetResponses()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:164 +0x30
  github.com/grafana/loki/pkg/ingester.Test_StructuredMetadata.func1.2()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:326 +0x40
  github.com/stretchr/testify/assert.Eventually.func1()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/assert/assertions.go:1852 +0x38

Previous write at 0x00c000c225d0 by goroutine 110:
  github.com/grafana/loki/pkg/ingester.(*fakeTailServer).Send()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:156 +0x138
  github.com/grafana/loki/pkg/ingester.(*tailer).loop()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer.go:105 +0x214
  github.com/grafana/loki/pkg/ingester.Test_StructuredMetadata.func1.1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:318 +0x34

Goroutine 113 (running) created at:
  github.com/stretchr/testify/assert.Eventually()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/assert/assertions.go:1852 +0x2b8
  github.com/stretchr/testify/require.Eventually()
      /Users/progers/dev/src/github.com/grafana/loki/vendor/github.com/stretchr/testify/require/require.go:401 +0x90
  github.com/grafana/loki/pkg/ingester.Test_StructuredMetadata.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:325 +0x30c
  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 110 (running) created at:
  github.com/grafana/loki/pkg/ingester.Test_StructuredMetadata.func1()
      /Users/progers/dev/src/github.com/grafana/loki/pkg/ingester/tailer_test.go:317 +0x1e4
  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:


go test -race -count=10 . -run Test_StructuredMetadata
ok  	github.com/grafana/loki/pkg/ingester	21.665s

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 12, 2024 20:38
Copy link
Collaborator

@trevorwhitney trevorwhitney left a comment

Choose a reason for hiding this comment

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

lgtm

f.responses = append(f.responses, *response)
return nil

}

func (f *fakeTailServer) Context() context.Context { return context.Background() }

func (f *fakeTailServer) cloneTailResponse(response logproto.TailResponse) logproto.TailResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I don't think we need the *fakeTailerServer reciever here

@paul1r paul1r enabled auto-merge (squash) March 13, 2024 00:58
@paul1r paul1r merged commit bd3f83a into main Mar 13, 2024
11 checks passed
@paul1r paul1r deleted the paul1r/tailer_test_data_race branch March 13, 2024 00:58
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.

None yet

2 participants