441a6c9969
This change adds a new `dns_config.recursor_strategy` option which controls how Consul queries DNS resolvers listed in the `recursors` config option. The supported options are `sequential` (default), and `random`. Closes #8807 Co-authored-by: Blake Covarrubias <blake@covarrubi.as> Co-authored-by: Priyanka Sengupta <psengupta@flatiron.com>
35 lines
681 B
Go
35 lines
681 B
Go
package dns
|
|
|
|
import (
|
|
"math/rand"
|
|
"regexp"
|
|
)
|
|
|
|
// MaxLabelLength is the maximum length for a name that can be used in DNS.
|
|
const MaxLabelLength = 63
|
|
|
|
// InvalidNameRe is a regex that matches characters which can not be included in
|
|
// a DNS name.
|
|
var InvalidNameRe = regexp.MustCompile(`[^A-Za-z0-9\\-]+`)
|
|
|
|
type RecursorStrategy string
|
|
|
|
const (
|
|
RecursorStrategySequential RecursorStrategy = "sequential"
|
|
RecursorStrategyRandom RecursorStrategy = "random"
|
|
)
|
|
|
|
func (s RecursorStrategy) Indexes(max int) []int {
|
|
switch s {
|
|
case RecursorStrategyRandom:
|
|
return rand.Perm(max)
|
|
default:
|
|
idxs := make([]int, max)
|
|
for i := range idxs {
|
|
idxs[i] = i
|
|
}
|
|
return idxs
|
|
|
|
}
|
|
}
|