Skip to content
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

[WIP] refactor and add http and script checks #9

Closed
wants to merge 30 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c5927cf
docs for new http and script checks
sarkis Feb 28, 2018
b452fc1
fix 504 http status
sarkis Feb 28, 2018
7359201
a new approach using a config file
sarkis Feb 28, 2018
1a8dc74
changes from CR and better documentation
sarkis Feb 28, 2018
dc2a791
convert current ports check to work with yaml file
sarkis Feb 28, 2018
296b46f
use the struct to do tcp checks
sarkis Mar 1, 2018
f8e392f
fixes from CR
sarkis Mar 1, 2018
b8ce7a9
add http checkers
sarkis Mar 1, 2018
667aa16
adjust debug mode logic
sarkis Mar 1, 2018
f6c2b8c
update README and cleanup
sarkis Mar 1, 2018
687b550
comments and cleanup
sarkis Mar 1, 2018
de4dae1
use common Check interface
sarkis Mar 2, 2018
c115758
no longer need this to be a variable
sarkis Mar 2, 2018
7b1127e
add HttpCheck DoCheck method
sarkis Mar 2, 2018
c27b432
add DoCheck for ScriptCheck
sarkis Mar 3, 2018
607a644
add ValidateCheck for all checks and run after Unmarshaling
sarkis Mar 3, 2018
e98dd19
add a default http behavior to pass on 200 if no conditions defined
sarkis Mar 3, 2018
0321e74
add more info on configs in README
sarkis Mar 3, 2018
500434f
add an advanced example
sarkis Mar 3, 2018
2a8369d
refactor a bit to make unit testing easier
sarkis Mar 4, 2018
4eb333e
error with a message out if bad or empty config file is passed
sarkis Mar 4, 2018
fd09b6c
configurable timeout with a 5s default if not specified
sarkis Mar 4, 2018
c62118c
fix syntax error
sarkis Mar 4, 2018
faa39bd
remove call to opts here as it will not exist in the if err != nil
sarkis Mar 4, 2018
61a145b
add first internal unit test
sarkis Mar 4, 2018
03544b5
test an invalid config
sarkis Mar 4, 2018
308c457
cleanup tests and use subtests for better organization
sarkis Mar 10, 2018
00fc8e5
error cleanup
sarkis Mar 10, 2018
cf2321b
add more logging
sarkis Mar 10, 2018
59c1e2a
rename test file
sarkis Mar 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a quick start right here so users get a very clear idea of what this is and, most importantly, why they'd want to use it.

## Quick start

Put the following in `health-checker.yml`:

<include simple example of a file with two health checks>

And run `health-checker`. Now, requests to `localhost:xxx` will return a 200 OK if X and Y checks pass.


## Motivation

Expand All @@ -12,14 +12,14 @@ the TCP Listeners of both services are successfully accepting connections. But t
a single TCP port, or an HTTP(S) endpoint. As a result, our use case just isn't supported natively by AWS.

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.
checking more conditions than a just single port or HTTP request while still allowing for a single HTTP request on the given listener.

## How It Works
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rename this section to configuring health-checker?


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`.
When health-checker is started, it will parse a YAML file specified with the `--config` flag (example config
in [examples/config.yml.simple]()) and listen for inbound HTTP requests for any URL on the IP address and port specified
by `listener` directive. When it receives a request, it will attempt to run all checks specified in the config
and return `HTTP 200 OK` if all checks pass. If any of the checks fail, it will return `HTTP 504 GATEWAY TIMEOUT`.

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.
Expand All @@ -42,19 +42,23 @@ health-checker [options]

| Option | Description | Default
| ------ | ----------- | -------
| `--port` | The port number on which a TCP connection will be attempted. Specify one or more times. | |
| `--listener` | The IP address and port on which inbound HTTP connections will be accepted. | `0.0.0.0:5000`
| `--config` | A YAML config file containing options and checks | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps health-checker.yml in the current working dir should be the default?

| `--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 | |
| `--version` | Show the program's version | |

#### Example
#### Config File Options

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
504 Gateway Not Found`.
TODO: add more info on the config options

#### Examples

Parse configuration from `health-checker.yml` and run a listener that accepts all inbound HTTP connections for any URL. When
the request is received, attempt to run all checks specified in `health-checker.yml`. If all checks succeed, return `HTTP 200 OK`.
If any fail, return `HTTP 504 GATEWAY TIMEOUT`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like this paragraph adds much. I'd just say "see the examples folder for all examples."


```
health-checker --listener "0.0.0.0:6000" --port 5432 --port 3306
health-checker --config health-checker.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this right below the table of options.

```

See [examples/]() for configuration examples.