Skip to content

Commit 48e1480

Browse files
authored
Merge pull request #369 from porters-xyz/develop
Configurable File Descriptor Threshold
2 parents 4c0f965 + 62678a1 commit 48e1480

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

gateway/common/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
FLY_GATEWAY_URI = "FLY_GATEWAY_URI"
3232
GATEWAY_API_KEY = "GATEWAY_API_KEY"
3333
GATEWAY_REQUEST_API_KEY = "GATEWAY_REQUEST_API_KEY"
34+
FILE_DESCRIPTOR_LIMIT = "FILE_DESCRIPTOR_LIMIT"
3435
)
3536

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

6365
level := parseLogLevel(os.Getenv(LOG_LEVEL))
6466
config.SetLogLevel(level)

gateway/proxy/health.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type HealthStatus struct {
1919
// New function to check file descriptor health and log the results using slog
2020
func checkFileDescriptorHealth() bool {
2121
var rLimit unix.Rlimit
22+
fdLimit := common.GetConfigInt("FILE_DESCRIPTOR_LIMIT")
2223

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

38-
healthy := fdUsage < rLimit.Cur*80/100
39+
healthy := fdUsage < uint64(fdLimit)
3940

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

0 commit comments

Comments
 (0)