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

Add script checks #12

Merged
merged 9 commits into from
Jan 11, 2019
Merged

Add script checks #12

merged 9 commits into from
Jan 11, 2019

Conversation

autero1
Copy link
Contributor

@autero1 autero1 commented Jan 8, 2019

Purpose of this PR is to document planned changes for adding a capability to execute health check script targets. PR #9 addresses this as part of the changes.

However, the idea with a smaller change is to have the capability available faster and add the advanced features (such as YAML config) incrementally. Feel free to disagree with the approach :)

@autero1
Copy link
Contributor Author

autero1 commented Jan 8, 2019

Seems the tests have failed since 10 months ago. Will look into it.

Copy link
Contributor

@josh-padnick josh-padnick left a comment

Choose a reason for hiding this comment

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

LGTM! This will be a nice addition. Left a few comments with ideas for minor improvements.

README.md Outdated Show resolved Hide resolved
README.md Outdated
504 Gateway Not Found`.

```
health-checker --listener "0.0.0.0:6000" --script /path/to/script.sh
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

@autero1
Copy link
Contributor Author

autero1 commented Jan 8, 2019

Now that I think of it, we might also want to consider adding the HTTP check after all, especially from the ZK point of view. Then we could monitor ZK with a script and Exhibitor with HTTP.

@josh-padnick
Copy link
Contributor

Does it make more sense to find a way to specify more than one script and then the script can do a simple CURL call itself?

@autero1
Copy link
Contributor Author

autero1 commented Jan 8, 2019

Definitely doable, we already support specifying multiple --port numbers, so that would work for the --script as well. Probably will have to parallelise the script executions in case there are more scripts to run.

@josh-padnick
Copy link
Contributor

Agreed. You can see how I originally handled parallelization here.

@autero1
Copy link
Contributor Author

autero1 commented Jan 10, 2019

This is now pretty much done and ready for review. I think the test now cover most of the use cases, including the unhappy paths.

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Looks great!

README.md Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

s/exeample/example/

| `--version` | Show the program's version | |

#### Example
If you execute a shell script, ensure you have a `shebang` line in your script, otherwise the script will fail with an `exec format error`.
Copy link
Member

Choose a reason for hiding this comment

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

Could our code catch that? Seems like a simple strings.HasPrefix("#!") would do the trick to avoid some confusing errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Catch here is that we can execute other targets than shell scripts. We would then first have to identify the script as shell script (via the extension or some other way) and only after that check the prefix within. I think it would unnecessarily clutter the code and potentially lead to even more confusing errors 😄

scripts := options.ParseScripts(scriptArr)

if len(ports) == 0 && len(scripts) == 0 {
return nil, OneOfParamsRequired{portFlag.Name, scriptFlag.Name}
Copy link
Member

Choose a reason for hiding this comment

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

Nice error handling 👍

scriptParams := []string{}
if len(commandArr) > 1 {
scriptParams = commandArr[1:]
}
Copy link
Member

Choose a reason for hiding this comment

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

For non-empty arrays, can be simplified to:

scriptName, scriptArgs := commandArr[0], commandArr[1:]

server/server.go Outdated
logger.Infof("Script %v successful", script)
}

waitGroup.Done()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be defered right at the top of this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it should.

@autero1 autero1 merged commit 780e701 into master Jan 11, 2019
@autero1 autero1 deleted the add_script_check branch January 11, 2019 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants