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

DNS with new API #1513

Merged
merged 19 commits into from
Sep 28, 2017
Merged

DNS with new API #1513

merged 19 commits into from
Sep 28, 2017

Conversation

lyuxuan
Copy link
Contributor

@lyuxuan lyuxuan commented Sep 12, 2017

)

// NewDNSBuilder creates a dnsBuilder which is used to factory DNS resolvers.
func NewDNSBuilder() resolver.Builder {
Copy link
Contributor

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().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

rn: make(chan struct{}),
}

go dnsWatcher(d)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not d.watcher()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return nil, err
}

// IP address
Copy link
Contributor

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return i, nil
}

// DNS address (non-IP)
Copy link
Contributor

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
host, _ = formatIP(host)
i.updateChan <- resolver.Address{Addr: host + ":" + port}
go ipWatcher(i)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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()?

d.mu.Lock()
defer d.mu.Unlock()
d.t.Stop()
d.rn <- struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do an unblocking write?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good.

d.t.Reset(d.b.freq)
d.mu.Unlock()
d.cc.NewAddress(result)
d.cc.NewServiceConfig(string(sc))
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

d.t.Reset(d.b.freq)
d.mu.Unlock()
d.cc.NewAddress(result)
d.cc.NewServiceConfig(string(sc))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

return true
}

func canaryingSC(js []byte) []byte {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


func (d *dnsResolver) lookup() ([]resolver.Address, []byte) {
newAddrs := d.lookupSRV()
if newAddrs == nil {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@menghanl menghanl self-assigned this Sep 12, 2017
@@ -0,0 +1,35 @@
// +build go1.6, !go1.8
Copy link
Contributor

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?

Copy link
Contributor Author

@lyuxuan lyuxuan Sep 13, 2017

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"
Copy link
Contributor

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

Copy link
Contributor Author

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

}

// TXT record must have "grpc_config=" attribute in order to be used as service config.
if len(res) < len(txtAttribute) || res[:len(txtAttribute)] != txtAttribute {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

defaultPort = "443"
defaultFreq = time.Minute * 30
golang = "GO"
txtAttribute = "grpc_config="
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

case <-d.rn:
}
result, sc := d.lookup()
// Next lookup should happen after an interval defined by d.b.freq.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// target doesn't have port
return host, port, nil
}
return "", "", fmt.Errorf("invalid target address %v", target)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

grpclog.Warningf("grpc: failed to parse service config json string due to %v.\n", err)
return ""
}
clihostname, err := os.Hostname()
Copy link
Contributor

Choose a reason for hiding this comment

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

cliHostName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

addrs, ok = cc.getAddress()
if ok > 0 {
break
}
Copy link
Contributor

Choose a reason for hiding this comment

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

time.Sleep(time.Millisecond)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
*/

package dns
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dfawley dfawley assigned lyuxuan and unassigned menghanl Sep 21, 2017
Copy link
Contributor

@menghanl menghanl left a 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.

}
}

func newBool(b bool) *bool {
Copy link
Contributor

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.

@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@lyuxuan
Copy link
Contributor Author

lyuxuan commented Sep 27, 2017

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@lyuxuan lyuxuan merged commit eaf555a into grpc:master Sep 28, 2017
@menghanl menghanl added this to the 1.7 Release milestone Sep 29, 2017
@menghanl menghanl added the Type: Feature New features or improvements in behavior label Sep 29, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants