Documentation ¶
Index ¶
- Constants
- Variables
- func Close(c io.Closer)
- func HostPort(servers []string) ([]string, error)
- func PluginError(err error) error
- func SplitByByte(s string, c byte) (string, string)
- func SplitTransportHost(s string) (trans string, addr string)
- type Dnsredir
- type HealthCheck
- type NameItem
- type NameList
- type Once
- type Policy
- type Random
- type RoundRobin
- type Sequential
- type Spray
- type StringSet
- type Transport
- type Upstream
- type UpstreamHost
- func (uh *UpstreamHost) Check() error
- func (uh *UpstreamHost) Dial(proto string, bootstrap []string, noIPv6 bool) (*persistConn, bool, error)
- func (uh *UpstreamHost) Down() bool
- func (uh *UpstreamHost) Exchange(ctx context.Context, state *request.Request, bootstrap []string, noIPv6 bool) (*dns.Msg, error)
- func (uh *UpstreamHost) InitDOH(u *reloadableUpstream)
- func (uh *UpstreamHost) IsDOH() bool
- func (uh *UpstreamHost) Name() string
- type UpstreamHostDownFunc
- type UpstreamHostPool
Constants ¶
const ( NameItemTypePath = iota NameItemTypeUrl NameItemTypeLast // Dummy )
Variables ¶
var ( // This metric value mainly used for benchmarking purpose NameLookupDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "name_lookup_duration_ms", Buckets: nameLookupBuckets, Help: "Histogram of the time(in milliseconds) each name lookup took.", }, []string{"server", "matched"}) RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "request_duration_ms", Buckets: requestBuckets, Help: "Histogram of the time(in milliseconds) each request took.", }, []string{"server", "to"}) RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "request_count_total", Help: "Counter of requests made per upstream.", }, []string{"server", "to"}) RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "response_rcode_count_total", Help: "Rcode counter of requests made per upstream.", }, []string{"server", "to", "rcode"}) // XXX: currently server not embedded into hc failure count label HealthCheckFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "hc_failure_count_total", Help: "Counter of the number of failed healthchecks.", }, []string{"to"}) /// XXX: Ditto. HealthCheckAllDownCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: pluginName, Name: "hc_all_down_count_total", Help: "Counter of the number of complete failures of the healthchecks.", }, []string{"to"}) )
var SupportedPolicies = map[string]Policy{ "random": &Random{}, "round_robin": &RoundRobin{}, "sequential": &Sequential{}, "spray": &Spray{}, }
SupportedPolicies is the collection of policies registered
Functions ¶
func Close ¶
see: https://blevesearch.com/news/Deferred-Cleanup,-Checking-Errors,-and-Potential-Problems/
func PluginError ¶
func SplitByByte ¶
Return two strings delimited by the `c', the second one will including `c' as beginning character If `c' not found in `s', the second string will be empty
func SplitTransportHost ¶
Types ¶
type Dnsredir ¶
func (*Dnsredir) OnShutdown ¶
type HealthCheck ¶
type HealthCheck struct {
// contains filtered or unexported fields
}
func (*HealthCheck) Select ¶
func (hc *HealthCheck) Select() *UpstreamHost
Select an upstream host based on the policy and the health check result Taken from proxy/healthcheck/healthcheck.go with modification
func (*HealthCheck) Start ¶
func (hc *HealthCheck) Start()
func (*HealthCheck) Stop ¶
func (hc *HealthCheck) Stop()
type NameItem ¶
func NewNameItemsWithForms ¶
type Policy ¶
type Policy interface { // nil will be selected if all hosts are down // NOTE: Spray policy will always return a nonnull host Select(pool UpstreamHostPool) *UpstreamHost }
Policy decides how a host will be selected from a pool. When all hosts are unhealthy, it is assumed the health checking failed. In this case each policy will *randomly* return a host from the pool
to prevent no traffic to go through at all.
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 UpstreamHostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
RoundRobin is a policy that selects hosts based on round robin ordering.
func (*RoundRobin) Select ¶
func (r *RoundRobin) Select(pool UpstreamHostPool) *UpstreamHost
Select selects an up host from the pool using a round robin ordering scheme.
func (*RoundRobin) String ¶
func (r *RoundRobin) String() string
type Sequential ¶
type Sequential struct{}
Sequential is a policy that selects always the first healthy host in the list order.
func (*Sequential) Select ¶
func (s *Sequential) Select(pool UpstreamHostPool) *UpstreamHost
Select always the first that is not Down, nil if all hosts are down
func (*Sequential) String ¶
func (s *Sequential) String() string
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 (s *Spray) Select(pool UpstreamHostPool) *UpstreamHost
Select selects an up host at random from the specified pool.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport settings Inspired from coredns/plugin/forward/persistent.go addr isn't sealed into this struct since it's a high-level item
type Upstream ¶
type Upstream interface { // Check if given domain name should be routed to this upstream zone Match(state *request.Request) bool // Select an upstream host to be routed to, nil if no available host Select() *UpstreamHost Start() error Stop() error }
Upstream manages a pool of proxy upstream hosts see: github.com/coredns/proxy#proxy.go
func NewReloadableUpstreams ¶
func NewReloadableUpstreams(c *caddy.Controller) ([]Upstream, error)
Parses Caddy config input and return a list of reloadable upstream for this plugin
type UpstreamHost ¶
type UpstreamHost struct {
// contains filtered or unexported fields
}
UpstreamHost represents a single upstream DNS server
func (*UpstreamHost) Check ¶
func (uh *UpstreamHost) Check() error
For health check we send to . IN NS +norec message to the upstream. Dial timeouts and empty replies are considered fails
basically anything else constitutes a healthy upstream.
func (*UpstreamHost) Dial ¶
func (uh *UpstreamHost) Dial(proto string, bootstrap []string, noIPv6 bool) (*persistConn, bool, error)
Return:
#0 Persistent connection #1 true if it's a cached connection #2 error(if any)
func (*UpstreamHost) Down ¶
func (uh *UpstreamHost) Down() bool
Down checks whether the upstream host is down or not Down will try to use uh.downFunc first, and will fallback
to some default criteria if necessary.
func (*UpstreamHost) InitDOH ¶
func (uh *UpstreamHost) InitDOH(u *reloadableUpstream)
func (*UpstreamHost) IsDOH ¶
func (uh *UpstreamHost) IsDOH() bool
func (*UpstreamHost) Name ¶
func (uh *UpstreamHost) Name() string
type UpstreamHostDownFunc ¶
type UpstreamHostDownFunc func(*UpstreamHost) bool
UpstreamHostDownFunc can be used to customize how Down behaves see: proxy/healthcheck/healthcheck.go
type UpstreamHostPool ¶
type UpstreamHostPool []*UpstreamHost
UpstreamHostPool is an array of upstream DNS servers