Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Configurable service TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pivotal committed Dec 13, 2017
1 parent 4c07cc3 commit 5687ca2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions jobs/consul_agent/spec
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ properties:
description: "Timeout used by Consul when recursively querying an upstream DNS server."
default: "5s"

consul.agent.dns_config.service_ttl:
description: "TTL for service DNS"
default: "0s"

consul.agent.domain:
description: "Domain suffix for DNS"

Expand Down
4 changes: 4 additions & 0 deletions jobs/consul_agent_windows/spec
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ properties:
description: "When allow_stale is specified, this is used to limit how stale results are allowed to be."
default: "5s"

consul.agent.dns_config.service_ttl:
description: "TTL for service DNS"
default: "0s"

consul.agent.domain:
description: "Domain suffix for DNS"

Expand Down
4 changes: 4 additions & 0 deletions src/confab/chaperon/config_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ = Describe("ConfigWriter", func() {
cfg = config.Config{}
cfg.Consul.Agent.DnsConfig.MaxStale = "5s"
cfg.Consul.Agent.DnsConfig.RecursorTimeout = "5s"
cfg.Consul.Agent.DnsConfig.ServiceTTL = "5s"
cfg.Node = config.ConfigNode{Name: "node", Index: 0}
cfg.Path.ConsulConfigDir = configDir
cfg.Path.DataDir = dataDir
Expand Down Expand Up @@ -78,6 +79,9 @@ var _ = Describe("ConfigWriter", func() {
"allow_stale": false,
"max_stale": "5s",
"recursor_timeout": "5s",
"service_ttl": map[string]interface{}{
"*": "5s",
},
},
"ports": map[string]int{
"dns": 53,
Expand Down
3 changes: 3 additions & 0 deletions src/confab/confab/confab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ var _ = Describe("confab", func() {
"allow_stale": true,
"max_stale": "30s",
"recursor_timeout": "5s",
"service_ttl": map[string]interface{}{
"*": "0s",
},
},
"ports": map[string]int{
"dns": 53,
Expand Down
2 changes: 2 additions & 0 deletions src/confab/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ConfigConsulAgentDnsConfig struct {
AllowStale bool `json:"allow_stale"`
MaxStale string `json:"max_stale"`
RecursorTimeout string `json:"recursor_timeout"`
ServiceTTL string `json:"service_ttl"`
}

type ConfigConsulTelemetry struct {
Expand All @@ -84,6 +85,7 @@ func defaultConfig() Config {
AllowStale: true,
MaxStale: "30s",
RecursorTimeout: "5s",
ServiceTTL: "0s",
},
Servers: ConfigConsulAgentServers{
LAN: []string{},
Expand Down
8 changes: 6 additions & 2 deletions src/confab/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ var _ = Describe("Config", func() {
"dns_config": {
"allow_stale": true,
"max_stale": "15s",
"recursor_timeout": "15s"
"recursor_timeout": "15s",
"service_ttl": "0s"
},
"require_ssl": true
},
Expand Down Expand Up @@ -97,6 +98,7 @@ var _ = Describe("Config", func() {
AllowStale: true,
MaxStale: "15s",
RecursorTimeout: "15s",
ServiceTTL: "0s",
},
RequireSSL: true,
},
Expand Down Expand Up @@ -139,6 +141,7 @@ var _ = Describe("Config", func() {
AllowStale: true,
MaxStale: "30s",
RecursorTimeout: "5s",
ServiceTTL: "0s",
},
},
},
Expand All @@ -160,7 +163,7 @@ var _ = Describe("Config", func() {
"lan": ["server1", "server2", "server3"],
"wan": ["wan-server1", "wan-server2", "wan-server3"]
},
"dns_config": { "allow_stale": true, "max_stale": "15s", "recursor_timeout": "15s" }
"dns_config": { "allow_stale": true, "max_stale": "15s", "recursor_timeout": "15s", "service_ttl": "10s" }
},
"encrypt_keys": ["key-1", "key-2"]
}
Expand Down Expand Up @@ -191,6 +194,7 @@ var _ = Describe("Config", func() {
AllowStale: true,
MaxStale: "15s",
RecursorTimeout: "15s",
ServiceTTL: "10s",
},
Services: map[string]config.ServiceDefinition{
"myservice": {
Expand Down
14 changes: 11 additions & 3 deletions src/confab/config/consul_config_definer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ type ConsulConfigPorts struct {
}

type ConsulConfigDnsConfig struct {
AllowStale bool `json:"allow_stale"`
MaxStale string `json:"max_stale"`
RecursorTimeout string `json:"recursor_timeout"`
AllowStale bool `json:"allow_stale"`
MaxStale string `json:"max_stale"`
RecursorTimeout string `json:"recursor_timeout"`
ServiceTTL ConsulConfigServiceTTL `json:"service_ttl"`
}

type ConsulConfigServiceTTL struct {
AllServices string `json:"*"`
}

type ConsulConfigPerformance struct {
Expand Down Expand Up @@ -92,6 +97,9 @@ func GenerateConfiguration(config Config, configDir, nodeName string) ConsulConf
AllowStale: config.Consul.Agent.DnsConfig.AllowStale,
MaxStale: config.Consul.Agent.DnsConfig.MaxStale,
RecursorTimeout: config.Consul.Agent.DnsConfig.RecursorTimeout,
ServiceTTL: ConsulConfigServiceTTL{
AllServices: config.Consul.Agent.DnsConfig.ServiceTTL,
},
},
Performance: ConsulConfigPerformance{
RaftMultiplier: 1,
Expand Down
17 changes: 17 additions & 0 deletions src/confab/config/consul_config_definer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ var _ = Describe("ConsulConfigDefiner", func() {
})
})
})

Describe("service_ttl", func() {
Context("when the `consul.agent.dns_config.service_ttl` property is set", func() {
It("uses that value", func() {
consulConfig = config.GenerateConfiguration(config.Config{
Consul: config.ConfigConsul{
Agent: config.ConfigConsulAgent{
DnsConfig: config.ConfigConsulAgentDnsConfig{
ServiceTTL: "15s",
},
},
},
}, configDir, "")
Expect(consulConfig.DnsConfig.ServiceTTL.AllServices).To(Equal("15s"))
})
})
})
})

Describe("log_level", func() {
Expand Down

0 comments on commit 5687ca2

Please sign in to comment.