2017-09-14 09:36:06 +01:00
|
|
|
// Package proxy is plugin that proxies requests.
|
2016-03-18 20:57:35 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
|
|
import (
|
2018-04-22 08:34:35 +01:00
|
|
|
"context"
|
2016-03-18 20:57:35 +00:00
|
|
|
"errors"
|
2017-09-02 18:43:52 +02:00
|
|
|
"fmt"
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
"net"
|
2016-03-18 20:57:35 +00:00
|
|
|
"sync/atomic"
|
|
|
|
|
"time"
|
|
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
"github.com/coredns/coredns/plugin"
|
2018-04-18 09:42:20 +01:00
|
|
|
"github.com/coredns/coredns/plugin/metrics"
|
2017-09-14 09:36:06 +01:00
|
|
|
"github.com/coredns/coredns/plugin/pkg/healthcheck"
|
2017-02-21 22:51:47 -08:00
|
|
|
"github.com/coredns/coredns/request"
|
2016-04-30 15:54:41 +01:00
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
"github.com/miekg/dns"
|
2017-01-29 12:06:26 -08:00
|
|
|
ot "github.com/opentracing/opentracing-go"
|
2016-03-18 20:57:35 +00:00
|
|
|
)
|
|
|
|
|
|
2017-01-15 08:12:58 +00:00
|
|
|
var (
|
|
|
|
|
errUnreachable = errors.New("unreachable backend")
|
|
|
|
|
errInvalidProtocol = errors.New("invalid protocol")
|
2017-02-07 18:01:16 +00:00
|
|
|
errInvalidDomain = errors.New("invalid path for proxy")
|
2017-01-15 08:12:58 +00:00
|
|
|
)
|
2016-03-18 20:57:35 +00:00
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
// Proxy represents a plugin instance that can proxy requests to another (DNS) server.
|
2016-03-18 20:57:35 +00:00
|
|
|
type Proxy struct {
|
2017-09-14 09:36:06 +01:00
|
|
|
Next plugin.Handler
|
2017-02-06 19:32:48 +00:00
|
|
|
|
|
|
|
|
// Upstreams is a pointer to a slice, so we can update the upstream (used for Google)
|
|
|
|
|
// midway.
|
|
|
|
|
|
|
|
|
|
Upstreams *[]Upstream
|
2017-03-01 10:41:54 -05:00
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
// Trace is the Trace plugin, if it is installed
|
2017-03-01 10:41:54 -05:00
|
|
|
// This is used by the grpc exchanger to trace through the grpc calls
|
2017-09-14 09:36:06 +01:00
|
|
|
Trace plugin.Handler
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Upstream manages a pool of proxy upstream hosts. Select should return a
|
|
|
|
|
// suitable upstream host, or nil if no such hosts are available.
|
|
|
|
|
type Upstream interface {
|
|
|
|
|
// The domain name this upstream host should be routed on.
|
|
|
|
|
From() string
|
|
|
|
|
// Selects an upstream host to be routed to.
|
2017-08-09 09:21:33 -07:00
|
|
|
Select() *healthcheck.UpstreamHost
|
2016-03-18 20:57:35 +00:00
|
|
|
// Checks if subpdomain is not an ignored.
|
2017-02-07 18:01:16 +00:00
|
|
|
IsAllowedDomain(string) bool
|
2017-02-06 19:32:48 +00:00
|
|
|
// Exchanger returns the exchanger to be used for this upstream.
|
|
|
|
|
Exchanger() Exchanger
|
2017-04-26 10:58:14 +01:00
|
|
|
// Stops the upstream from proxying requests to shutdown goroutines cleanly.
|
|
|
|
|
Stop() error
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tryDuration is how long to try upstream hosts; failures result in
|
|
|
|
|
// immediate retries until this duration ends or we get a nil host.
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
var tryDuration = 16 * time.Second
|
2016-03-18 20:57:35 +00:00
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
// ServeDNS satisfies the plugin.Handler interface.
|
2016-03-19 07:18:57 +00:00
|
|
|
func (p Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
2017-01-23 15:40:47 -05:00
|
|
|
var span, child ot.Span
|
|
|
|
|
span = ot.SpanFromContext(ctx)
|
2017-01-15 08:12:58 +00:00
|
|
|
state := request.Request{W: w, Req: r}
|
2017-02-07 18:01:16 +00:00
|
|
|
|
|
|
|
|
upstream := p.match(state)
|
|
|
|
|
if upstream == nil {
|
2017-09-14 09:36:06 +01:00
|
|
|
return plugin.NextOrFailure(p.Name(), p.Next, ctx, w, r)
|
2017-02-07 18:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for {
|
2016-03-18 20:57:35 +00:00
|
|
|
start := time.Now()
|
2018-07-28 17:32:13 +08:00
|
|
|
var reply *dns.Msg
|
2017-09-02 18:43:52 +02:00
|
|
|
var backendErr error
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// Since Select() should give us "up" hosts, keep retrying
|
|
|
|
|
// hosts until timeout (or until we get a nil host).
|
2017-08-06 05:54:24 -07:00
|
|
|
for time.Since(start) < tryDuration {
|
2016-03-18 20:57:35 +00:00
|
|
|
host := upstream.Select()
|
|
|
|
|
if host == nil {
|
2017-09-02 18:43:52 +02:00
|
|
|
return dns.RcodeServerFailure, fmt.Errorf("%s: %s", errUnreachable, "no upstream host")
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-23 15:40:47 -05:00
|
|
|
if span != nil {
|
|
|
|
|
child = span.Tracer().StartSpan("exchange", ot.ChildOf(span.Context()))
|
|
|
|
|
ctx = ot.ContextWithSpan(ctx, child)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
atomic.AddInt64(&host.Conns, 1)
|
2016-10-08 14:46:22 +01:00
|
|
|
|
2018-04-18 09:42:20 +01:00
|
|
|
RequestCount.WithLabelValues(metrics.WithServer(ctx), state.Proto(), upstream.Exchanger().Protocol(), familyToString(state.Family()), host.Name).Add(1)
|
2017-10-08 04:30:44 -07:00
|
|
|
|
2017-09-02 18:43:52 +02:00
|
|
|
reply, backendErr = upstream.Exchanger().Exchange(ctx, host.Name, state)
|
2016-10-08 14:46:22 +01:00
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
atomic.AddInt64(&host.Conns, -1)
|
2016-10-08 14:46:22 +01:00
|
|
|
|
2017-01-23 15:40:47 -05:00
|
|
|
if child != nil {
|
|
|
|
|
child.Finish()
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 19:46:41 +01:00
|
|
|
taperr := toDnstap(ctx, host.Name, upstream.Exchanger(), state, reply, start)
|
2017-09-01 12:41:41 +02:00
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
if backendErr == nil {
|
2018-03-25 17:11:10 +01:00
|
|
|
|
|
|
|
|
// Check if the reply is correct; if not return FormErr.
|
|
|
|
|
if !state.Match(reply) {
|
|
|
|
|
formerr := state.ErrorMessage(dns.RcodeFormatError)
|
|
|
|
|
w.WriteMsg(formerr)
|
|
|
|
|
return 0, taperr
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 14:46:22 +01:00
|
|
|
w.WriteMsg(reply)
|
2016-10-28 12:54:49 +01:00
|
|
|
|
2018-04-18 09:42:20 +01:00
|
|
|
RequestDuration.WithLabelValues(metrics.WithServer(ctx), state.Proto(), upstream.Exchanger().Protocol(), familyToString(state.Family()), host.Name).Observe(time.Since(start).Seconds())
|
2016-10-28 12:54:49 +01:00
|
|
|
|
2017-09-01 12:41:41 +02:00
|
|
|
return 0, taperr
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
2017-09-01 12:41:41 +02:00
|
|
|
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
// A "ANY isc.org" query is being dropped by ISC's nameserver, we see this as a i/o timeout, but
|
|
|
|
|
// would then mark our upstream is being broken. We should not do this if we consider the error temporary.
|
|
|
|
|
// Of course it could really be that our upstream is broken
|
|
|
|
|
if oe, ok := backendErr.(*net.OpError); ok {
|
|
|
|
|
// Note this keeps looping and trying until tryDuration is hit, at which point our client
|
|
|
|
|
// might be long gone...
|
|
|
|
|
if oe.Timeout() {
|
2018-08-14 17:55:55 +02:00
|
|
|
// Our upstream's upstream is probably messing up, continue with next selected
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
// host - which my be the *same* one as we don't set any uh.Fails.
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
timeout := host.FailTimeout
|
|
|
|
|
if timeout == 0 {
|
2017-10-15 19:38:39 +02:00
|
|
|
timeout = defaultFailTimeout
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
atomic.AddInt32(&host.Fails, 1)
|
2017-10-15 19:38:39 +02:00
|
|
|
fails := atomic.LoadInt32(&host.Fails)
|
plugin/proxy: decrease health timeouts (#1107)
Turn down the timeouts and numbers a bit:
FailTimeout 10s -> 5s
Future 60s -> 12s
TryDuration 60s -> 16s
The timeout for decrementing the fails in a host: 10s -> 2s
And the biggest change: don't set fails when the error is Timeout(),
meaning we loop for a bit and may try the same server again, but we
don't mark our upstream as bad, see comments in proxy.go. Testing this
with "ANY isc.org" and "MX miek.nl" we see:
~~~
::1 - [24/Sep/2017:08:06:17 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.001621221s
24/Sep/2017:08:06:17 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:37420->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:17 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 35.957284ms
127.0.0.1 - [24/Sep/2017:08:06:18 +0100] "ANY IN isc.org. udp 37 false 4096" SERVFAIL qr,rd 37 10.002051726s
24/Sep/2017:08:06:18 +0100 [ERROR 0 isc.org. ANY] unreachable backend: read udp 192.168.1.148:54901->8.8.8.8:53: i/o timeout
::1 - [24/Sep/2017:08:06:19 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 56.848416ms
127.0.0.1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 48.118349ms
::1 - [24/Sep/2017:08:06:21 +0100] "MX IN miek.nl. udp 37 false 4096" NOERROR qr,rd,ra,ad 170 1.055172915s
~~~
So the ANY isc.org queries show up twice, because we retry internally -
this is I think WAI.
The `miek.nl MX` queries are just processed normally as no backend is
marked as unreachable.
May fix #1035 #486
2017-09-24 20:05:36 +01:00
|
|
|
|
2017-08-09 09:21:33 -07:00
|
|
|
go func(host *healthcheck.UpstreamHost, timeout time.Duration) {
|
2016-03-18 20:57:35 +00:00
|
|
|
time.Sleep(timeout)
|
2017-10-15 19:38:39 +02:00
|
|
|
// we may go negative here, should be rectified by the HC.
|
2016-03-18 20:57:35 +00:00
|
|
|
atomic.AddInt32(&host.Fails, -1)
|
2017-10-15 19:38:39 +02:00
|
|
|
if fails%failureCheck == 0 { // Kick off healthcheck on eveyry third failure.
|
|
|
|
|
host.HealthCheckURL()
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
}(host, timeout)
|
|
|
|
|
}
|
2016-10-28 12:54:49 +01:00
|
|
|
|
2017-09-02 18:43:52 +02:00
|
|
|
return dns.RcodeServerFailure, fmt.Errorf("%s: %s", errUnreachable, backendErr)
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
2017-02-07 18:01:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p Proxy) match(state request.Request) (u Upstream) {
|
2017-03-02 19:35:44 +00:00
|
|
|
if p.Upstreams == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 18:01:16 +00:00
|
|
|
longestMatch := 0
|
|
|
|
|
for _, upstream := range *p.Upstreams {
|
|
|
|
|
from := upstream.From()
|
|
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
if !plugin.Name(from).Matches(state.Name()) || !upstream.IsAllowedDomain(state.Name()) {
|
2017-02-07 18:01:16 +00:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if lf := len(from); lf > longestMatch {
|
|
|
|
|
longestMatch = lf
|
|
|
|
|
u = upstream
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return u
|
|
|
|
|
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-27 11:48:37 +00:00
|
|
|
// Name implements the Handler interface.
|
2016-10-26 10:01:52 +01:00
|
|
|
func (p Proxy) Name() string { return "proxy" }
|
|
|
|
|
|
2017-10-15 19:38:39 +02:00
|
|
|
const (
|
|
|
|
|
defaultFailTimeout = 2 * time.Second
|
|
|
|
|
defaultTimeout = 5 * time.Second
|
|
|
|
|
failureCheck = 3
|
|
|
|
|
)
|