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

Fix tracing.NewRandomRatioBased panic #5044

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 <approtas@amazon.com>
Signed-off-by: Alan Protasio <approtas@amazon.com>
Signed-off-by: Alan Protasio <approtas@amazon.com>
pkg/tracing/sampler/sampling.go Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
Signed-off-by: Alan Protasio <approtas@amazon.com>
@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 15, 2022
Signed-off-by: Alan Protasio <approtas@amazon.com>
Copy link
Collaborator

@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 <approtas@amazon.com>

* changelog

Signed-off-by: Alan Protasio <approtas@amazon.com>

* make lint happy

Signed-off-by: Alan Protasio <approtas@amazon.com>

* adding back xray propagator

Signed-off-by: Alan Protasio <approtas@amazon.com>

* rename the sampler

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <approtas@amazon.com>

* changelog

Signed-off-by: Alan Protasio <approtas@amazon.com>

* make lint happy

Signed-off-by: Alan Protasio <approtas@amazon.com>

* adding back xray propagator

Signed-off-by: Alan Protasio <approtas@amazon.com>

* rename the sampler

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <approtas@amazon.com>

* changelog

Signed-off-by: Alan Protasio <approtas@amazon.com>

* make lint happy

Signed-off-by: Alan Protasio <approtas@amazon.com>

* adding back xray propagator

Signed-off-by: Alan Protasio <approtas@amazon.com>

* rename the sampler

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
alanprot added a commit that referenced this pull request Dec 18, 2022
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <approtas@amazon.com>

* changelog

Signed-off-by: Alan Protasio <approtas@amazon.com>

* make lint happy

Signed-off-by: Alan Protasio <approtas@amazon.com>

* adding back xray propagator

Signed-off-by: Alan Protasio <approtas@amazon.com>

* rename the sampler

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
alexqyle pushed a commit to alexqyle/cortex that referenced this pull request May 2, 2023
* fix NewRandomRatioBased panic

Signed-off-by: Alan Protasio <approtas@amazon.com>

* changelog

Signed-off-by: Alan Protasio <approtas@amazon.com>

* make lint happy

Signed-off-by: Alan Protasio <approtas@amazon.com>

* adding back xray propagator

Signed-off-by: Alan Protasio <approtas@amazon.com>

* rename the sampler

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
Signed-off-by: Alex Le <leqiyue@amazon.com>
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