Skip to content

Fix tracing.NewRandomRatioBased panic #5044

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

Merged
merged 5 commits into from
Dec 15, 2022

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented Dec 15, 2022

What this PR does:
Fix the NewRandomRatioBased panic.

This sampler were using a random - which is not thread safe:

// NewSource returns a new pseudo-random Source seeded with the given value.
// Unlike the default Source used by top-level functions, this source is not
// safe for concurrent use by multiple goroutines.
func NewSource(seed int64) Source {
	var rng rngSource
	rng.Seed(seed)
	return &rng
}
goroutine 514103346 [running]:
math/rand.(*rngSource).Uint64(...)
	/opt/brazil-pkg-cache/packages/GoLang/GoLang-1.x.108333.0/AL2_x86_64/DEV.STD.PTHREAD/build/lib/src/math/rand/rng.go:249
math/rand.(*rngSource).Int63(0x0?)
	/opt/brazil-pkg-cache/packages/GoLang/GoLang-1.x.108333.0/AL2_x86_64/DEV.STD.PTHREAD/build/lib/src/math/rand/rng.go:234 +0x92
math/rand.(*Rand).Int63(...)
	/opt/brazil-pkg-cache/packages/GoLang/GoLang-1.x.108333.0/AL2_x86_64/DEV.STD.PTHREAD/build/lib/src/math/rand/rand.go:84
math/rand.(*Rand).Float64(0xc000893b30)
	/opt/brazil-pkg-cache/packages/GoLang/GoLang-1.x.108333.0/AL2_x86_64/DEV.STD.PTHREAD/build/lib/src/math/rand/rand.go:195 +0x30
golang.a2z.com/AWSPrometheusCortex/vendor/github.com/cortexproject/cortex/pkg/tracing/sampler.(*RandomRatioBased).ShouldSample(0xc000893b60, {{0x28a1ef0, 0xc34f531710}, {0x63, 0x9b, 0x55, 0x68, 0x6d, 0xcb, 0x45, ...}, ...})

This PR change the sample decision to be based on the random part of the trace Id.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 15, 2022
Signed-off-by: Alan Protasio <[email protected]>
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

LGTM

@yeya24 yeya24 enabled auto-merge (squash) December 15, 2022 23:06
@alanprot
Copy link
Member Author

I created a PR on the otel contrib: open-telemetry/opentelemetry-go-contrib#3090

Lets see if get merged.

@yeya24 yeya24 merged commit 9d53ea0 into cortexproject:master Dec 15, 2022
@alanprot alanprot deleted the fix-xray-sampler branch December 15, 2022 23:16
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <[email protected]>

* changelog

Signed-off-by: Alan Protasio <[email protected]>

* make lint happy

Signed-off-by: Alan Protasio <[email protected]>

* adding back xray propagator

Signed-off-by: Alan Protasio <[email protected]>

* rename the sampler

Signed-off-by: Alan Protasio <[email protected]>

Signed-off-by: Alan Protasio <[email protected]>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <[email protected]>

* changelog

Signed-off-by: Alan Protasio <[email protected]>

* make lint happy

Signed-off-by: Alan Protasio <[email protected]>

* adding back xray propagator

Signed-off-by: Alan Protasio <[email protected]>

* rename the sampler

Signed-off-by: Alan Protasio <[email protected]>

Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <[email protected]>

* changelog

Signed-off-by: Alan Protasio <[email protected]>

* make lint happy

Signed-off-by: Alan Protasio <[email protected]>

* adding back xray propagator

Signed-off-by: Alan Protasio <[email protected]>

* rename the sampler

Signed-off-by: Alan Protasio <[email protected]>

Signed-off-by: Alan Protasio <[email protected]>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <[email protected]>

* changelog

Signed-off-by: Alan Protasio <[email protected]>

* make lint happy

Signed-off-by: Alan Protasio <[email protected]>

* adding back xray propagator

Signed-off-by: Alan Protasio <[email protected]>

* rename the sampler

Signed-off-by: Alan Protasio <[email protected]>

Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alan Protasio <[email protected]>
alexqyle pushed a commit to alexqyle/cortex that referenced this pull request May 2, 2023
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <[email protected]>

* changelog

Signed-off-by: Alan Protasio <[email protected]>

* make lint happy

Signed-off-by: Alan Protasio <[email protected]>

* adding back xray propagator

Signed-off-by: Alan Protasio <[email protected]>

* rename the sampler

Signed-off-by: Alan Protasio <[email protected]>

Signed-off-by: Alan Protasio <[email protected]>
Signed-off-by: Alex Le <[email protected]>
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