-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Docker Support for Consul Health Checks #1343
Conversation
…'t respond while running checks
I'm asking out of curiosity. How is this different from using "docker exec" in a standard script check? |
@salehe Not very different at all, but that depends on users generating scripts for every container running on the system. This exposes an API which makes this easy to run checks programatically, for example Nomad could use Consul agent to run health checks for a container that it is managing. |
Logger: a.logger, | ||
} | ||
dockerCheck.Start() | ||
a.checkDockers[check.CheckID] = dockerCheck | ||
} |
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.
I'd add a final else that returns an error that the type is unknown.
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.
@slackpad The previous behaviour defaulted to Script check, perhaps we should keep that?
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.
Yeah that would be ok, too.
One other thing - will need to updates the docs as well - it's all under /website. |
@@ -64,7 +68,7 @@ func (c *CheckType) IsTTL() bool { | |||
|
|||
// IsMonitor checks if this is a Monitor type | |||
func (c *CheckType) IsMonitor() bool { | |||
return c.Script != "" && c.Interval != 0 | |||
return c.Script != "" && c.DockerContainerId == "" && c.Interval != 0 |
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.
Actually this made me realize how sloppy the current else
is. We should probably add the script check back to Docker and make an explicit check for IsMonitor
and have an else
that fails. Right now we will roll into creating a monitor when these requirements aren't met. Sorry for the flip-flop on this one.
// Collect the output | ||
output, _ := circbuf.NewBuffer(CheckBufSize) | ||
|
||
err = c.dockerClient.StartExec(exec.ID, docker.StartExecOptions{Detach: false, Tty: false, OutputStream: output, ErrorStream: output}) |
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.
Is this Tty
option redundant with the one above? Also, does OutputStream
trump the Attach*
ones?
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.
Is this Tty option redundant with the one above?
I think this is an idiosyncrasy of the API. When you run via CLI some of these actions are merged (e.g. creating the exec and starting the exec) but via the API they are separate actions so you end up specifying the same setting twice. I haven't traced this all the way through but I think it's fine to specify twice for now.
} | ||
|
||
func TestDockerCheckWhenExecReturnsSuccessExitCode(t *testing.T) { | ||
expectDockerCheckStatus(t, &fakeDockerClientWithNoErrors{}, "passing") |
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.
Would be good to throw in a warning case as well, since there's a code path for it.
mock := &MockNotify{ | ||
state: make(map[string]string), | ||
updates: make(map[string]int), | ||
output: make(map[string]string), |
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.
Would it be pretty easy to make sure the output gets plumbed through? With the mock it's kind of lame but it would test the basic logic of the check.
Docker Support for Consul Health Checks
@diptanu it looks like this change broke some of the BSD targets (from a full
|
Hm.. I'm not sure whether this is (still) a problem in logrus or a problem because go-dockerclient has ventured an old version, but it may be easier to build flag this feature for now since Docker doesn't run on BSD anyway. |
This PR adds support for running script based health checks inside Docker Containers.
Users have to configure the checks by passing the container id, the script to run and the shell. We default to /bin/sh or override that with $SHELL in case the user doesn't specify the shell while configuring the check.
Ex -