aboutsummaryrefslogtreecommitdiff
path: root/middleware/proxy/google.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-09-02 18:43:52 +0200
committerGravatar GitHub <noreply@github.com> 2017-09-02 18:43:52 +0200
commit9bcddc5c16f39a03408675b8c271138a757c94b6 (patch)
tree6a836a990924ede75cb23a72aaaba85535e49275 /middleware/proxy/google.go
parent3a96d1ab778417d2dc5384de8d3547674d77e6cc (diff)
downloadcoredns-9bcddc5c16f39a03408675b8c271138a757c94b6.tar.gz
coredns-9bcddc5c16f39a03408675b8c271138a757c94b6.tar.zst
coredns-9bcddc5c16f39a03408675b8c271138a757c94b6.zip
mw/proxy: simplify google code (#1019)
* mw/proxy: simplify google code Minimize bootstrap code a bit, and block on the first resolve of the google https endpont. Add more logging and include actual error in the returned errors. Also re-resolve every 120 seconds, instead of 300 (might eventually make this an option). * fix test
Diffstat (limited to 'middleware/proxy/google.go')
-rw-r--r--middleware/proxy/google.go55
1 files changed, 28 insertions, 27 deletions
diff --git a/middleware/proxy/google.go b/middleware/proxy/google.go
index 7b215f517..205b09379 100644
--- a/middleware/proxy/google.go
+++ b/middleware/proxy/google.go
@@ -112,11 +112,8 @@ func (g *google) exchangeJSON(addr, json string) ([]byte, error) {
return buf, nil
}
-func (g *google) Transport() string {
- return "tcp"
-}
-
-func (g *google) Protocol() string { return "https_google" }
+func (g *google) Transport() string { return "tcp" }
+func (g *google) Protocol() string { return "https_google" }
func (g *google) OnShutdown(p *Proxy) error {
g.quit <- true
@@ -130,52 +127,56 @@ func (g *google) OnStartup(p *Proxy) error {
req.SetQuestion(g.endpoint, dns.TypeA)
state := request.Request{W: new(fakeBootWriter), Req: req}
- new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
+ if len(*p.Upstreams) == 0 {
+ return fmt.Errorf("no upstreams defined")
+ }
- var oldUpstream Upstream
+ oldUpstream := (*p.Upstreams)[0]
- // ignore errors here, as we want to keep on trying.
+ log.Printf("[INFO] Bootstrapping A records %q", g.endpoint)
+
+ new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
if err != nil {
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
} else {
addrs, err1 := extractAnswer(new)
if err1 != nil {
- log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
- }
+ log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err1)
+ } else {
- if len(*p.Upstreams) > 0 {
- oldUpstream = (*p.Upstreams)[0]
up := newUpstream(addrs, oldUpstream.(*staticUpstream))
p.Upstreams = &[]Upstream{up}
- } else {
- log.Printf("[WARNING] Failed to bootstrap upstreams %q", g.endpoint)
+
+ log.Printf("[INFO] Bootstrapping A records %q found: %v", g.endpoint, addrs)
}
}
go func() {
- tick := time.NewTicker(300 * time.Second)
+ tick := time.NewTicker(120 * time.Second)
for {
select {
case <-tick.C:
+ log.Printf("[INFO] Resolving A records %q", g.endpoint)
+
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
if err != nil {
- log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
- } else {
- addrs, err1 := extractAnswer(new)
- if err1 != nil {
- log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
- continue
- }
+ log.Printf("[WARNING] Failed to resolve A records %q: %s", g.endpoint, err)
+ continue
+ }
- // TODO(miek): can this actually happen?
- if oldUpstream != nil {
- up := newUpstream(addrs, oldUpstream.(*staticUpstream))
- p.Upstreams = &[]Upstream{up}
- }
+ addrs, err1 := extractAnswer(new)
+ if err1 != nil {
+ log.Printf("[WARNING] Failed to resolve A records %q: %s", g.endpoint, err1)
+ continue
}
+ up := newUpstream(addrs, oldUpstream.(*staticUpstream))
+ p.Upstreams = &[]Upstream{up}
+
+ log.Printf("[INFO] Resolving A records %q found: %v", g.endpoint, addrs)
+
case <-g.quit:
return
}