Skip to content

Commit

Permalink
Merge pull request #16 from jeffsaremi/server-health-check
Browse files Browse the repository at this point in the history
First version of server health check
  • Loading branch information
rsparihar authored Feb 23, 2023
2 parents e534560 + dbd41e8 commit a1acb83
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 35 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Usage: bin/redisbetween [OPTIONS] uri1 [uri2] ...
statsd address (default "localhost:8125")
-unlink
unlink existing unix sockets before listening
-healthcheck
start a background process to check the health of server connections
-healthcheckcycle
number of seconds after which the healthcheck process should repeat itself (default 60s)
-healthcheckthreshold
count of consecutive healthcheck failures after which a server is declared unhealthy (default 3)
```

Each URI can specify the following settings as GET params:
Expand Down
47 changes: 29 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ const defaultStatsdAddress = "localhost:8125"
var validNetworks = []string{"tcp", "tcp4", "tcp6", "unix", "unixpacket"}

type Config struct {
Network string
LocalSocketPrefix string
LocalSocketSuffix string
Unlink bool
MinPoolSize uint64
MaxPoolSize uint64
Pretty bool
Statsd string
Level zapcore.Level
Upstreams []Upstream
Network string
LocalSocketPrefix string
LocalSocketSuffix string
Unlink bool
MinPoolSize uint64
MaxPoolSize uint64
Pretty bool
Statsd string
Level zapcore.Level
Upstreams []Upstream
HealthCheck bool
ServerHealthCheckSec uint64
ServerHealthCheckThreshold uint64
}

type Upstream struct {
Expand Down Expand Up @@ -72,13 +75,18 @@ func parseFlags() (*Config, error) {

var network, localSocketPrefix, localSocketSuffix, stats, loglevel string
var pretty, unlink bool
var healthCheck bool
var healthCheckThreshold, healthCheckCycle uint64
flag.StringVar(&network, "network", "unix", "One of: tcp, tcp4, tcp6, unix or unixpacket")
flag.StringVar(&localSocketPrefix, "localsocketprefix", "/var/tmp/redisbetween-", "Prefix to use for unix socket filenames")
flag.StringVar(&localSocketSuffix, "localsocketsuffix", ".sock", "Suffix to use for unix socket filenames")
flag.BoolVar(&unlink, "unlink", false, "Unlink existing unix sockets before listening")
flag.StringVar(&stats, "statsd", defaultStatsdAddress, "Statsd address")
flag.BoolVar(&pretty, "pretty", false, "Pretty print logging")
flag.StringVar(&loglevel, "loglevel", "info", "One of: debug, info, warn, error, dpanic, panic, fatal")
flag.BoolVar(&healthCheck, "healthcheck", false, "Start the routine to do health checks on redis servers")
flag.Uint64Var(&healthCheckCycle, "healthcheckcycle", 60, "Integer value for the cycle during which server connections will be health-checked (sec); Must be bigger than healthcheckthreshold * 1sec; default: 60s")
flag.Uint64Var(&healthCheckThreshold, "healthcheckthreshold", 3, "The number of concecutive failures needed to declare a server connection dead; default: 3")

// todo remove these flags in a follow up, after all envs have updated to the new url-param style of timeout config
var obsoleteArg string
Expand Down Expand Up @@ -167,14 +175,17 @@ func parseFlags() (*Config, error) {
}

return &Config{
Upstreams: upstreams,
Network: network,
LocalSocketPrefix: localSocketPrefix,
LocalSocketSuffix: localSocketSuffix,
Unlink: unlink,
Pretty: pretty,
Statsd: stats,
Level: level,
Upstreams: upstreams,
Network: network,
LocalSocketPrefix: localSocketPrefix,
LocalSocketSuffix: localSocketSuffix,
Unlink: unlink,
Pretty: pretty,
Statsd: stats,
Level: level,
HealthCheck: healthCheck,
ServerHealthCheckThreshold: healthCheckThreshold,
ServerHealthCheckSec: healthCheckCycle,
}, nil
}

Expand Down
Loading

0 comments on commit a1acb83

Please sign in to comment.