feature: handle cnames, random ip from list when list, better handling of host.docker.local#12
Draft
feature: handle cnames, random ip from list when list, better handling of host.docker.local#12
Conversation
…g of host.docker.local
ChrisStatham
approved these changes
Aug 18, 2021
karljin
reviewed
Aug 18, 2021
alexpatz
approved these changes
Aug 18, 2021
consul_srv/query.py
Outdated
| for resource in answer: | ||
| if resource.rdtype == rdatatype.SRV: | ||
| a = self._lookup_host(resource.target) | ||
| if a is not False: |
There was a problem hiding this comment.
I'm wondering when is a returned from lookup_host going to be False? I see you set d=False in the function but as Karl says this d value doesn't then get appended to iplist. You may need to - instead of setting d to False - just add a line at the end of the function along the lines of:
if len(iplist) == 0:
return False
else:
return iplist[random.randint(0,len(iplist)-1)]
| if(server_address=='host.docker.internal'): | ||
| logging.debug('consul_srv: SPECIAL CASE FOR AGENT_URI = {}'.format(server_address)) | ||
| theresolver = dns.resolver.Resolver() | ||
| answer = theresolver.query('{}'.format(server_address)) |
There was a problem hiding this comment.
You may want to catch DNSException here? Like this example. Not sure what you would do if there was an exception though.
https://www.programcreek.com/python/example/97692/dns.resolver.Resolver
ingcsmoreno
approved these changes
Aug 18, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Still need to set up for new version to push to gemfurry
Goals here:
First, the DNS package doesn't like using "names" for nameserver (go figure) so we need to be able to resolve the special case 'host.docker.internal' to an IP and use that in the nameserver list when the override AGENT_URI contains that.
Second, currently consul_srv only worked when consul responded to a SRV request that contained an IP in the "address" field. Since it's part of the spec that consul can also support a host name here, we need to support that.
Third, we need to not change the lookup behavior much because of the non threaded, synchronous nature of python and dns. (this is a known problem and why there is the weird loop with random sleeps, a brute force method to work through the issue)
Some notes:
Behavior when CONSUL service is registered with an IP:
SRV request for an existing service addrservice registered with the ip of 4.3.2.1 returns:
04030201.addr.dc1.consul.is an internal consul record that we make a standard query for against consul returning:so the returned address should be 4.3.2.1
SRV request for an existing service hostservice registered with the hostname of hostservice.mksp.co:
hostservice.mksp.co.is an EXTERNAL host name that returns when queried against consul:NXDOMAIN - host doesn't exist
but when we query against the "normal" dns (no consul overrides) we get:
so the returned address should be one of the three at random
This changes the original behavior a bit which originally depended on using the additional section of the SRV request to get the IP
FULL SRV lookups for reference:
SRV addrservice asked against consul:
SRV hostservice asked against consul:
RESOLV request asked against not consul: