-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add script checks #12
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4aa5b29
Update README first in RDD -style.
dcfe397
Recommended updates to documentation.
2af902b
Implement options parsing and add tests
d900766
More tests
9de20d3
Add script execution target and corresponding tests
87fa1cb
Add more permutations to tests
770a126
Run tests from root instead
2286fe7
Fix a typo in one of the test names
02fe94c
Small improvements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# health-checker | ||
|
||
A simple HTTP server that will return `200 OK` if the given TCP ports are all successfully accepting connections. | ||
A simple HTTP server that will return `200 OK` if the configured checks are all successful. If any of the checks fail, | ||
it will return `HTTP 504 Gateway Not Found`. | ||
|
||
## Motivation | ||
|
||
|
@@ -14,15 +15,23 @@ a single TCP port, or an HTTP(S) endpoint. As a result, our use case just isn't | |
We wrote health-checker so that we could run a daemon on the server that reports the true health of the server by | ||
attempting to open a TCP connection to more than one port when it receives an inbound HTTP request on the given listener. | ||
|
||
Using the `--script` -option, the `health-checker` can be extended to check many other targets. One concrete exeample is monitoring | ||
`ZooKeeper` node status during rolling deployment. Just polling the `ZooKeeper`'s TCP client port doesn't necessarily guarantee | ||
that the node has (re-)joined the cluster. Using the `health-check` with a custom script target, we can | ||
[monitor ZooKeeper](https://zookeeper.apache.org/doc/r3.4.8/zookeeperAdmin.html#sc_monitoring) using the | ||
[4 letter words](https://zookeeper.apache.org/doc/r3.4.8/zookeeperAdmin.html#sc_zkCommands), ensuring we report health back to the | ||
[Load Balancer](https://aws.amazon.com/documentation/elastic-load-balancing/) correctly. | ||
|
||
## How It Works | ||
|
||
When health-checker is started, it will listen for inbound HTTP requests for any URL on the IP address and port specified | ||
by `--listener`. When it receives a request, it will attempt to open TCP connections to each of the ports specified by | ||
an instance of `--port`. If all TCP connections succeed, it will return `HTTP 200 OK`. If any TCP connection fails, it | ||
will return `HTTP 504 Gateway Not Found`. | ||
an instance of `--port` and/or execute the script target specified by `--script`. If all configured checks - all TCP | ||
connections and zero exit status for the script - succeed, it will return `HTTP 200 OK`. If any of the checks fail, | ||
it will return `HTTP 504 Gateway Not Found`. | ||
|
||
Configure your AWS Health Check to only pass the Health Check on `HTTP 200 OK`. Now when an HTTP Health Check request | ||
comes in, all desired TCP ports will be checked. | ||
comes in, all desired TCP ports will be checked and the script target executed. | ||
|
||
For stability, we recommend running health-checker under a process supervisor such as [supervisord](http://supervisord.org/) | ||
or [systemd](https://www.freedesktop.org/wiki/Software/systemd/) to automatically restart health-checker in the unlikely | ||
|
@@ -46,9 +55,10 @@ health-checker [options] | |
| `--listener` | The IP address and port on which inbound HTTP connections will be accepted. | `0.0.0.0:5000` | ||
| `--log-level` | Set the log level to LEVEL. Must be one of: `panic`, `fatal`, `error,` `warning`, `info`, or `debug` | `info` | ||
| `--help` | Show the help screen | | | ||
| `--script` | Path to script to run - will PASS if it completes within 5s with a zero exit status | | | ||
autero1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `--version` | Show the program's version | | | ||
|
||
#### Example | ||
#### Example 1 | ||
|
||
Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received, | ||
attempt to open TCP connections to port 5432 and 3306. If both succeed, return `HTTP 200 OK`. If any fails, return `HTTP | ||
|
@@ -58,3 +68,23 @@ attempt to open TCP connections to port 5432 and 3306. If both succeed, return ` | |
health-checker --listener "0.0.0.0:6000" --port 5432 --port 3306 | ||
``` | ||
|
||
#### Example 2 | ||
|
||
Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received, | ||
attempt to run the script. If exit code is zero, return `HTTP 200 OK`. If any other exit code, return `HTTP | ||
504 Gateway Not Found`. | ||
|
||
``` | ||
health-checker --listener "0.0.0.0:6000" --script /path/to/script.sh | ||
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. Can you show an example of how you'd pass args to the script? |
||
``` | ||
|
||
#### Example 3 | ||
|
||
Run a listener on port 6000 that accepts all inbound HTTP connections for any URL. When the request is received, | ||
attempt to open TCP connection to port 8000 and run the script. If both succeed, return `HTTP 200 OK`. If either fails, return `HTTP | ||
504 Gateway Not Found`. | ||
|
||
``` | ||
health-checker --listener "0.0.0.0:6000" --port 8000 --script /usr/local/bin/zk-health-check.sh | ||
``` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
s/exeample/example/