-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Critical Logging for Low Disk Space Condition #9617
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: master
Are you sure you want to change the base?
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
package healthcheck | ||||||
|
||||||
import ( | ||||||
"errors" | ||||||
"fmt" | ||||||
"os" | ||||||
"syscall" | ||||||
) | ||||||
|
||||||
// CheckFileDescriptors checks if there are any free file descriptors available. | ||||||
// It returns an error if no free file descriptors are available or if an unexpected error occurs. | ||||||
func CheckFileDescriptors() error { | ||||||
// Attempt to open /dev/null to test for available file descriptors | ||||||
fd, err := os.OpenFile(os.DevNull, os.O_RDONLY, 0) | ||||||
if err != nil { | ||||||
// Check if the error is due to "too many open files" | ||||||
if errors.Is(err, syscall.EMFILE) { | ||||||
return fmt.Errorf("no free file descriptors available") | ||||||
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. Consider enhancing this error message to provide more context about the implications:
Suggested change
|
||||||
} | ||||||
|
||||||
return fmt.Errorf("error checking file descriptors: %w", err) | ||||||
} | ||||||
|
||||||
fd.Close() | ||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ type HealthCheckConfig struct { | |
|
||
DiskCheck *DiskCheckConfig `group:"diskspace" namespace:"diskspace"` | ||
|
||
FileDescriptorCheck *DiskCheckConfig `group:"file_descriptor" namespace:"file_descriptor"` | ||
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 new configuration option needs to be documented in the CLI help text and sample configurations. Ensure users understand:
|
||
|
||
TLSCheck *CheckConfig `group:"tls" namespace:"tls"` | ||
|
||
TorConnection *CheckConfig `group:"torconnection" namespace:"torconnection"` | ||
|
@@ -48,6 +50,10 @@ func (h *HealthCheckConfig) Validate() error { | |
return err | ||
} | ||
|
||
if err := h.FileDescriptorCheck.validate("file descriptor"); err != nil { | ||
return err | ||
} | ||
|
||
if err := h.TLSCheck.validate("tls"); err != nil { | ||
return err | ||
} | ||
|
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.
commenting for lines ~ 12-26 .....
This check only triggers when file descriptors are completely exhausted, which might be too late for preventive action. Consider modifying this to accept a threshold parameter (similar to how DiskCheck uses RequiredRemaining) that would warn when file descriptors are running low but not yet exhausted .