From d0fb19948a215690c07aceac82515656a164ba9f Mon Sep 17 00:00:00 2001 From: chromerobv Date: Fri, 24 Jun 2016 19:49:35 +0000 Subject: [PATCH 1/4] added check to nginx --- ext/lb/nginx/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/lb/nginx/config.go b/ext/lb/nginx/config.go index 2b6085bc..6bc287d5 100644 --- a/ext/lb/nginx/config.go +++ b/ext/lb/nginx/config.go @@ -32,6 +32,7 @@ type Host struct { Upstream *Upstream WebsocketEndpoints []string IPHash bool + Check string } type Config struct { Hosts []*Host From fe81762680c273d7554972bc3996b4ecd6f798ec Mon Sep 17 00:00:00 2001 From: chromerobv Date: Wed, 28 Sep 2016 00:58:57 +0000 Subject: [PATCH 2/4] nginx checks --- ext/lb/nginx/generate.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ext/lb/nginx/generate.go b/ext/lb/nginx/generate.go index ca21be0c..6b43f524 100644 --- a/ext/lb/nginx/generate.go +++ b/ext/lb/nginx/generate.go @@ -12,6 +12,7 @@ import ( func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Container) (interface{}, error) { var hosts []*Host upstreamServers := map[string][]string{} + hostChecks := map[string]string{} serverNames := map[string][]string{} hostContextRoots := map[string]*ContextRoot{} hostContextRootRewrites := map[string]bool{} @@ -59,6 +60,28 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai } hostContextRootRewrites[domain] = utils.ContextRootRewrite(cInfo.Config) + healthCheck := utils.HealthCheck(cInfo.Config) + healthCheckInterval, err := utils.HealthCheckInterval(cInfo.Config) + if err != nil { + log().Errorf("error parsing health check interval: %s", err) + continue + } + + + if healthCheck != "" { + if val, ok := hostChecks[domain]; ok { + // check existing host check for different values + if val != healthCheck { + log().Warnf("conflicting check specified for %s", domain) + } + } else { + hostChecks[domain] = healthCheck + log().Debugf("using custom check for %s: %s", domain, healthCheck) + } + + log().Debugf("check interval for %s: %d", domain, healthCheckInterval) + } + // check if the first server name is there; if not, add // this happens if there are multiple backend containers if _, ok := serverNames[domain]; !ok { @@ -159,6 +182,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai Port: p.cfg.Port, ContextRoot: hostContextRoots[k], ContextRootRewrite: hostContextRootRewrites[k], + Check: hostChecks[k], SSLPort: p.cfg.SSLPort, SSL: hostSSL[k], SSLCert: hostSSLCert[k], @@ -182,6 +206,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai up := &Upstream{ Name: k, Servers: servers, + heckInterval: healthCheckInterval, } h.Upstream = up From c34d0bb55c14635315b92412a839b70ba6e0a518 Mon Sep 17 00:00:00 2001 From: chromerobv Date: Thu, 1 Dec 2016 22:55:15 +0000 Subject: [PATCH 3/4] added interval --- Dockerfile.build | 4 ++-- ext/lb/nginx/config.go | 1 + ext/lb/nginx/generate.go | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile.build b/Dockerfile.build index 210e9174..25c66f7b 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,6 +1,6 @@ FROM golang:1.6-alpine -RUN apk add -U git make -RUN go get github.com/tools/godep +RUN apk add -U git make curl +RUN go get github.com/Masterminds/glide ENV DOCKER_VERSION 1.10.3 ENV APP interlock ENV REPO ehazlett/$APP diff --git a/ext/lb/nginx/config.go b/ext/lb/nginx/config.go index 6bc287d5..f29281a3 100644 --- a/ext/lb/nginx/config.go +++ b/ext/lb/nginx/config.go @@ -33,6 +33,7 @@ type Host struct { WebsocketEndpoints []string IPHash bool Check string + CheckInterval int } type Config struct { Hosts []*Host diff --git a/ext/lb/nginx/generate.go b/ext/lb/nginx/generate.go index 6b43f524..dd178e51 100644 --- a/ext/lb/nginx/generate.go +++ b/ext/lb/nginx/generate.go @@ -13,6 +13,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai var hosts []*Host upstreamServers := map[string][]string{} hostChecks := map[string]string{} + hostCheckIntervals := map[string]int{} serverNames := map[string][]string{} hostContextRoots := map[string]*ContextRoot{} hostContextRootRewrites := map[string]bool{} @@ -60,6 +61,13 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai } hostContextRootRewrites[domain] = utils.ContextRootRewrite(cInfo.Config) + + // check if the first server name is there; if not, add + // this happens if there are multiple backend containers + if _, ok := serverNames[domain]; !ok { + serverNames[domain] = []string{domain} + } + healthCheck := utils.HealthCheck(cInfo.Config) healthCheckInterval, err := utils.HealthCheckInterval(cInfo.Config) if err != nil { @@ -67,8 +75,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai continue } - - if healthCheck != "" { + if healthCheck != "" { if val, ok := hostChecks[domain]; ok { // check existing host check for different values if val != healthCheck { @@ -76,18 +83,13 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai } } else { hostChecks[domain] = healthCheck + hostCheckIntervals[domain] = healthCheckInterval log().Debugf("using custom check for %s: %s", domain, healthCheck) } log().Debugf("check interval for %s: %d", domain, healthCheckInterval) } - // check if the first server name is there; if not, add - // this happens if there are multiple backend containers - if _, ok := serverNames[domain]; !ok { - serverNames[domain] = []string{domain} - } - hostSSL[domain] = utils.SSLEnabled(cInfo.Config) hostSSLOnly[domain] = utils.SSLOnly(cInfo.Config) hostIPHash[domain] = utils.IPHash(cInfo.Config) @@ -183,6 +185,7 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai ContextRoot: hostContextRoots[k], ContextRootRewrite: hostContextRootRewrites[k], Check: hostChecks[k], + CheckInterval: hostCheckIntervals[k], SSLPort: p.cfg.SSLPort, SSL: hostSSL[k], SSLCert: hostSSLCert[k], @@ -206,8 +209,8 @@ func (p *NginxLoadBalancer) GenerateProxyConfig(containers []dockerclient.Contai up := &Upstream{ Name: k, Servers: servers, - heckInterval: healthCheckInterval, } + h.Upstream = up hosts = append(hosts, h) From 2a84a2684f5f3beaa622226d72606975bafc4cfa Mon Sep 17 00:00:00 2001 From: chromerobv Date: Thu, 1 Dec 2016 23:33:31 +0000 Subject: [PATCH 4/4] anged default interval --- ext/lb/utils/health_check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/lb/utils/health_check.go b/ext/lb/utils/health_check.go index 10cd64d9..d09e5b05 100644 --- a/ext/lb/utils/health_check.go +++ b/ext/lb/utils/health_check.go @@ -8,7 +8,7 @@ import ( ) const ( - DefaultHealthCheckInterval = 5000 + DefaultHealthCheckInterval = 10000 ) func HealthCheck(config *dockerclient.ContainerConfig) string {