Documentation ¶
Overview ¶
Package proxy is middleware that proxies requests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( RequestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Namespace: middleware.Namespace, Subsystem: "proxy", Name: "request_duration_milliseconds", Buckets: append(prometheus.DefBuckets, []float64{50, 100, 200, 500, 1000, 2000, 3000, 4000, 5000, 10000}...), Help: "Histogram of the time (in milliseconds) each request took.", }, []string{"proto", "proxy_proto", "from"}) )
Metrics the proxy middleware exports.
Functions ¶
func OnStartupMetrics ¶
func OnStartupMetrics() error
OnStartupMetrics sets up the metrics on startup. This is done for all proxy protocols.
func RegisterPolicy ¶
RegisterPolicy adds a custom policy to the proxy.
Types ¶
type Exchanger ¶
type Exchanger interface { Exchange(ctx context.Context, addr string, state request.Request) (*dns.Msg, error) Protocol() string OnStartup(*Proxy) error OnShutdown(*Proxy) error }
Exchanger is an interface that specifies a type implementing a DNS resolver that can use whatever transport it likes.
type LeastConn ¶
type LeastConn struct{}
LeastConn is a policy that selects the host with the least connections.
func (*LeastConn) Select ¶
func (r *LeastConn) Select(pool HostPool) *UpstreamHost
Select selects the up host with the least number of connections in the pool. If more than one host has the same least number of connections, one of the hosts is chosen at random.
type Policy ¶
type Policy interface {
Select(pool HostPool) *UpstreamHost
}
Policy decides how a host will be selected from a pool. When all hosts are unhealthy, it is assumed the healthchecking failed. In this case each policy will *randomly* return a host from the pool to prevent no traffic to go through at all.
type Proxy ¶
type Proxy struct { Next middleware.Handler Upstreams *[]Upstream // Trace is the Trace middleware, if it is installed // This is used by the grpc exchanger to trace through the grpc calls Trace middleware.Handler }
Proxy represents a middleware instance that can proxy requests to another (DNS) server.
func NewLookupWithOption ¶
NewLookupWithForcedProto process creates a simple round robin forward with potentially forced proto for upstream.
func (Proxy) Forward ¶
Forward forward the request in state as-is. Unlike Lookup that adds EDNS0 suffix to the message.
type Random ¶
type Random struct{}
Random is a policy that selects up hosts from a pool at random.
func (*Random) Select ¶
func (r *Random) Select(pool HostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type RoundRobin ¶
type RoundRobin struct {
Robin uint32
}
RoundRobin is a policy that selects hosts based on round robin ordering.
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(pool HostPool) *UpstreamHost
Select selects an up host from the pool using a round robin ordering scheme.
type Spray ¶
type Spray struct{}
Spray is a policy that selects a host from a pool at random. This should be used as a last ditch attempt to get a host when all hosts are reporting unhealthy.
func (*Spray) Select ¶
func (r *Spray) Select(pool HostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type Upstream ¶
type Upstream interface { // The domain name this upstream host should be routed on. From() string // Selects an upstream host to be routed to. Select() *UpstreamHost // Checks if subpdomain is not an ignored. IsAllowedDomain(string) bool // Exchanger returns the exchanger to be used for this upstream. Exchanger() Exchanger // Stops the upstream from proxying requests to shutdown goroutines cleanly. Stop() error }
Upstream manages a pool of proxy upstream hosts. Select should return a suitable upstream host, or nil if no such hosts are available.
type UpstreamHost ¶
type UpstreamHost struct { Conns int64 // must be first field to be 64-bit aligned on 32-bit systems Name string // IP address (and port) of this upstream host Fails int32 FailTimeout time.Duration Unhealthy bool CheckDown UpstreamHostDownFunc WithoutPathPrefix string // contains filtered or unexported fields }
UpstreamHost represents a single proxy upstream
func (*UpstreamHost) Down ¶
func (uh *UpstreamHost) Down() bool
Down checks whether the upstream host is down or not. Down will try to use uh.CheckDown first, and will fall back to some default criteria if necessary.
type UpstreamHostDownFunc ¶
type UpstreamHostDownFunc func(*UpstreamHost) bool
UpstreamHostDownFunc can be used to customize how Down behaves.