Skip to content

Commit

Permalink
Merge pull request #63 from glebkin/main
Browse files Browse the repository at this point in the history
Add server-count support with random selection algorithm
  • Loading branch information
denis-tingaikin authored Sep 3, 2024
2 parents 3cd285d + 2794bd1 commit 402e0dc
Show file tree
Hide file tree
Showing 19 changed files with 846 additions and 2,183 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- run: |
go build -race ./...
test:
Expand All @@ -38,9 +38,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- name: Install gotestsum
run: go get gotest.tools/gotestsum@v0.4.0
run: go install gotest.tools/gotestsum@v0.4.0
- name: Run tests
run: |
eval $(go env)
Expand All @@ -50,7 +50,7 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.23.2
GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.59.1
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -68,7 +68,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- name: build coredns binary
run: |
go build -o coredns/coredns coredns/main.go
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- run: go mod tidy
- name: Check for changes in go.mod or go.sum
run: |
Expand All @@ -124,9 +124,9 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- name: Install go-header
run: 'go get github.com/denis-tingajkin/go-header@v0.2.2'
run: 'go install github.com/denis-tingajkin/go-header@v0.2.2'
- name: Run go-header
run: |
eval $(go env)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- name: "Build coredns binary"
run: |
go build -o coredns/coredns coredns/main.go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

- uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.21
- name: "Build coredns binary"
run: |
go build -o coredns/coredns coredns/main.go
Expand Down
56 changes: 8 additions & 48 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ linters-settings:
check-type-assertions: false
check-blank: false
govet:
check-shadowing: true
enable:
shadow
settings:
printf:
funcs:
- (github.com/sirupsen/logrus.FieldLogger).Infof
- (github.com/sirupsen/logrus.FieldLogger).Warnf
- (github.com/sirupsen/logrus.FieldLogger).Errorf
- (github.com/sirupsen/logrus.FieldLogger).Fatalf
golint:
min-confidence: 0.8
goimports:
local-prefixes: github.com/networkservicemesh/sdk
gocyclo:
Expand All @@ -31,13 +30,11 @@ linters-settings:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
include-go-root: false
packages:
- errors
packages-with-error-message:
# specify an error message to output when a blacklisted package is used
- errors: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports"
rules:
default:
deny:
- pkg: "errors"
desc: "Please use \"github.com/pkg/errors\" instead of \"errors\" in go imports"
misspell:
locale: US
unparam:
Expand All @@ -50,78 +47,45 @@ linters-settings:
for-loops: false
gocritic:
enabled-checks:
- appendAssign
- assignOp
- appendCombine
- argOrder
- badCall
- badCond
- boolExprSimplify
- builtinShadow
- captLocal
- caseOrder
- codegenComment
- commentFormatting
- commentedOutCode
- commentedOutImport
- defaultCaseOrder
- deprecatedComment
- docStub
- dupArg
- dupBranchBody
- dupCase
- dupImport
- dupSubExpr
- elseif
- emptyFallthrough
- emptyStringTest
- equalFold
- evalOrder
- exitAfterDefer
- flagDeref
- flagName
- hexLiteral
- hugeParam
- ifElseChain
- importShadow
- indexAlloc
- initClause
- methodExprCall
- nestingReduce
- newDeref
- nilValReturn
- octalLiteral
- offBy1
- paramTypeCombine
- ptrToRefParam
- rangeExprCopy
- rangeValCopy
- regexpMust
- regexpPattern
- singleCaseSwitch
- sloppyLen
- sloppyReassign
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- typeUnparen
- unlabelStmt
- unnamedResult
- unnecessaryBlock
- underef
- unlambda
- unslice
- valSwap
- weakCond
- wrapperFunc
- yodaStyleExpr
linters:
disable-all: true
enable:
# - rowserrcheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -133,24 +97,20 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- revive
- gosec
- gosimple
- govet
- ineffassign
- interfacer
# - lll
- misspell
- nakedret
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
issues:
exclude-use-default: false
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Each incoming DNS query that hits the CoreDNS fanout plugin will be replicated i
(Cloudflare) will not work.

* `worker-count` is the number of parallel queries per request. By default equals to count of IP list. Use this only for reducing parallel queries per request.
* `policy` - specifies the policy of DNS server selection mechanism. The default is `sequential`.
* `sequential` - select DNS servers one-by-one based on its order
* `weighted-random` - select DNS servers randomly based on `weighted-random-server-count` and `weighted-random-load-factor` params.
* `weighted-random-server-count` is the number of DNS servers to be requested. Equals to the number of specified IPs by default. Used only with the `weighted-random` policy.
* `weighted-random-load-factor` - the probability of selecting a server. This is specified in the order of the list of IP addresses and takes values between 1 and 100. By default, all servers have an equal probability of 100. Used only with the `weighted-random` policy.
* `network` is a specific network protocol. Could be `tcp`, `udp`, `tcp-tls`.
* `except` is a list is a space-separated list of domains to exclude from proxying.
* `except-file` is the path to file with line-separated list of domains to exclude from proxying.
Expand Down Expand Up @@ -110,3 +115,23 @@ If `race` is enable, we will get `NXDOMAIN` result quickly, otherwise we will ge
}
}
~~~

Sends parallel requests between two randomly selected resolvers. Note, that `127.0.0.1:9007` would be selected more frequently as it has the highest `weighted-random-load-factor`.
~~~ corefile
example.org {
fanout . 127.0.0.1:9005 127.0.0.1:9006 127.0.0.1:9007 {
policy weighted-random
weighted-random-server-count 2
weighted-random-load-factor 50 70 100
}
}
~~~

Sends parallel requests between three resolver sequentially (default mode).
~~~ corefile
example.org {
fanout . 127.0.0.1:9005 127.0.0.1:9006 127.0.0.1:9007 {
policy sequential
}
}
~~~
24 changes: 14 additions & 10 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ package fanout
import "time"

const (
maxIPCount = 100
maxWorkerCount = 32
minWorkerCount = 2
maxTimeout = 2 * time.Second
defaultTimeout = 30 * time.Second
readTimeout = 2 * time.Second
attemptDelay = time.Millisecond * 100
tcptls = "tcp-tls"
tcp = "tcp"
udp = "udp"
maxIPCount = 100
maxLoadFactor = 100
minLoadFactor = 1
policyWeightedRandom = "weighted-random"
policySequential = "sequential"
maxWorkerCount = 32
minWorkerCount = 2
maxTimeout = 2 * time.Second
defaultTimeout = 30 * time.Second
readTimeout = 2 * time.Second
attemptDelay = time.Millisecond * 100
tcptls = "tcp-tls"
tcp = "tcp"
udp = "udp"
)
45 changes: 26 additions & 19 deletions coredns/go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
module github.com/networkservicemesh/fanout/coredns

go 1.17
go 1.21

require (
github.com/coredns/coredns v1.9.1
github.com/coredns/coredns v1.11.3
github.com/networkservicemesh/fanout v0.0.0-20200313150119-ddef81d89163
)

require (
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coredns/caddy v1.1.1 // indirect
github.com/dnstap/golang-dnstap v0.4.0 // indirect
github.com/farsightsec/golang-framestream v0.3.0 // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.46 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.61 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c // indirect
google.golang.org/grpc v1.44.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/quic-go v0.42.0 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

replace github.com/networkservicemesh/fanout => ../
Loading

0 comments on commit 402e0dc

Please sign in to comment.