-
Notifications
You must be signed in to change notification settings - Fork 0
Add naming support to readiness probes for better logging #13
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ type ReadinessProbe struct { | |
| doneC chan struct{} // Completion signal channel | ||
| mu sync.RWMutex // Protects err field | ||
| err error // Error if failed, nil if successful | ||
| name string // Name for logging and debugging | ||
| } | ||
|
|
||
| // NewReadinessProbe creates a new readiness probe. | ||
|
|
@@ -46,3 +47,14 @@ func (rp *ReadinessProbe) Error() error { | |
| defer rp.mu.RUnlock() | ||
| return rp.err | ||
| } | ||
|
|
||
| // WithName sets the name of the readiness probe for logging and debugging. | ||
| func (rp *ReadinessProbe) WithName(name string) *ReadinessProbe { | ||
| rp.name = name | ||
| return rp | ||
| } | ||
|
|
||
| // GetName returns the name of the readiness probe. | ||
| func (rp *ReadinessProbe) GetName() string { | ||
| return rp.name | ||
| } | ||
|
Comment on lines
+58
to
+60
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name field is accessed without mutex protection, which could lead to race conditions. The ReadinessProbe struct already has a sync.RWMutex to protect the err field. The name field should be similarly protected since WithName could be called concurrently with GetName. Consider acquiring the appropriate lock (write lock for WithName, read lock for GetName) to ensure thread-safe access.