From dd41a77c8b2639784efd33650de0046c09f9f890 Mon Sep 17 00:00:00 2001 From: Neng Date: Mon, 10 Sep 2018 16:38:51 +0800 Subject: [PATCH] Add Consul gRPC check support --- consul/consul.go | 13 ++++++++++++- docs/user/backends.md | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/consul/consul.go b/consul/consul.go index 0348c9a06..5f31cc077 100644 --- a/consul/consul.go +++ b/consul/consul.go @@ -115,10 +115,21 @@ func (r *ConsulAdapter) buildCheck(service *bridge.Service) *consulapi.AgentServ if timeout := service.Attrs["check_timeout"]; timeout != "" { check.Timeout = timeout } + } else if grpc := service.Attrs["check_grpc"]; grpc != "" { + check.GRPC = fmt.Sprintf("%s:%d", service.IP, service.Port) + if timeout := service.Attrs["check_timeout"]; timeout != "" { + check.Timeout = timeout + } + if useTLS := service.Attrs["check_grpc_use_tls"]; useTLS != "" { + check.GRPCUseTLS = true + if tlsSkipVerify := service.Attrs["check_tls_skip_verify"]; tlsSkipVerify != "" { + check.TLSSkipVerify = true + } + } } else { return nil } - if check.Script != "" || check.HTTP != "" || check.TCP != "" { + if check.Script != "" || check.HTTP != "" || check.TCP != "" || check.GRPC != "" { if interval := service.Attrs["check_interval"]; interval != "" { check.Interval = interval } else { diff --git a/docs/user/backends.md b/docs/user/backends.md index 55233e6fd..80c4b2ad3 100644 --- a/docs/user/backends.md +++ b/docs/user/backends.md @@ -93,6 +93,20 @@ healthy. SERVICE_CHECK_TTL=30s ``` +### Consul gRPC Check + +This feature is only available when using Consul 1.0.5 or newer. Containers +specifying these extra metadata in labels or environment will be used to +register an gRPC health check with the service. + +```bash +SERVICE_CHECK_GRPC=true +SERVICE_CHECK_INTERVAL=5s +SERVICE_CHECK_TIMEOUT=3s # optional, Consul default uses 10s +SERVICE_CHECK_GRPC_USE_TLS=true # optional, Consul default uses false +SERVICE_CHECK_TLS_SKIP_VERIFY=true # optional, Consul default uses false +``` + ### Consul Initial Health Check Status By default when a service is registered against Consul, the state is set to "critical". You can specify the initial health check status.