Skip to content

Commit

Permalink
Merge pull request #48 from zzhuang94/main
Browse files Browse the repository at this point in the history
race policy
  • Loading branch information
denis-tingaikin authored Jan 20, 2023
2 parents cbad194 + af13dea commit ebe17d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit ebe17d8

Please sign in to comment.