Merge pull request #943 from inercia/weave-941

make negative TTL default to same value as TTL

Fixes #941.
This commit is contained in:
Matthias Radestock committed 2015-06-17 10:23:41 +01:00
commit cfe14ff568
4 files changed
+14 -15

No files matched your search

-2
View File
@@ -22,8 +22,6 @@ var (
)
const (
DefaultCacheNegLocalTTL = 30 // Default TTL for negative local resolutions
defPendingTimeout int = 5 // timeout for a resolution
)
+9 -9
View File
@@ -196,26 +196,26 @@ func TestCacheEntries(t *testing.T) {
question3 := &questionMsg3.Question[0]
t.Logf("Checking that a entry with CacheNoLocalReplies return an error")
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
resp, err = l.Get(questionMsg3, minUDPSize)
wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies")
wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies")
t.Logf("Checking that more Put's do not make the negative TTL longer")
clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second)
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second)
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
clk.Add(time.Duration(1) * time.Second)
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
clk.Add(time.Duration(1) * time.Second)
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
resp, err = l.Get(questionMsg3, minUDPSize)
wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies")
wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies")
clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second)
t.Logf("Checking that we get an expired response after %f seconds", DefaultCacheNegLocalTTL)
clk.Add(time.Second * time.Duration(DefaultCacheNegLocalTTL+1))
t.Logf("Checking that we get an expired response after %d seconds", DefaultCacheNegLocalTTL)
clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second)
t.Logf("Checking that we get an expired response after %f seconds", DefaultLocalTTL)
clk.Add(time.Second * time.Duration(DefaultLocalTTL+1))
t.Logf("Checking that we get an expired response after %d seconds", DefaultLocalTTL)
resp, err = l.Get(questionMsg3, minUDPSize)
wt.AssertNil(t, resp, "expired Get() response with CacheNoLocalReplies")
wt.AssertNil(t, err, "expired Get() error with CacheNoLocalReplies")
+3 -2
View File
@@ -45,7 +45,7 @@ type DNSServerConfig struct {
Cache ZoneCache
// (Optional) TTL for local domain responses
LocalTTL int
// (Optional) TTL for negative results in the local domain
// (Optional) TTL for negative results in the local domain (defaults to LocalTTL)
CacheNegLocalTTL int
// (Optional) for a specific clock provider
Clock clock.Clock
@@ -120,7 +120,6 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) {
cacheDisabled: false,
maxAnswers: DefaultMaxAnswers,
localTTL: DefaultLocalTTL,
negLocalTTL: DefaultCacheNegLocalTTL,
clock: config.Clock,
}
@@ -164,6 +163,8 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) {
}
if config.CacheNegLocalTTL > 0 {
s.negLocalTTL = config.CacheNegLocalTTL
} else {
s.negLocalTTL = s.localTTL
}
if config.CacheDisabled {
s.cacheDisabled = true
+2 -2
View File
@@ -5,13 +5,13 @@ import (
"fmt"
"net"
"os"
"strconv"
"github.com/miekg/dns"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
weavedns "github.com/weaveworks/weave/nameserver"
weavenet "github.com/weaveworks/weave/net"
"strconv"
)
var version = "(unreleased version)"
@@ -55,7 +55,7 @@ func main() {
flag.BoolVar(&watch, "watch", true, "watch the docker socket for container events")
flag.BoolVar(&debug, "debug", false, "output debugging info to stderr")
// advanced options
flag.IntVar(&negTTL, "neg-ttl", weavedns.DefaultCacheNegLocalTTL, "negative TTL (in secs) for unanswered queries for local names")
flag.IntVar(&negTTL, "neg-ttl", 0, "negative TTL (in secs) for unanswered queries for local names")
flag.IntVar(&refreshInterval, "refresh", weavedns.DefaultRefreshInterval, "refresh interval (in secs) for local names (0=disable)")
flag.IntVar(&maxAnswers, "max-answers", weavedns.DefaultMaxAnswers, "maximum number of answers returned to clients (0=unlimited)")
flag.IntVar(&relevantTime, "relevant", weavedns.DefaultRelevantTime, "life time for info in the absence of queries (in secs)")