Skip to content

Commit

Permalink
Rename few ENV vars and add CHECK_DONORS_ENABLED option and donor check
Browse files Browse the repository at this point in the history
  • Loading branch information
larrabee committed Sep 12, 2018
1 parent b46c7df commit 013fe26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ You can override any of the following values in configuration file:
- `WEB_READ_TIMEOUT`: Web server request read timeout in milliseconds. Default: `30000`
- `WEB_WRITE_TIMEOUT`: Web server request write timeout in milliseconds. Default: `30000`
- `CHECK_RO_ENABLED`: Mark 'read_only' node as available. Default: `false`
- `CHECK_FORCE_ENABLE`: Ignoring the status of the checks and always marking the node as available. Default: `false`
- `CHECK_FORCE_ENABLED`: Ignoring the status of the checks and always marking the node as available. Default: `false`
- `CHECK_DONORS_ENABLED`: Mark donors nodes as available. By default donor nodes marking as failed. Default: `false`
- `CHECK_INTERVAL`: Mysql checks interval in milliseconds. Default: `500`
- `CHECK_FAIL_TIMEOUT`: Mark the node inaccessible if for the specified time (in milliseconds) there were no successful checks. Default: `3000`
- `MYSQL_HOST`: MySQL host address. Default: `127.0.0.1`
- `MYSQL_PORT`: MySQL port. Default: `3306`
- `MYSQL_USER`: MySQL username. Default: `pxc_checker`
- `MYSQL_PASS`: Mysql password. Default: no password

7 changes: 6 additions & 1 deletion checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
reasonCheckTimeout ReasonCode = 4
reasonRWDisabled ReasonCode = 5
reasonNonPrimaryCluster ReasonCode = 6
reasonDonorsDisabled ReasonCode = 7
)

type Response struct {
Expand All @@ -34,7 +35,7 @@ func checkerHandler(ctx *fasthttp.RequestCtx) {
response := Response{NodeStatus: status}
ctx.SetContentType("application/json")

if config.CheckForceEnable {
if config.CheckForceEnabled {
ctx.SetStatusCode(fasthttp.StatusOK)
response.ReasonText = "Force enabled"
response.ReasonCode = reasonForceEnabled
Expand All @@ -46,6 +47,10 @@ func checkerHandler(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "Node in non-Primary cluster"
response.ReasonCode = reasonNonPrimaryCluster
} else if (status.WSRepStatus == 2) && !config.CheckDonorsEnabled {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "Node currently is donor"
response.ReasonCode = reasonDonorsDisabled
} else if (status.WSRepStatus != 4) && (status.WSRepStatus != 2) {
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
response.ReasonText = "WSRep failed"
Expand Down
2 changes: 1 addition & 1 deletion config/example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ MYSQL_USER="monitor"
MYSQL_PASS="monitorUserPassword"

CHECK_RO_ENABLED=false
CHECK_FORCE_ENABLE=false
CHECK_FORCE_ENABLED=false
CHECK_INTERVAL=500 # ms
CHECK_FAIL_TIMEOUT=3000 # ms
26 changes: 14 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ type NodeStatus struct {
}

type Config struct {
WebListen string
WebReadTimeout int
WebWriteTimeout int
CheckROEnabled bool
CheckInterval int64
CheckFailTimeout int64
CheckForceEnable bool
MysqlHost string
MysqlPort int
MysqlUser string
MysqlPass string
WebListen string
WebReadTimeout int
WebWriteTimeout int
CheckROEnabled bool
CheckForceEnabled bool
CheckDonorsEnabled bool
CheckInterval int64
CheckFailTimeout int64
MysqlHost string
MysqlPort int
MysqlUser string
MysqlPass string
}

var (
Expand Down Expand Up @@ -75,7 +76,8 @@ func parseFlags() *Config {
flag.IntVar(&config.WebReadTimeout, "WEB_READ_TIMEOUT", 30000, "Web server request read timeout, ms")
flag.IntVar(&config.WebWriteTimeout, "WEB_WRITE_TIMEOUT", 30000, "Web server request write timeout, ms")
flag.BoolVar(&config.CheckROEnabled, "CHECK_RO_ENABLED", false, "Mark 'read_only' node as available")
flag.BoolVar(&config.CheckForceEnable, "CHECK_FORCE_ENABLE", false, "Ignoring the status of the checks and always marking the node as available")
flag.BoolVar(&config.CheckForceEnabled, "CHECK_FORCE_ENABLED", false, "Ignoring the status of the checks and always marking the node as available")
flag.BoolVar(&config.CheckDonorsEnabled, "CHECK_DONORS_ENABLED", false, "Mark donors nodes as available.")
flag.Int64Var(&config.CheckInterval, "CHECK_INTERVAL", 500, "Mysql checks interval, ms")
flag.Int64Var(&config.CheckFailTimeout, "CHECK_FAIL_TIMEOUT", 3000, "Mark the node inaccessible if for the specified time there were no successful checks, ms")
flag.StringVar(&config.MysqlHost, "MYSQL_HOST", "127.0.0.1", "MySQL host addr")
Expand Down

0 comments on commit 013fe26

Please sign in to comment.