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

setup ConsulConfig and ConsulExtras #252

Merged
merged 2 commits into from
Dec 8, 2016
Merged

setup ConsulConfig and ConsulExtras #252

merged 2 commits into from
Dec 8, 2016

Conversation

flyinprogrammer
Copy link
Contributor

This might address:
#213
#218
#243

I should write more tests.

@flyinprogrammer
Copy link
Contributor Author

flyinprogrammer commented Nov 22, 2016

So far as I can tell, there's actually no way to get the value of DeregisterCriticalServiceAfter out of the consul API because the /v1/agent/checks API returns an AgentCheck which does not posses the CheckType data.

@@ -99,6 +96,7 @@ consul:
docker rm -f containerpilot_consul > /dev/null 2>&1 || true
docker run -d -m 256m --name containerpilot_consul \
consul:latest agent -dev -client 0.0.0.0 -bind=0.0.0.0
docker run --rm --link containerpilot_consul:consul flyinprogrammer/wait4consul
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's check this in the test runner and not the makefile; it's possible to run the tests against an existing Consul.

var consulExtras *discovery.ConsulExtras
if s.ConsulConfig != nil {
consulExtras = &discovery.ConsulExtras{
DeregisterCriticalServiceAfter: s.ConsulConfig.DeregisterCriticalServiceAfter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever validate this is a valid time?

// ConsulConfig handles additional Consul configuration.
type ConsulConfig struct {
EnableTagOverride bool `mapstructure:"enabletagoverride"`
DeregisterCriticalServiceAfter string `mapstructure:"deregistercriticalserviceafter"`
Copy link
Contributor

@tgross tgross Nov 22, 2016

Choose a reason for hiding this comment

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

I feel like these deserialization annotations should probably be camelCase, given that we use it elsewhere (ex. preStart)

@tgross
Copy link
Contributor

tgross commented Nov 22, 2016

So far as I can tell, there's actually no way to get the value of DeregisterCriticalServiceAfter out of the consul API because the /v1/agent/checks API returns an AgentCheck which does not posses the CheckType data.

Don't we only ever write it though? Not read it? Or are you concerned (reasonably) about testing it?

"timeout": "1ms",
"tags": ["tag1","tag2"],
"consul": {
"enabletagoverride": true
Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely should be testing for misconfigurations for both of these features too.

@tgross
Copy link
Contributor

tgross commented Nov 22, 2016

Looking pretty good with just the few questions and comments. It's just about as ugly as I expected in terms of what configuration we end up with. 😀 We should update the documentation as well as part of the same PR.

@flyinprogrammer
Copy link
Contributor Author

Alright see what you think of this @tgross and I'll start working on documentation tonight.

@@ -91,7 +91,7 @@ func TestReloadSignal(t *testing.T) {
if err == nil {
t.Errorf("Invalid configuration did not return error")
}
app.ConfigFlag = `{ "consul": "newconsul:8500" }`
app.ConfigFlag = `{ "consul": "consul:8500" }`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why'd we change this? We want to make sure we have a different configuration than we had before during the reload.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A side effect of the timeout in NewConsulConfig is this needing to be a valid endpoint.


maxRetry := 30
retry := 0
// we need to wait for Consul to start and self-elect
Copy link
Contributor

Choose a reason for hiding this comment

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

This section appears to have been added to support #164 but I'd really like that behavior change to be a separate PR and design discussion.

I'm not comfortable adding a hard-coded retry here nor making it non-optional. It's entirely reasonable to have an application start up without Consul being ready, and to have it simply fail to make health checks until Consul is available (so long as ContainerPilot can handle this without crashing, which as far as I'm aware it can currently do just fine).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hahaha you give me too much credit @tgross, I'm much lazier than this 😄. I went to go add a WaitForLeader() type method to our tests, and figured why not add it to the code that actually creates the client. I'm in full agreement with you, this will be gone in a moment, and I'd love to work on #164 in a separate PR as I have a similar desire/use case on wanting an app on startup to crash, but if it's already up, to stay running.

t.Fatalf("First read of %s should show `false` for change", id)
}
consul.SendHeartbeat(service) // force registration
consul.SendHeartbeat(service) // write TTL
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to do without the second heartbeat now that #247 has been merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, I'll try this out in a few minutes.

@tgross
Copy link
Contributor

tgross commented Dec 2, 2016

Looks good, with some comments. There are some integration tests failing intermittently -- I kicked the build again to see if it was a flaky test and a different one failed. I suspect that we're seeing the bug I hopefully fixed in #256 yesterday here, so once that's merged we should rebase on master to double-check.

@flyinprogrammer
Copy link
Contributor Author

flyinprogrammer commented Dec 2, 2016

so once that's merged we should rebase on master to double-check.

I await the merge.

This is fun, thanks for your help, and I'll refactor this again based on your comments!

@tgross
Copy link
Contributor

tgross commented Dec 2, 2016

Ok #256 has been merged, let's give that rebase a go.

@tgross
Copy link
Contributor

tgross commented Dec 8, 2016

This all LGTM. Let's merge it and I'll release this as 2.6.0. Thanks again for your help @flyinprogrammer!

@tgross tgross merged commit 348b254 into TritonDataCenter:master Dec 8, 2016
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.

2 participants