Skip to content

Commit

Permalink
Merge pull request #25 from duedil-ltd/feature/default-ttl
Browse files Browse the repository at this point in the history
Implement a default TTL on all records (5 mins)
  • Loading branch information
tarnfeld committed Aug 11, 2014
2 parents 044150b + a73e127 commit 7207b66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
MetricsDuration int `short:"m" long:"metrics" description:"Dump metrics to stderr every N seconds" default:"30"`
GraphiteServer string `long:"graphite" description:"Graphite server to send metrics to"`
GraphiteDuration int `long:"graphite-duration" description:"Duration to periodically send metrics to the graphite server" default:"10"`
DefaultTtl uint32 `short:"t" long:"default-ttl" description:"Default TTL to return on records without an explicit TTL" default:"300"`
}
)

Expand Down Expand Up @@ -81,7 +82,8 @@ func main() {
port: Options.ListenPort,
etcd: etcd,
rTimeout: time.Duration(5) * time.Second,
wTimeout: time.Duration(5) * time.Second}
wTimeout: time.Duration(5) * time.Second,
defaultTtl: Options.DefaultTtl}

server.Run()

Expand Down
7 changes: 4 additions & 3 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
type Resolver struct {
etcd *etcd.Client
etcdPrefix string
defaultTtl uint32
}

type EtcdRecord struct {
Expand Down Expand Up @@ -62,14 +63,14 @@ func (r *Resolver) GetFromStorage(key string) (nodes []*EtcdRecord, err error) {
}
} else {
if lastValNode != nil {
findKeys(lastValNode, 0, false)
findKeys(lastValNode, r.defaultTtl, false)
}
lastValNode = node
}
}

if lastValNode != nil {
findKeys(lastValNode, 0, false)
findKeys(lastValNode, r.defaultTtl, false)
}
} else {
// If for some reason this is passed a ttl node unexpectedly, bail
Expand Down Expand Up @@ -98,7 +99,7 @@ func (r *Resolver) GetFromStorage(key string) (nodes []*EtcdRecord, err error) {
}
}

findKeys(response.Node, 0, true)
findKeys(response.Node, r.defaultTtl, true)

return
}
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Server struct {
etcd *etcd.Client
rTimeout time.Duration
wTimeout time.Duration
defaultTtl uint32
}

type Handler struct {
Expand Down Expand Up @@ -59,7 +60,7 @@ func (s *Server) Run() {
udp_request_counter := metrics.NewCounter()
metrics.Register("request.handler.udp.requests", udp_request_counter)

resolver := Resolver{etcd: s.etcd}
resolver := Resolver{etcd: s.etcd, defaultTtl: s.defaultTtl}
tcpDNShandler := &Handler{
resolver: &resolver,
request_counter: tcp_request_counter,
Expand Down

0 comments on commit 7207b66

Please sign in to comment.