-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
DNS with new API #1513
DNS with new API #1513
Conversation
resolver/dns/dns_resolver.go
Outdated
) | ||
|
||
// NewDNSBuilder creates a dnsBuilder which is used to factory DNS resolvers. | ||
func NewDNSBuilder() resolver.Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to NewBuilder
.
Otherwise it will be dns.NewDNSBuilder()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
rn: make(chan struct{}), | ||
} | ||
|
||
go dnsWatcher(d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not d.watcher()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
return nil, err | ||
} | ||
|
||
// IP address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add period at the end...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
return i, nil | ||
} | ||
|
||
// DNS address (non-IP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add period at the end...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
} | ||
host, _ = formatIP(host) | ||
i.updateChan <- resolver.Address{Addr: host + ":" + port} | ||
go ipWatcher(i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not i.watcher()
?
And, we don't need this goroutine here. It should be OK to call NewAddress()
directly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. we still need a go routine here: when user calls ResolveNow() on IPWatcher we can return the same IP again, so we need a go routine to monitor user calling ResolveNow() and send IP as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call NewAddress()
in ipResolver.ResolveNow()
?
resolver/dns/dns_resolver.go
Outdated
d.mu.Lock() | ||
defer d.mu.Unlock() | ||
d.t.Stop() | ||
d.rn <- struct{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do an unblocking write?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good.
resolver/dns/dns_resolver.go
Outdated
d.t.Reset(d.b.freq) | ||
d.mu.Unlock() | ||
d.cc.NewAddress(result) | ||
d.cc.NewServiceConfig(string(sc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle ServiceConfig before addresses, so if the ServiceConfig changes balancer, we can avoid a bit overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
d.t.Reset(d.b.freq) | ||
d.mu.Unlock() | ||
d.cc.NewAddress(result) | ||
d.cc.NewServiceConfig(string(sc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And don't call NewServiceConfig if it's empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty can mean reset, e.g. switching from previous service config to no service config. But I just realize that, Mark mentioned that we should have an Option to turn on/off ServiceConfig check. So I may add some check here later I guess.
resolver/dns/dns_resolver.go
Outdated
return true | ||
} | ||
|
||
func canaryingSC(js []byte) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the reason this function takes a []byte
and returns a []byte
is that it calls json
functions, how about making this function takes a string
and returns a string
, and doing the conversion between []byte
and string
within this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
resolver/dns/dns_resolver.go
Outdated
|
||
func (d *dnsResolver) lookup() ([]resolver.Address, []byte) { | ||
newAddrs := d.lookupSRV() | ||
if newAddrs == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the result contains both balancer addresses and backend addresses?
There's a fallback mechanism that use backends directly if cannot connect to the remote balancers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it says future work here, but I guess we can do it now.
35cccf1
to
69fe9e1
Compare
@@ -0,0 +1,35 @@ | |||
// +build go1.6, !go1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name of file is go17, but the tag of build is go1.6, the name of file should be go16.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This build tags says go1.6 <= build < go1.8, which essentially means go1.6 and go1.7. So the file name indicates that this build file is for build <= go1.7.
import ( | ||
"net" | ||
|
||
"golang.org/x/net/context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context have been official lib on go1.7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but LookupHost
, LookupSRV
and LookupTXT
taking in a context starts from go1.8. see here
4f80d41
to
0af96da
Compare
resolver/dns/dns_resolver.go
Outdated
} | ||
|
||
// TXT record must have "grpc_config=" attribute in order to be used as service config. | ||
if len(res) < len(txtAttribute) || res[:len(txtAttribute)] != txtAttribute { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
defaultPort = "443" | ||
defaultFreq = time.Minute * 30 | ||
golang = "GO" | ||
txtAttribute = "grpc_config=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not hard to explain, add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
q: make(chan struct{}), | ||
} | ||
cc.NewAddress(addr) | ||
go i.watcher() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this goroutine?
Is it to support ResolveNow()
? If so, we could call NewAddress()
in ResolverNow()
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, and I am indirectly calling NewAddress()
in ResolveNow()
by sending an empty struct on a notification channel, so inside the watcher it will call NewAddress()
. We can also making ResolveNow()
running in a gorotine in place of watcher()
, but I think our current way is more consistent and clearer.
resolver/dns/dns_resolver.go
Outdated
case <-d.rn: | ||
} | ||
result, sc := d.lookup() | ||
// Next lookup should happen after an interval defined by d.b.freq. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: comment still shows d.b.freq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
// target doesn't have port | ||
return host, port, nil | ||
} | ||
return "", "", fmt.Errorf("invalid target address %v", target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the error returned by SplitHostPort
in the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver.go
Outdated
grpclog.Warningf("grpc: failed to parse service config json string due to %v.\n", err) | ||
return "" | ||
} | ||
clihostname, err := os.Hostname() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cliHostName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resolver/dns/dns_resolver_test.go
Outdated
addrs, ok = cc.getAddress() | ||
if ok > 0 { | ||
break | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time.Sleep(time.Millisecond)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* | ||
*/ | ||
|
||
package dns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an init()
to register the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ef970f7
to
62b449b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more nit in tests. Otherwise LGTM.
resolver/dns/dns_resolver_test.go
Outdated
} | ||
} | ||
|
||
func newBool(b bool) *bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems nobody calls these two functions.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Implement DNS resolver conforming to v2 resolver API. https://github.com/grpc/grpc-go/blob/master/resolver/resolver.go
Add service config support as specified here https://github.com/grpc/proposal/blob/master/A2-service-configs-in-dns.md