-
Notifications
You must be signed in to change notification settings - Fork 692
chore: enable exposedSyncMutex rule from go-critic #7726
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
base: main
Are you sure you want to change the base?
Changes from all commits
8530472
6fedb8f
c3c5d58
9f63fc3
2238e3b
1b19815
46aa08a
c91a6e2
f6c8f02
0a4fb75
e0fe00d
bc456c2
a794cea
84c9b64
d0061c7
2cf8caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,17 +18,38 @@ | |||||||
) | ||||||||
|
||||||||
// IDGenerator is used for generating a new traceID and spanID. | ||||||||
type IDGenerator struct { | ||||||||
sync.Mutex | ||||||||
sync.Mutex // Deprecated: mutex is internal and shall not be used. | ||||||||
mu sync.Mutex | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field needs to be kept as removing an exported field is a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't the lign added between L28 and L47 here to handle deprecation ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
mmorel-35 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for duplicating the fields?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wanted to fix exposedSyncMutex... this is a nightmare 😭. Please take it from here. I don’t want to here about this egg or chicken problem! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot you add a |
||||||||
randSource *rand.Rand | ||||||||
} | ||||||||
|
||||||||
var _ sdktrace.IDGenerator = &IDGenerator{} | ||||||||
|
||||||||
// Lock is used to lock the IDGenerator for concurrent use. | ||||||||
// noop method to satisfy the sync.Mutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
func (*IDGenerator) Lock() {} | ||||||||
|
||||||||
// TryLock attempts to lock the IDGenerator for concurrent use. | ||||||||
// noop method to satisfy the sync.Mutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
func (*IDGenerator) TryLock() bool { | ||||||||
return false | ||||||||
} | ||||||||
|
||||||||
// Unlock is used to unlock the IDGenerator for concurrent use. | ||||||||
// noop method to satisfy the sync.Mutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
func (*IDGenerator) Unlock() {} | ||||||||
|
||||||||
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence. | ||||||||
func (gen *IDGenerator) NewSpanID(context.Context, trace.TraceID) trace.SpanID { | ||||||||
gen.Lock() | ||||||||
defer gen.Unlock() | ||||||||
gen.mu.Lock() | ||||||||
defer gen.mu.Unlock() | ||||||||
sid := trace.SpanID{} | ||||||||
_, _ = gen.randSource.Read(sid[:]) | ||||||||
return sid | ||||||||
|
@@ -40,8 +61,8 @@ | |||||||
// | ||||||||
// span ID is from a randomly-chosen sequence. | ||||||||
func (gen *IDGenerator) NewIDs(context.Context) (trace.TraceID, trace.SpanID) { | ||||||||
gen.Lock() | ||||||||
defer gen.Unlock() | ||||||||
gen.mu.Lock() | ||||||||
defer gen.mu.Unlock() | ||||||||
|
||||||||
tid := trace.TraceID{} | ||||||||
currentTime := getCurrentTimeHex() | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -71,8 +71,9 @@ type Sampler struct { | |||||||
// These fields must be first in the struct because `sync/atomic` expects 64-bit alignment. | ||||||||
// Cf. https://github.com/jaegertracing/jaeger-client-go/issues/155, https://pkg.go.dev/sync/atomic#pkg-note-BUG | ||||||||
closed int64 // 0 - not closed, 1 - closed | ||||||||
|
||||||||
sync.RWMutex // used to serialize access to samplerConfig.sampler | ||||||||
//nolint:gocritic // ongoing deletion | ||||||||
sync.RWMutex // Deprecated: mutex is internal and shall not be used. | ||||||||
mu sync.RWMutex // used to serialize access to samplerConfig.sampler | ||||||||
dmathieu marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field needs to be kept as removing an exported field is a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't the lign added between L98 and L117 here to handle deprecation ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only handles deprecation of the "embedded methods". package main
import "go.opentelemetry.io/contrib/samplers/jaegerremote"
func main() {
s := new(jaegerremote.Sampler)
s.RWMutex.Lock()
} Thus this is a breaking change from Go perspective.
Comment on lines
+75
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
config | ||||||||
|
||||||||
serviceName string | ||||||||
|
@@ -95,11 +96,31 @@ func New( | |||||||
return sampler | ||||||||
} | ||||||||
|
||||||||
// Lock is used to lock the Sampler for concurrent use. | ||||||||
// noop method to satisfy the sync.RWMutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
dmathieu marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
func (*Sampler) Lock() {} | ||||||||
|
||||||||
// TryLock attempts to lock the Sampler for concurrent use. | ||||||||
// noop method to satisfy the sync.RWMutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
func (*Sampler) TryLock() bool { | ||||||||
return false | ||||||||
} | ||||||||
|
||||||||
// Unlock is used to unlock the Sampler for concurrent use. | ||||||||
// noop method to satisfy the sync.RWMutex interface. | ||||||||
// | ||||||||
// Deprecated: mutex is internal and shall not be used. | ||||||||
func (*Sampler) Unlock() {} | ||||||||
|
||||||||
// ShouldSample returns a sampling choice based on the passed sampling | ||||||||
// parameters. | ||||||||
func (s *Sampler) ShouldSample(p trace.SamplingParameters) trace.SamplingResult { | ||||||||
s.RLock() | ||||||||
defer s.RUnlock() | ||||||||
s.mu.RLock() | ||||||||
defer s.mu.RUnlock() | ||||||||
return s.sampler.ShouldSample(p) | ||||||||
} | ||||||||
|
||||||||
|
@@ -143,8 +164,8 @@ func (s *Sampler) pollControllerWithTicker(ticker *time.Ticker) { | |||||||
} | ||||||||
|
||||||||
func (s *Sampler) setSampler(sampler trace.Sampler) { | ||||||||
s.Lock() | ||||||||
defer s.Unlock() | ||||||||
s.mu.Lock() | ||||||||
defer s.mu.Unlock() | ||||||||
s.sampler = sampler | ||||||||
} | ||||||||
|
||||||||
|
@@ -162,8 +183,8 @@ func (s *Sampler) UpdateSampler() { | |||||||
return | ||||||||
} | ||||||||
|
||||||||
s.Lock() | ||||||||
defer s.Unlock() | ||||||||
s.mu.Lock() | ||||||||
defer s.mu.Unlock() | ||||||||
|
||||||||
if err := s.updateSamplerViaUpdaters(strategy); err != nil { | ||||||||
s.logger.Error(err, "failed to handle sampling strategy response", "response", res) | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.