Skip to content

Commit

Permalink
Merge pull request #726 from luraproject/config_dnsttl
Browse files Browse the repository at this point in the history
Add config option to tweak the DNS cache TTL
  • Loading branch information
kpacha authored Jul 10, 2024
2 parents be5c8bd + dc4f760 commit fb531bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
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

0 comments on commit fb531bf

Please sign in to comment.