Improve gRPC Plugin when backend is not available (#3966)
* Improve gRPC Plugin when backend is not available Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@serpro.gov.br> * Improve gRPC Plugin when backend is not available Signed-off-by: Ricardo Pchevuzinske Katz <ricardo.katz@serpro.gov.br>
This commit is contained in:
parent
d371738149
commit
3ebb46320a
1 changed files with 17 additions and 5 deletions
|
@ -3,6 +3,7 @@ package grpc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
@ -38,7 +39,7 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||||
var (
|
var (
|
||||||
span, child ot.Span
|
span, child ot.Span
|
||||||
ret *dns.Msg
|
ret *dns.Msg
|
||||||
err error
|
upstreamErr, err error
|
||||||
i int
|
i int
|
||||||
)
|
)
|
||||||
span = ot.SpanFromContext(ctx)
|
span = ot.SpanFromContext(ctx)
|
||||||
|
@ -73,6 +74,8 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||||
child.Finish()
|
child.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upstreamErr = err
|
||||||
|
|
||||||
// Check if the reply is correct; if not return FormErr.
|
// Check if the reply is correct; if not return FormErr.
|
||||||
if !state.Match(ret) {
|
if !state.Match(ret) {
|
||||||
debug.Hexdumpf(ret, "Wrong reply for id: %d, %s %d", ret.Id, state.QName(), state.QType())
|
debug.Hexdumpf(ret, "Wrong reply for id: %d, %s %d", ret.Id, state.QName(), state.QType())
|
||||||
|
@ -87,7 +90,11 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, nil
|
if upstreamErr != nil {
|
||||||
|
return dns.RcodeServerFailure, upstreamErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return dns.RcodeServerFailure, ErrNoHealthy
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGRPC returns a new GRPC.
|
// NewGRPC returns a new GRPC.
|
||||||
|
@ -129,3 +136,8 @@ func (g *GRPC) isAllowedDomain(name string) bool {
|
||||||
func (g *GRPC) list() []*Proxy { return g.p.List(g.proxies) }
|
func (g *GRPC) list() []*Proxy { return g.p.List(g.proxies) }
|
||||||
|
|
||||||
const defaultTimeout = 5 * time.Second
|
const defaultTimeout = 5 * time.Second
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrNoHealthy means no healthy proxies left.
|
||||||
|
ErrNoHealthy = errors.New("no healthy gRPC proxies")
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue