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 consul version compatibility check on startup #62

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

findkim
Copy link
Contributor

@findkim findkim commented May 14, 2020

Recent versions of the ESM Consul client uses endpoints that are not supported in Consul
prior to 1.4.1. This checks for compatibility with all running Consul servers at startup and exits
with an informative error rather than silently failing on updating health checks for external
services.

This a follow-up PR to enforce the version constraint in the documentation
https://github.com/hashicorp/consul-esm#prerequisites

Example error message

$ consul-esm 
2020/05/14 13:58:40 [INFO] Connecting to Consul on 127.0.0.1:8500...
2020/05/14 13:58:40 [ERR] Incompatible Consul versions

Consul ESM version 0.3.4-dev is incompatible with the running versions of the local
Consul agent or Consul servers (1.3.1), please refer to the documentation
to safely upgrade Consul or change to a version of ESM that is compatible.

https://www.consul.io/docs/upgrading.html

New CLI version output

$ consul-esm -version
0.3.4-dev
Compatible with Consul versions >= 1.4.1

Resolves #33

Copy link
Member

@lornasong lornasong left a comment

Choose a reason for hiding this comment

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

looks good to me! very readable and lots of helpful comments. only a suggestion for a tiny typo

// to retry the request.
return fmt.Errorf("unable to check version compatibility with Consul agent: %s", err)
}
agentVersionRaw, ok := agentInfo["Config"]["Version"]
Copy link
Member

Choose a reason for hiding this comment

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

cool - didn't know you could check a map within a map in one call!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly always have to sanity check this in https://play.golang.com/ 😂

if err != nil {
if strings.Contains(err.Error(), "429") {
// 429 is a warning that something is unhealthy. This may occur when ESM
// races with Consul servers first starting up, so this is safe to retry.
Copy link
Member

Choose a reason for hiding this comment

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

helpful comment, thanks!


func TestAgent_VerifyConsulCompatibility(t *testing.T) {
// Smoke test to test the compatibility with the current Consul version
// pinned in go dependency.
Copy link
Member

Choose a reason for hiding this comment

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

🎉

version/version.go Outdated Show resolved Hide resolved
The ESM Consul client uses endpoints that are not supported in Consul
prior to 1.4.1. This checks for compatibility with all running Consul
servers at startup and exits with an informative error rather than
silently failing on updating health checks for external services.
Compatibility with agent is necessary because the ESM client makes
health check update using txn request to the local agent first, which
then is forwarded to the servers.
@findkim findkim merged commit 1151348 into hashicorp:master Jun 15, 2020
@findkim findkim deleted the consul-version branch June 15, 2020 16:47
@lornasong lornasong added this to the 0.4.0 milestone Jul 24, 2020
lornasong added a commit that referenced this pull request Aug 6, 2020
ACL for operator:read is necessary for Consul-ESM v0.4.0 due to a new feature that check’s ESM and Consul’s version compatibility on start up: #62. This feature makes a request to /operator/autopilot, which needs to be added to the list of necessary ACLs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Service status in Consul is never updated
2 participants