Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

race policy #48

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Each incoming DNS query that hits the CoreDNS fanout plugin will be replicated i
* `except-file` is the path to file with line-separated list of domains to exclude from proxying.
* `attempt-count` is the number of attempts to connect to upstream servers that are needed before considering an upstream to be down. If 0, the upstream will never be marked as down and request will be finished by `timeout`. Default is `3`.
* `timeout` is the timeout of request. After this period, attempts to receive a response from the upstream servers will be stopped. Default is `30s`.
* `race` gives priority to the first result, whether it is negative or not, as long as it is a standard DNS result.
## Metrics

If monitoring is enabled (via the *prometheus* plugin) then the following metric are exported:
Expand Down Expand Up @@ -99,3 +100,13 @@ Sends parallel requests between five resolvers via UDP uses two workers and with
}
}
~~~

Multiple upstream servers are configured but one of them is down, query a `non-existent` domain.
If `race` is enable, we will get `NXDOMAIN` result quickly, otherwise we will get `"connection timed out"` result in a few seconds.
~~~ corefile
. {
fanout . 10.0.0.10:53 10.0.0.11:53 10.0.0.12:53 10.0.0.13:1053 10.0.0.14:1053 {
race
}
}
~~~
4 changes: 4 additions & 0 deletions fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Fanout struct {
excludeDomains Domain
tlsServerName string
timeout time.Duration
race bool
net string
from string
attempts int
Expand Down Expand Up @@ -141,6 +142,9 @@ func (f *Fanout) getFanoutResult(ctx context.Context, responseCh <-chan *respons
if r.err != nil {
break
}
if f.race {
return r
}
if r.response.Rcode != dns.RcodeSuccess {
break
}
Expand Down
10 changes: 10 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func parseValue(v string, f *Fanout, c *caddyfile.Dispenser) error {
return parseWorkerCount(f, c)
case "timeout":
return parseTimeout(f, c)
case "race":
return parseRace(f, c)
case "except":
return parseIgnored(f, c)
case "except-file":
Expand All @@ -184,6 +186,14 @@ func parseTimeout(f *Fanout, c *caddyfile.Dispenser) error {
return err
}

func parseRace(f *Fanout, c *caddyfile.Dispenser) error {
if c.NextArg() {
return c.ArgErr()
}
f.race = true
return nil
}

func parseIgnoredFromFile(f *Fanout, c *caddyfile.Dispenser) error {
args := c.RemainingArgs()
if len(args) != 1 {
Expand Down