Skip to content

Commit

Permalink
Add DeregisterCriticalServiceAfter to Consul checks
Browse files Browse the repository at this point in the history
Consul can automatically deregister services if the health check is
critical for a given amount of time. This is useful if fabio exits
abnormally without deregistering services.
  • Loading branch information
rileyje committed Feb 7, 2018
1 parent dc1cd89 commit 9ece33a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 32 deletions.
31 changes: 16 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ type File struct {
}

type Consul struct {
Addr string
Scheme string
Token string
KVPath string
NoRouteHTMLPath string
TagPrefix string
Register bool
ServiceAddr string
ServiceName string
ServiceTags []string
ServiceStatus []string
CheckInterval time.Duration
CheckTimeout time.Duration
CheckScheme string
CheckTLSSkipVerify bool
Addr string
Scheme string
Token string
KVPath string
NoRouteHTMLPath string
TagPrefix string
Register bool
ServiceAddr string
ServiceName string
ServiceTags []string
ServiceStatus []string
CheckInterval time.Duration
CheckTimeout time.Duration
CheckScheme string
CheckTLSSkipVerify bool
CheckDeregisterCriticalServiceAfter string
}
25 changes: 13 additions & 12 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ var defaultConfig = &Config{
Registry: Registry{
Backend: "consul",
Consul: Consul{
Addr: "localhost:8500",
Scheme: "http",
KVPath: "/fabio/config",
NoRouteHTMLPath: "/fabio/noroute.html",
TagPrefix: "urlprefix-",
Register: true,
ServiceAddr: ":9998",
ServiceName: "fabio",
ServiceStatus: []string{"passing"},
CheckInterval: time.Second,
CheckTimeout: 3 * time.Second,
CheckScheme: "http",
Addr: "localhost:8500",
Scheme: "http",
KVPath: "/fabio/config",
NoRouteHTMLPath: "/fabio/noroute.html",
TagPrefix: "urlprefix-",
Register: true,
ServiceAddr: ":9998",
ServiceName: "fabio",
ServiceStatus: []string{"passing"},
CheckInterval: time.Second,
CheckTimeout: 3 * time.Second,
CheckScheme: "http",
CheckDeregisterCriticalServiceAfter: "90m",
},
Timeout: 10 * time.Second,
Retry: 500 * time.Millisecond,
Expand Down
3 changes: 2 additions & 1 deletion config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringSliceVar(&cfg.Registry.Consul.ServiceStatus, "registry.consul.service.status", defaultConfig.Registry.Consul.ServiceStatus, "valid service status values")
f.DurationVar(&cfg.Registry.Consul.CheckInterval, "registry.consul.register.checkInterval", defaultConfig.Registry.Consul.CheckInterval, "service check interval")
f.DurationVar(&cfg.Registry.Consul.CheckTimeout, "registry.consul.register.checkTimeout", defaultConfig.Registry.Consul.CheckTimeout, "service check timeout")
f.BoolVar(&cfg.Registry.Consul.CheckTLSSkipVerify, "registry.consul.register.checkTLSSkipVerify", defaultConfig.Registry.Consul.CheckTLSSkipVerify, "service check TLS verifcation")
f.BoolVar(&cfg.Registry.Consul.CheckTLSSkipVerify, "registry.consul.register.checkTLSSkipVerify", defaultConfig.Registry.Consul.CheckTLSSkipVerify, "service check TLS verification")
f.StringVar(&cfg.Registry.Consul.CheckDeregisterCriticalServiceAfter, "registry.consul.register.checkDeregisterCriticalServiceAfter", defaultConfig.Registry.Consul.CheckDeregisterCriticalServiceAfter, "critical service deregistration timeout")
f.IntVar(&cfg.Runtime.GOGC, "runtime.gogc", defaultConfig.Runtime.GOGC, "sets runtime.GOGC")
f.IntVar(&cfg.Runtime.GOMAXPROCS, "runtime.gomaxprocs", defaultConfig.Runtime.GOMAXPROCS, "sets runtime.GOMAXPROCS")
f.StringVar(&cfg.UI.Access, "ui.access", defaultConfig.UI.Access, "access mode, one of [ro, rw]")
Expand Down
13 changes: 13 additions & 0 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,19 @@
# registry.consul.register.checkTLSSkipVerify = false


# registry.consul.register.checkDeregisterCriticalServiceAfter configures
# automatic deregistration of a service after the health check is critical for
# this length of time.
#
# Fabio registers an http health check on http(s)://${ui.addr}/health
# and this value tells consul to deregister the associated service if the check
# is critical for the specified duration.
#
# The default is
#
# registry.consul.register.checkDeregisterCriticalServiceAfter = 90m


# metrics.target configures the backend the metrics values are
# sent to.
#
Expand Down
9 changes: 5 additions & 4 deletions registry/consul/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ func serviceRegistration(cfg *config.Consul, serviceName string) (*api.AgentServ
Port: port,
Tags: cfg.ServiceTags,
Check: &api.AgentServiceCheck{
HTTP: checkURL,
Interval: cfg.CheckInterval.String(),
Timeout: cfg.CheckTimeout.String(),
TLSSkipVerify: cfg.CheckTLSSkipVerify,
HTTP: checkURL,
Interval: cfg.CheckInterval.String(),
Timeout: cfg.CheckTimeout.String(),
TLSSkipVerify: cfg.CheckTLSSkipVerify,
DeregisterCriticalServiceAfter: cfg.CheckDeregisterCriticalServiceAfter,
},
}

Expand Down

0 comments on commit 9ece33a

Please sign in to comment.