proxy

package
v1.10.1-v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2023 License: MIT Imports: 18 Imported by: 0

README

proxy

proxy copied from github.com/coredns/pkg/proxy@master

the coredns latest version has removed this build-in package.

Documentation

Overview

Package proxy 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

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var (
	RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "proxy",
		Name:      "requests_total",
		Help:      "Counter of requests made per upstream.",
	}, []string{"to"})
	RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "proxy",
		Name:      "responses_total",
		Help:      "Counter of responses received per upstream.",
	}, []string{"rcode", "to"})
	RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: plugin.Namespace,
		Subsystem: "proxy",
		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: "proxy",
		Name:      "healthcheck_failures_total",
		Help:      "Counter of the number of failed healthchecks.",
	}, []string{"to"})
	ConnCacheHitsCount = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: plugin.Namespace,
		Subsystem: "proxy",
		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: "proxy",
		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 HealthChecker

type HealthChecker interface {
	Check(*Proxy) error
	SetTLSConfig(*tls.Config)
	GetTLSConfig() *tls.Config
	SetRecursionDesired(bool)
	GetRecursionDesired() bool
	SetDomain(domain string)
	GetDomain() string
	SetTCPTransport()
	GetReadTimeout() time.Duration
	SetReadTimeout(time.Duration)
	GetWriteTimeout() time.Duration
	SetWriteTimeout(time.Duration)
}

HealthChecker checks the upstream health.

func NewHealthChecker

func NewHealthChecker(trans string, recursionDesired bool, domain string) HealthChecker

NewHealthChecker returns a new HealthChecker based on transport.

type Options

type Options struct {
	// ForceTCP use TCP protocol for upstream DNS request. Has precedence over PreferUDP flag
	ForceTCP bool
	// PreferUDP use UDP protocol for upstream DNS request.
	PreferUDP bool
	// HCRecursionDesired sets recursion desired flag for Proxy healthcheck requests
	HCRecursionDesired bool
	// HCDomain sets domain for Proxy healthcheck requests
	HCDomain string
}

Options holds various Options that can be set.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy defines an upstream host.

func NewProxy

func NewProxy(addr, trans string) *Proxy

NewProxy returns a new proxy.

func (*Proxy) Addr

func (p *Proxy) Addr() string

func (*Proxy) Connect

func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options) (*dns.Msg, error)

Connect selects an upstream, sends the request and waits for a response.

func (*Proxy) Down

func (p *Proxy) Down(maxfails uint32) bool

Down returns true if this proxy is down, i.e. has *more* fails than maxfails.

func (*Proxy) Fails

func (p *Proxy) Fails() uint32

func (*Proxy) GetHealthchecker

func (p *Proxy) GetHealthchecker() HealthChecker

func (*Proxy) Healthcheck

func (p *Proxy) Healthcheck()

Healthcheck kicks of a round of health checks for this proxy.

func (*Proxy) SetExpire

func (p *Proxy) SetExpire(expire time.Duration)

SetExpire sets the expire duration in the lower p.transport.

func (*Proxy) SetReadTimeout

func (p *Proxy) SetReadTimeout(duration time.Duration)

func (*Proxy) SetTLSConfig

func (p *Proxy) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in the lower p.transport and in the healthchecking client.

func (*Proxy) Start

func (p *Proxy) Start(duration time.Duration)

Start starts the proxy's healthchecking.

func (*Proxy) Stop

func (p *Proxy) Stop()

Stop close stops the health checking goroutine.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport hold the persistent cache.

func (*Transport) Dial

func (t *Transport) Dial(proto string) (*persistConn, bool, error)

Dial dials the address configured in transport, potentially reusing a connection or creating a new one.

func (*Transport) SetExpire

func (t *Transport) SetExpire(expire time.Duration)

SetExpire sets the connection expire time in transport.

func (*Transport) SetTLSConfig

func (t *Transport) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in transport.

func (*Transport) Start

func (t *Transport) Start()

Start starts the transport's connection manager.

func (*Transport) Stop

func (t *Transport) Stop()

Stop stops the transport's connection manager.

func (*Transport) Yield

func (t *Transport) Yield(pc *persistConn)

Yield returns the connection to transport for reuse.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL