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

Add config option to tweak the DNS cache TTL #726

Merged
merged 1 commit into from
Jul 10, 2024
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
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ type ServiceConfig struct {
// ClientTLS is used to configure the http default transport
// with TLS parameters
ClientTLS *ClientTLS `mapstructure:"client_tls"`

// DNSCacheTTL is the duration of the cached data for the DNS lookups
DNSCacheTTL time.Duration `mapstructure:"dns_cache_ttl"`
}

// AsyncAgent defines the configuration of a single subscriber/consumer to be initialized
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestConfig_init(t *testing.T) {
t.Error(err.Error())
}

if hash != "dEnC/Sn/mHYtt5vj+DkI0Ib22D/1liL8zx/WHpT2ajY=" {
if hash != "mIfuGTgHS91DJtAE6KMVl2kcluxCzc9n3f6fi0YgWs8=" {
t.Errorf("unexpected hash: %s", hash)
}
}
Expand Down
2 changes: 2 additions & 0 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ type parseableServiceConfig struct {
TLS *parseableTLS `json:"tls,omitempty"`
ClientTLS *parseableClientTLS `json:"client_tls,omitempty"`
UseH2C bool `json:"use_h2c,omitempty"`
DNSCacheTTL string `json:"dns_cache_ttl"`
}

func (p *parseableServiceConfig) normalize() ServiceConfig {
Expand Down Expand Up @@ -197,6 +198,7 @@ func (p *parseableServiceConfig) normalize() ServiceConfig {
OutputEncoding: p.OutputEncoding,
Plugin: p.Plugin,
UseH2C: p.UseH2C,
DNSCacheTTL: parseDuration(p.DNSCacheTTL),
}
if p.TLS != nil {
cfg.TLS = &TLS{
Expand Down
13 changes: 12 additions & 1 deletion sd/dnssrv/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ import (

// Namespace is the key for the dns sd module
const Namespace = "dns"
const DefaultTTL = 30 * time.Second
const MinTTL = time.Second

// Register registers the dns sd subscriber factory under the name defined by Namespace
func Register() error {
return sd.GetRegister().Register(Namespace, SubscriberFactory)
}

// TTL is the duration of the cached data
var TTL = 30 * time.Second
var TTL = DefaultTTL

func SetTTL(d time.Duration) {
if d < MinTTL {
// in case the TTL is less than the minimum, we leave what is
// already set.
return
}
TTL = d
}

// DefaultLookup is the function used for the DNS resolution
var DefaultLookup = net.LookupSRV
Expand Down
Loading