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 advertise_addrs. #1004

Merged
merged 1 commit into from
Jun 23, 2015
Merged

Add advertise_addrs. #1004

merged 1 commit into from
Jun 23, 2015

Conversation

hanshasselberg
Copy link
Member

Fixes #550.
This will make it possible to configure the advertised adresses for SerfLan, SerfWan and RPC. It will enable multiple consul clients on a single host which is very useful in a container environment.

This option might override advertise_addr and advertise_addr_wan depending on the configuration.

It will be configureable with advertise_addrs. Example:

{
  "advertise_addrs": {
    "serf_lan": "10.0.120.91:4424",
    "serf_wan": "201.20.10.61:4423",
    "rpc": "10.20.10.61:4424"
  }
}

base.SerfWANConfig.MemberlistConfig.AdvertiseAddr = addr.IP.String()
base.SerfWANConfig.MemberlistConfig.AdvertisePort = addr.Port
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of printing a message for both of the above and allowing Consul to start even with a bad advertise address specified in its config, can we store the *net.TCPAddrs in the AdvertiseAddrs struct and parse the address while we are decoding? This would also make a config merge pretty easy for these fields. We do a similar thing with parsing time values.

@ryanuber
Copy link
Member

ryanuber commented Jun 5, 2015

Hey @i0rek, I took a quick look through what you have so far and I think you're on the right track. We are missing a few things. See my comment above. We will also need to add the new config fields to the Merge method in a *Config, so that the new config options may be specified in any configuration file and not just the first one on the list.

@hanshasselberg
Copy link
Member Author

Thank you very much for the suggestions @ryanuber! I will take care of them beginning next week.

@hanshasselberg hanshasselberg changed the title Add advertise_addrs. [HOLD] Add advertise_addrs. Jun 8, 2015
@hanshasselberg
Copy link
Member Author

@ryanuber I think I added everything you suggested. Still have to test it though.

addr, err := net.ResolveTCPAddr("tcp", result.AdvertiseAddrs.SerfLanRaw)
if err != nil {
return nil, fmt.Errorf("AdvertiseAddrs.SerfLan is invalid: %v", err)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit-pick but let's drop these else statements, since we already return in the error path above.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am sorry, I should've paid more attention to the other code.

@ryanuber
Copy link
Member

ryanuber commented Jun 8, 2015

@i0rek this is looking good. Ping me when you feel it is complete and I'll give it another once-over!

@hanshasselberg
Copy link
Member Author

In theory this could be necessary for CLI RPC, HTTP API and DNS Interface too. What do you think? When any of the above available from the outside it would be good to include them in the advertise_addrs configuration.

@hanshasselberg hanshasselberg changed the title [HOLD] Add advertise_addrs. [WIP] Add advertise_addrs. Jun 9, 2015
@hanshasselberg
Copy link
Member Author

Ok, it works fine for our usecase. Which is letting consul run in two containers on one host, connecting to a remote server. This is the configuration I used:

{ "advertise_addr": "10.111.111.112", "advertise_addrs": { "serf_lan": "10.111.111.112:9301" } }

I don't think RPC works yet, but I could add that afterwards.

docker1            10.111.111.112:9301    alive   client  0.5.2  2
docker2            10.111.111.112:8301    alive   client  0.5.2  2

@hanshasselberg hanshasselberg changed the title [WIP] Add advertise_addrs. Add advertise_addrs. Jun 9, 2015
@hanshasselberg
Copy link
Member Author

@ryanuber I added RPC to the mix, because that was missing. I also added a little bit of documentation, not sure how you handle that. I was planning to rebase a last time after you looked at it so that you have a nice commit you can merge. I am not sure how you handle that either.

}
if b.AdvertiseAddrs.RPC != nil {
result.AdvertiseAddrs.RPC = b.AdvertiseAddrs.RPC
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we are missing tests for this. Let's definitely make sure this is tested.

@ryanuber
Copy link
Member

@i0rek this looks good, just some minor notes about test coverage but overall this is really close! The documentation looks right. Also, no need to rebase this, since it can be cleanly applied against master in its current state.

@hanshasselberg
Copy link
Member Author

Thanks for the review @ryanuber. I added the tests.

@ryanuber
Copy link
Member

Great! Will review again soon!

On June 13, 2015 3:40:35 PM PDT, Hans Hasselberg notifications@github.com wrote:

Thanks for the review @ryanuber. I added the tests.


Reply to this email directly or view it on GitHub:
#1004 (comment)

Sent from my Android device with K-9 Mail. Please excuse my brevity.

@hanshasselberg
Copy link
Member Author

When I said rebasing, I meant squashing. I couldn't resist.

@hanshasselberg
Copy link
Member Author

I added tests to agent_test to make sure the configured values are used.

@hanshasselberg
Copy link
Member Author

@ryanuber any progress on this? Seems ready to merge to me. Thanks

@@ -322,6 +322,16 @@ definitions support being updated during a reload.
* <a name="advertise_addr"></a><a href="#advertise_addr">`advertise_addr`</a> Equivalent to
the [`-advertise` command-line flag](#_advertise).

* <a name="advertise_addrs"></a><a href="#advertise_addrs">`advertise_addrs`</a> Allows to set
the advertised addresses for SerfLan, SerfLan and RPC together with the port. This gives
Copy link
Member

Choose a reason for hiding this comment

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

I think we meant for this to be SerfLan, SerfWan, and RPC ?

@ryanuber
Copy link
Member

@i0rek sorry for the delay! It's been busy. Left a super-minor comment but otherwise let's get this merged. Great work!

Fixes #550.
This will make it possible to configure the advertised adresses for
SerfLan, SerfWan and RPC. It will enable multiple consul clients on a
single host which is very useful in a container environment.

This option might override advertise_addr and advertise_addr_wan
depending on the configuration.

It will be configureable with advertise_addrs. Example:

{
  "advertise_addrs": {
    "serf_lan": "10.0.120.91:4424",
    "serf_wan": "201.20.10.61:4423",
    "rpc": "10.20.10.61:4424"
  }
}
@hanshasselberg
Copy link
Member Author

@ryanuber no worries. I changed the typo!

@ryanuber
Copy link
Member

LGTM, thanks again!

ryanuber added a commit that referenced this pull request Jun 23, 2015
@ryanuber ryanuber merged commit d0348d1 into hashicorp:master Jun 23, 2015
@rotatingJazz
Copy link

BIG props!!! 👍

@hanshasselberg
Copy link
Member Author

❤️

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