mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Dedup policy implement between grpc and proxy plugin (#3537)
Signed-off-by: zouyee <zounengren@cmss.chinamobile.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/debug"
|
||||
"github.com/coredns/coredns/plugin/pkg/policy"
|
||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
@@ -25,7 +26,7 @@ var log = clog.NewWithPlugin("forward")
|
||||
// of proxies each representing one upstream proxy.
|
||||
type Forward struct {
|
||||
proxies []*Proxy
|
||||
p Policy
|
||||
p policy.Policy
|
||||
hcInterval time.Duration
|
||||
|
||||
from string
|
||||
@@ -43,7 +44,7 @@ type Forward struct {
|
||||
|
||||
// New returns a new Forward.
|
||||
func New() *Forward {
|
||||
f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(random), from: ".", hcInterval: hcInterval}
|
||||
f := &Forward{maxfails: 2, tlsConfig: new(tls.Config), expire: defaultExpire, p: new(policy.Random), from: ".", hcInterval: hcInterval}
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -91,8 +92,8 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
}
|
||||
// All upstream proxies are dead, assume healthcheck is completely broken and randomly
|
||||
// select an upstream to connect to.
|
||||
r := new(random)
|
||||
proxy = r.List(f.proxies)[0]
|
||||
r := new(policy.Random)
|
||||
proxy = r.List(f.proxies)[0].([]*Proxy)[0]
|
||||
|
||||
HealthcheckBrokenCount.Add(1)
|
||||
}
|
||||
@@ -188,7 +189,12 @@ func (f *Forward) ForceTCP() bool { return f.opts.forceTCP }
|
||||
func (f *Forward) PreferUDP() bool { return f.opts.preferUDP }
|
||||
|
||||
// List returns a set of proxies to be used for this client depending on the policy in f.
|
||||
func (f *Forward) List() []*Proxy { return f.p.List(f.proxies) }
|
||||
func (f *Forward) List() []*Proxy {
|
||||
if len(f.p.List(f.proxies)) == 1 {
|
||||
return f.p.List(f.proxies)[0].([]*Proxy)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrNoHealthy means no healthy proxies left.
|
||||
|
||||
Reference in New Issue
Block a user