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

Allow Nomads Consul health check names to be configurable. #4003

Merged
merged 2 commits into from
Mar 20, 2018
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
8 changes: 4 additions & 4 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (a *Agent) setupServer() error {
Tags: []string{consul.ServiceTagRPC},
Checks: []*structs.ServiceCheck{
{
Name: "Nomad Server RPC Check",
Name: a.config.Consul.ServerRPCCheckName,
Type: "tcp",
Interval: serverRpcCheckInterval,
Timeout: serverRpcCheckTimeout,
Expand All @@ -492,7 +492,7 @@ func (a *Agent) setupServer() error {
Tags: []string{consul.ServiceTagSerf},
Checks: []*structs.ServiceCheck{
{
Name: "Nomad Server Serf Check",
Name: a.config.Consul.ServerSerfCheckName,
Type: "tcp",
Interval: serverSerfCheckInterval,
Timeout: serverSerfCheckTimeout,
Expand Down Expand Up @@ -592,7 +592,7 @@ func (a *Agent) agentHTTPCheck(server bool) *structs.ServiceCheck {
httpCheckAddr = a.config.AdvertiseAddrs.HTTP
}
check := structs.ServiceCheck{
Name: "Nomad Client HTTP Check",
Name: a.config.Consul.ClientHTTPCheckName,
Type: "http",
Path: "/v1/agent/health?type=client",
Protocol: "http",
Expand All @@ -602,7 +602,7 @@ func (a *Agent) agentHTTPCheck(server bool) *structs.ServiceCheck {
}
// Switch to endpoint that doesn't require a leader for servers
if server {
check.Name = "Nomad Server HTTP Check"
check.Name = a.config.Consul.ServerHTTPCheckName
check.Path = "/v1/agent/health?type=server"
}
if !a.config.TLSConfig.EnableHTTP {
Expand Down
16 changes: 16 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ func (c *Command) readConfig() *Config {
return nil
}), "consul-client-auto-join", "")
flags.StringVar(&cmdConfig.Consul.ClientServiceName, "consul-client-service-name", "", "")
flags.StringVar(&cmdConfig.Consul.ClientHTTPCheckName, "consul-client-http-check-name", "", "")
flags.StringVar(&cmdConfig.Consul.KeyFile, "consul-key-file", "", "")
flags.StringVar(&cmdConfig.Consul.ServerServiceName, "consul-server-service-name", "", "")
flags.StringVar(&cmdConfig.Consul.ServerHTTPCheckName, "consul-server-http-check-name", "", "")
flags.StringVar(&cmdConfig.Consul.ServerSerfCheckName, "consul-server-serf-check-name", "", "")
flags.StringVar(&cmdConfig.Consul.ServerRPCCheckName, "consul-server-rpc-check-name", "", "")
flags.Var((flaghelper.FuncBoolVar)(func(b bool) error {
cmdConfig.Consul.ServerAutoJoin = &b
return nil
Expand Down Expand Up @@ -1027,13 +1031,25 @@ Consul Options:
-consul-client-service-name=<name>
Specifies the name of the service in Consul for the Nomad clients.
-consul-client-http-check-name=<name>
Specifies the HTTP health check name in Consul for the Nomad clients.
-consul-key-file=<path>
Specifies the path to the private key used for Consul communication. If this
is set then you need to also set cert_file.
-consul-server-service-name=<name>
Specifies the name of the service in Consul for the Nomad servers.
-consul-server-http-check-name=<name>
Specifies the HTTP health check name in Consul for the Nomad servers.
-consul-server-serf-check-name=<name>
Specifies the Serf health check name in Consul for the Nomad servers.
-consul-server-rpc-check-name=<name>
Specifies the RPC health check name in Consul for the Nomad servers.
-consul-server-auto-join
Specifies if the Nomad servers should automatically discover and join other
Nomad servers by searching for the Consul service name defined in the
Expand Down
4 changes: 4 additions & 0 deletions command/agent/config-test-fixtures/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ http_api_response_headers {
}
consul {
server_service_name = "nomad"
server_http_check_name = "nomad-server-http-health-check"
server_serf_check_name = "nomad-server-serf-health-check"
server_rpc_check_name = "nomad-server-rpc-health-check"
client_service_name = "nomad-client"
client_http_check_name = "nomad-client-http-health-check"
address = "127.0.0.1:9500"
token = "token1"
auth = "username:pass"
Expand Down
4 changes: 4 additions & 0 deletions command/agent/config_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,13 @@ func parseConsulConfig(result **config.ConsulConfig, list *ast.ObjectList) error
"checks_use_advertise",
"client_auto_join",
"client_service_name",
"client_http_check_name",
"key_file",
"server_auto_join",
"server_service_name",
"server_http_check_name",
"server_serf_check_name",
"server_rpc_check_name",
"ssl",
"timeout",
"token",
Expand Down
32 changes: 18 additions & 14 deletions command/agent/config_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,24 @@ func TestConfig_Parse(t *testing.T) {
DisableUpdateCheck: true,
DisableAnonymousSignature: true,
Consul: &config.ConsulConfig{
ServerServiceName: "nomad",
ClientServiceName: "nomad-client",
Addr: "127.0.0.1:9500",
Token: "token1",
Auth: "username:pass",
EnableSSL: &trueValue,
VerifySSL: &trueValue,
CAFile: "/path/to/ca/file",
CertFile: "/path/to/cert/file",
KeyFile: "/path/to/key/file",
ServerAutoJoin: &trueValue,
ClientAutoJoin: &trueValue,
AutoAdvertise: &trueValue,
ChecksUseAdvertise: &trueValue,
ServerServiceName: "nomad",
ServerHTTPCheckName: "nomad-server-http-health-check",
ServerSerfCheckName: "nomad-server-serf-health-check",
ServerRPCCheckName: "nomad-server-rpc-health-check",
ClientServiceName: "nomad-client",
ClientHTTPCheckName: "nomad-client-http-health-check",
Addr: "127.0.0.1:9500",
Token: "token1",
Auth: "username:pass",
EnableSSL: &trueValue,
VerifySSL: &trueValue,
CAFile: "/path/to/ca/file",
CertFile: "/path/to/cert/file",
KeyFile: "/path/to/key/file",
ServerAutoJoin: &trueValue,
ClientAutoJoin: &trueValue,
AutoAdvertise: &trueValue,
ChecksUseAdvertise: &trueValue,
},
Vault: &config.VaultConfig{
Addr: "127.0.0.1:9500",
Expand Down
50 changes: 41 additions & 9 deletions nomad/structs/config/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,26 @@ type ConsulConfig struct {
// servers with Consul
ServerServiceName string `mapstructure:"server_service_name"`

// ServerHTTPCheckName is the name of the health check that Nomad uses
// to register the server HTTP health check with Consul
ServerHTTPCheckName string `mapstructure:"server_http_check_name"`

// ServerSerfCheckName is the name of the health check that Nomad uses
// to register the server Serf health check with Consul
ServerSerfCheckName string `mapstructure:"server_serf_check_name"`

// ServerRPCCheckName is the name of the health check that Nomad uses
// to register the server RPC health check with Consul
ServerRPCCheckName string `mapstructure:"server_rpc_check_name"`

// ClientServiceName is the name of the service that Nomad uses to register
// clients with Consul
ClientServiceName string `mapstructure:"client_service_name"`

// ClientHTTPCheckName is the name of the health check that Nomad uses
// to register the client HTTP health check with Consul
ClientHTTPCheckName string `mapstructure:"client_http_check_name"`

// AutoAdvertise determines if this Nomad Agent will advertise its
// services via Consul. When true, Nomad Agent will register
// services with Consul.
Expand Down Expand Up @@ -78,15 +94,19 @@ type ConsulConfig struct {
// `consul` configuration.
func DefaultConsulConfig() *ConsulConfig {
return &ConsulConfig{
ServerServiceName: "nomad",
ClientServiceName: "nomad-client",
AutoAdvertise: helper.BoolToPtr(true),
ChecksUseAdvertise: helper.BoolToPtr(false),
EnableSSL: helper.BoolToPtr(false),
VerifySSL: helper.BoolToPtr(true),
ServerAutoJoin: helper.BoolToPtr(true),
ClientAutoJoin: helper.BoolToPtr(true),
Timeout: 5 * time.Second,
ServerServiceName: "nomad",
ServerHTTPCheckName: "Nomad Server HTTP Check",
ServerSerfCheckName: "Nomad Server Serf Check",
ServerRPCCheckName: "Nomad Server RPC Check",
ClientServiceName: "nomad-client",
ClientHTTPCheckName: "Nomad Client HTTP Check",
AutoAdvertise: helper.BoolToPtr(true),
ChecksUseAdvertise: helper.BoolToPtr(false),
EnableSSL: helper.BoolToPtr(false),
VerifySSL: helper.BoolToPtr(true),
ServerAutoJoin: helper.BoolToPtr(true),
ClientAutoJoin: helper.BoolToPtr(true),
Timeout: 5 * time.Second,
}
}

Expand All @@ -97,9 +117,21 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig {
if b.ServerServiceName != "" {
result.ServerServiceName = b.ServerServiceName
}
if b.ServerHTTPCheckName != "" {
result.ServerHTTPCheckName = b.ServerHTTPCheckName
}
if b.ServerSerfCheckName != "" {
result.ServerSerfCheckName = b.ServerSerfCheckName
}
if b.ServerRPCCheckName != "" {
result.ServerRPCCheckName = b.ServerRPCCheckName
}
if b.ClientServiceName != "" {
result.ClientServiceName = b.ClientServiceName
}
if b.ClientHTTPCheckName != "" {
result.ClientHTTPCheckName = b.ClientHTTPCheckName
}
if b.AutoAdvertise != nil {
result.AutoAdvertise = helper.BoolToPtr(*b.AutoAdvertise)
}
Expand Down