Skip to content

Commit

Permalink
Merge pull request #369 from porters-xyz/develop
Browse files Browse the repository at this point in the history
Configurable File Descriptor Threshold
  • Loading branch information
scermat authored Oct 9, 2024
2 parents 4c0f965 + 62678a1 commit 48e1480
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gateway/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
FLY_GATEWAY_URI = "FLY_GATEWAY_URI"
GATEWAY_API_KEY = "GATEWAY_API_KEY"
GATEWAY_REQUEST_API_KEY = "GATEWAY_REQUEST_API_KEY"
FILE_DESCRIPTOR_LIMIT = "FILE_DESCRIPTOR_LIMIT"
)

// This may evolve to include config outside env, or use .env file for
Expand Down Expand Up @@ -59,6 +60,7 @@ func setupConfig() *Config {
config.defaults[LOG_HTTP_RESPONSE] = "false"
config.defaults[LOG_BALANCE_UPDATE] = "false"
config.defaults[LOG_HTTP_REQUEST_FILTER] = ""
config.defaults[FILE_DESCRIPTOR_LIMIT] = "5000"

level := parseLogLevel(os.Getenv(LOG_LEVEL))
config.SetLogLevel(level)
Expand Down
3 changes: 2 additions & 1 deletion gateway/proxy/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type HealthStatus struct {
// New function to check file descriptor health and log the results using slog
func checkFileDescriptorHealth() bool {
var rLimit unix.Rlimit
fdLimit := common.GetConfigInt("FILE_DESCRIPTOR_LIMIT")

// Get the max number of allowed file descriptors
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit)
Expand All @@ -35,7 +36,7 @@ func checkFileDescriptorHealth() bool {
}
fdUsage := uint64(len(files))

healthy := fdUsage < rLimit.Cur*80/100
healthy := fdUsage < uint64(fdLimit)

// Log the file descriptor information using slog
slog.Info("File Descriptor Usage",
Expand Down

0 comments on commit 48e1480

Please sign in to comment.