Documentation ¶
Overview ¶
Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.
Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.
Index ¶
- Variables
- type Forward
- func (f *Forward) ForceTCP() bool
- func (f *Forward) Len() int
- func (f *Forward) List() []*Proxy
- func (f *Forward) Name() string
- func (f *Forward) OnShutdown() error
- func (f *Forward) OnStartup() (err error)
- func (f *Forward) PreferUDP() bool
- func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (f *Forward) SetProxy(p *Proxy)
- type HealthChecker
- type Policy
- type Proxy
- func (p *Proxy) Connect(ctx context.Context, state request.Request, opts options) (*dns.Msg, error)
- func (p *Proxy) Down(maxfails uint32) bool
- func (p *Proxy) Healthcheck()
- func (p *Proxy) SetExpire(expire time.Duration)
- func (p *Proxy) SetLocalAddr(addr net.Addr)
- func (p *Proxy) SetTLSConfig(cfg *tls.Config)
- type Transport
- func (t *Transport) Dial(proto string) (*persistConn, bool, error)
- func (t *Transport) SetExpire(expire time.Duration)
- func (t *Transport) SetLocalAddr(addr net.Addr)
- func (t *Transport) SetTLSConfig(cfg *tls.Config)
- func (t *Transport) Start()
- func (t *Transport) Stop()
- func (t *Transport) Yield(pc *persistConn)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoHealthy means no healthy proxies left. ErrNoHealthy = errors.New("no healthy proxies") // ErrNoForward means no forwarder defined. ErrNoForward = errors.New("no forwarder defined") // ErrCachedClosed means cached connection was closed by peer. ErrCachedClosed = errors.New("cached connection was closed by peer") )
var ( RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "requests_total", Help: "Counter of requests made per upstream.", }, []string{"to"}) RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "responses_total", Help: "Counter of responses received per upstream.", }, []string{"rcode", "to"}) RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "request_duration_seconds", Buckets: plugin.TimeBuckets, Help: "Histogram of the time each request took.", }, []string{"to", "rcode"}) HealthcheckFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "healthcheck_failures_total", Help: "Counter of the number of failed healthchecks.", }, []string{"to"}) HealthcheckBrokenCount = promauto.NewCounter(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "healthcheck_broken_total", Help: "Counter of the number of complete failures of the healthchecks.", }) SocketGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "sockets_open", Help: "Gauge of open sockets per upstream.", }, []string{"to"}) MaxConcurrentRejectCount = promauto.NewCounter(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "max_concurrent_rejects_total", Help: "Counter of the number of queries rejected because the concurrent queries were at maximum.", }) ConnCacheHitsCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "conn_cache_hits_total", Help: "Counter of connection cache hits per upstream and protocol.", }, []string{"to", "proto"}) ConnCacheMissesCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "forward", Name: "conn_cache_misses_total", Help: "Counter of connection cache misses per upstream and protocol.", }, []string{"to", "proto"}) )
Variables declared for monitoring.
Functions ¶
This section is empty.
Types ¶
type Forward ¶
type Forward struct { // ErrLimitExceeded indicates that a query was rejected because the number of concurrent queries has exceeded // the maximum allowed (maxConcurrent) ErrLimitExceeded error Next plugin.Handler // contains filtered or unexported fields }
Forward represents a plugin instance that can proxy requests to another (DNS) server. It has a list of proxies each representing one upstream proxy.
func (*Forward) ForceTCP ¶ added in v1.1.3
ForceTCP returns if TCP is forced to be used even when the request comes in over UDP.
func (*Forward) List ¶ added in v1.1.3
List returns a set of proxies to be used for this client depending on the policy in f.
func (*Forward) OnShutdown ¶
OnShutdown stops all configured proxies.
func (*Forward) PreferUDP ¶ added in v1.2.0
PreferUDP returns if UDP is preferred to be used even when the request comes in over TCP.
type HealthChecker ¶ added in v1.2.0
type HealthChecker interface { Check(*Proxy) error SetTLSConfig(*tls.Config) SetRecursionDesired(bool) GetRecursionDesired() bool }
HealthChecker checks the upstream health.
func NewHealthChecker ¶ added in v1.2.0
func NewHealthChecker(trans string, recursionDesired bool) HealthChecker
NewHealthChecker returns a new HealthChecker based on transport.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy defines an upstream host.
func (*Proxy) Connect ¶ added in v1.1.3
Connect selects an upstream, sends the request and waits for a response.
func (*Proxy) Healthcheck ¶
func (p *Proxy) Healthcheck()
Healthcheck kicks of a round of health checks for this proxy.
func (*Proxy) SetLocalAddr ¶ added in v1.8.6
func (*Proxy) SetTLSConfig ¶
SetTLSConfig sets the TLS config in the lower p.transport and in the healthchecking client.
type Transport ¶ added in v1.2.3
type Transport struct {
// contains filtered or unexported fields
}
Transport hold the persistent cache.
func (*Transport) Dial ¶ added in v1.2.3
Dial dials the address configured in transport, potentially reusing a connection or creating a new one.
func (*Transport) SetExpire ¶ added in v1.2.3
SetExpire sets the connection expire time in transport.
func (*Transport) SetLocalAddr ¶ added in v1.8.6
SetLocalAddr specify the local address to use when connecting to the proxy
func (*Transport) SetTLSConfig ¶ added in v1.2.3
SetTLSConfig sets the TLS config in transport.
func (*Transport) Start ¶ added in v1.2.3
func (t *Transport) Start()
Start starts the transport's connection manager.