Skip to content

Commit

Permalink
fix: dnscache to re-use failed DNS lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Jul 8, 2023
1 parent c4fd068 commit b05668e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ require (
github.com/gdamore/tcell/v2 v2.6.0
github.com/gorilla/mux v1.8.0
github.com/minio/cli v1.24.2
github.com/minio/dnscache v0.1.1
github.com/minio/pkg v1.6.5
github.com/prometheus/client_golang v1.15.0
github.com/rivo/tview v0.0.0-20230406072732-e22ce9588bb4
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417
github.com/sirupsen/logrus v1.9.0
go.uber.org/atomic v1.10.0
golang.org/x/sys v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/minio/cli v1.24.2 h1:J+fCUh9mhPLjN3Lj/YhklXvxj8mnyE/D6FpFduXJ2jg=
github.com/minio/cli v1.24.2/go.mod h1:bYxnK0uS629N3Bq+AOZZ+6lwF77Sodk4+UL9vNuXhOY=
github.com/minio/dnscache v0.1.1 h1:AMYLqomzskpORiUA1ciN9k7bZT1oB3YZN4cEIi88W5o=
github.com/minio/dnscache v0.1.1/go.mod h1:WCumm6offO4rQ/82oTCSoHnlhTmc81+vXgKpBtSYRbg=
github.com/minio/madmin-go/v2 v2.0.19 h1:XznxdMVCTyr0A88JrZFhdxWY8KLfJcrs0TTmFiE9cc8=
github.com/minio/madmin-go/v2 v2.0.19/go.mod h1:8bL1RMNkblIENFSgGYjeHrzUx9PxROb7OqfNuMU9ivE=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
Expand Down Expand Up @@ -86,8 +88,6 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 h1:Lt9DzQALzHoDwMBGJ6v8ObDPR0dzr2a6sXTB1Fq7IHs=
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/secure-io/sio-go v0.3.1 h1:dNvY9awjabXTYGsTF1PiCySl9Ltofk9GA3VdWlo7rRc=
Expand Down
36 changes: 17 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 MinIO, Inc.
// Copyright (c) 2021-2023 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -40,7 +40,7 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/rs/dnscache"
"github.com/minio/dnscache"
"github.com/sirupsen/logrus"
"golang.org/x/term"

Expand Down Expand Up @@ -82,22 +82,6 @@ var dnsCache = &dnscache.Resolver{
func init() {
// Create a new instance of the logger. You can have any number of instances.
log2 = logrus.New()

options := dnscache.ResolverRefreshOptions{
ClearUnused: true,
PersistOnFailure: false,
}

// Call to refresh will refresh names in cache. If you pass true, it will also
// remove cached names not looked up since the last call to Refresh. It is a good idea
// to call this method on a regular interval.
go func() {
t := time.NewTicker(30 * time.Second)
defer t.Stop()
for range t.C {
dnsCache.RefreshWithOptions(options)
}
}()
}

func logMsg(msg logMessage) error {
Expand Down Expand Up @@ -809,6 +793,15 @@ func sidekickMain(ctx *cli.Context) {
globalConsoleDisplay = globalLoggingEnabled || ctx.IsSet("trace") || !term.IsTerminal(int(os.Stdout.Fd()))
globalDebugEnabled = ctx.GlobalBool("debug")

go func() {
t := time.NewTicker(ctx.GlobalDuration("dns-ttl"))
defer t.Stop()

for range t.C {
dnsCache.Refresh()
}
}()

if !strings.HasPrefix(healthCheckPath, slashSeparator) {
healthCheckPath = slashSeparator + healthCheckPath
}
Expand Down Expand Up @@ -875,7 +868,7 @@ func main() {
app.Description = `High-Performance sidecar load-balancer`
app.UsageText = "[FLAGS] SITE1 [SITE2..]"
app.Version = version
app.Copyright = "(c) 2020-2021 MinIO, Inc."
app.Copyright = "(c) 2020-2023 MinIO, Inc."
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "address, a",
Expand Down Expand Up @@ -948,6 +941,11 @@ func main() {
Name: "pprof",
Usage: "start and listen for profiling on the specified address (e.g. `:1337`)",
},
cli.DurationFlag{
Name: "dns-ttl",
Usage: "choose custom DNS TTL value for DNS refreshes for load balanced endpoints",
Value: 10 * time.Minute,
},
}
app.CustomAppHelpTemplate = `NAME:
{{.Name}} - {{.Description}}
Expand Down

0 comments on commit b05668e

Please sign in to comment.