agent: Adding address configurations

This commit is contained in:
Armon Dadgar 2014-09-02 12:42:14 -07:00
parent 98acc0a908
commit cc728a1345
2 changed files with 43 additions and 0 deletions

View File

@ -29,6 +29,15 @@ type PortConfig struct {
Server int // Server internal RPC
}
// AddressConfig is used to provide address overrides
// for specific services. By default, either ClientAddress
// or ServerAddress is used.
type AddressConfig struct {
DNS string // DNS Query interface
HTTP string // HTTP API
RPC string // CLI RPC
}
// DNSConfig is used to fine tune the DNS sub-system.
// It can be used to control cache values, and stale
// reads
@ -117,6 +126,9 @@ type Config struct {
// Port configurations
Ports PortConfig
// Address configurations
Addresses AddressConfig
// LeaveOnTerm controls if Serf does a graceful leave when receiving
// the TERM signal. Defaults false. This can be changed on reload.
LeaveOnTerm bool `mapstructure:"leave_on_terminate"`
@ -627,6 +639,15 @@ func MergeConfig(a, b *Config) *Config {
if b.Ports.Server != 0 {
result.Ports.Server = b.Ports.Server
}
if b.Addresses.DNS != "" {
result.Addresses.DNS = b.Addresses.DNS
}
if b.Addresses.HTTP != "" {
result.Addresses.HTTP = b.Addresses.HTTP
}
if b.Addresses.RPC != "" {
result.Addresses.RPC = b.Addresses.RPC
}
if b.UiDir != "" {
result.UiDir = b.UiDir
}

View File

@ -430,6 +430,23 @@ func TestDecodeConfig(t *testing.T) {
if config.StatsdAddr != "127.0.0.1:7251" {
t.Fatalf("bad: %#v", config)
}
// Address overrides
input = `{"addresses": {"dns": "0.0.0.0", "http": "127.0.0.1", "rpc": "127.0.0.1"}}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
}
if config.Addresses.DNS != "0.0.0.0" {
t.Fatalf("bad: %#v", config)
}
if config.Addresses.HTTP != "127.0.0.1" {
t.Fatalf("bad: %#v", config)
}
if config.Addresses.RPC != "127.0.0.1" {
t.Fatalf("bad: %#v", config)
}
}
func TestDecodeConfig_Service(t *testing.T) {
@ -560,6 +577,11 @@ func TestMergeConfig(t *testing.T) {
SerfWan: 5,
Server: 6,
},
Addresses: AddressConfig{
DNS: "127.0.0.1",
HTTP: "127.0.0.2",
RPC: "127.0.0.3",
},
Server: true,
LeaveOnTerm: true,
SkipLeaveOnInt: true,