Translate Address to tagged WAN address in HTTP API when appropriate. #2118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Likely of interest to @slackpad and @evan2645.
This PR builds on #1698. That PR translates a returned IP address to a WAN address when Consul is configured appropriately, but only through the DNS interface.
This PR additionally translates a node's address to the WAN address in the HTTP API. The rationale is:
The particular use case that motivated this change is "using the HTTP API in a NAT'd, multi-DC environment, I want to query for all nodes providing service X, and I want to be able to connect to those nodes using the returned
Address
".The changes that this PR makes are:
TaggedAddresses
to theServiceNode
struct (so that thecatalog_endpoint.go
, in particular, has access to them and co do the WAN translation before returning the result)TaggedAddresses
in theServiceNode
struct instate_store.go
translateAddr
intoagent.go
and modifying the signature slightly so that it can be used from both HTTP and DNS handlers/v1/catalog/nodes
/v1/catalog/node/<node>
/v1/catalog/service/<service>
/v1/health/service/<service>
/v1/query/<query or name>/execute
Added tests are passing, but it seems some of the existing tests are somewhat flaky and will occasionally fail. AFAICT, the failures don't have anything to do with this PR's additions.
First time Go user, view the code with suspicion :-).