Repository: allegro/marathon-consul (go)

Issue:
Calculate ignored healthcheckonly once
Currently w parse config ignored healtcheck for every task. This is completly redundant job becouse we do not allow live config reload.

Create field inside `Consul` structure and fill it with ignored healthchecks. See [*Consul.getIgnoredHealthCheckTypes()](https://github.com/allegro/marathon-consul/blob/v1.0.0/consul/consul.go#L351-L360)

Pull request description:
Fixes #149 | Calculate ignored healthchecks once

Patch:
diff --git a/consul/consul.go b/consul/consul.go
index 11c48bf..b5688ae 100644
--- a/consul/consul.go
+++ b/consul/consul.go
@@ -15,16 +15,18 @@ import (
 )
 
 type Consul struct {
-	agents Agents
-	config Config
+	agents                  Agents
+	config                  Config
+	ignoredHealthCheckTypes []string
 }
 
 type ServicesProvider func(agent *consulapi.Client) ([]*service.Service, error)
 
 func New(config Config) *Consul {
 	return &Consul{
-		agents: NewAgents(&config),
-		config: config,
+		agents:                  NewAgents(&config),
+		config:                  config,
+		ignoredHealthCheckTypes: ignoredHealthCheckTypesFromRawConfigEntry(config.IgnoredHealthChecks),
 	}
 }
 
@@ -300,10 +302,8 @@ func (c *Consul) serviceID(task *apps.Task, name string, port int) string {
 
 func (c *Consul) marathonToConsulChecks(task *apps.Task, healthChecks []apps.HealthCheck, serviceAddress string) consulapi.AgentServiceChecks {
 	var checks = make(consulapi.AgentServiceChecks, 0, len(healthChecks))
-
-	ignoredHealthCheckTypes := c.getIgnoredHealthCheckTypes()
 	for _, check := range healthChecks {
-		if contains(ignoredHealthCheckTypes, check.Protocol) {
+		if contains(c.ignoredHealthCheckTypes, check.Protocol) {
 			log.WithField("Id", task.AppID.String()).WithField("Address", serviceAddress).
 				Info(fmt.Sprintf("Ignoring health check of type %s", check.Protocol))
 			continue
@@ -365,9 +365,9 @@ func getHealthCheckPort(check apps.HealthCheck, task apps.Task) (int, error) {
 	return port, nil
 }
 
-func (c *Consul) getIgnoredHealthCheckTypes() []string {
+func ignoredHealthCheckTypesFromRawConfigEntry(raw string) []string {
 	ignoredTypes := make([]string, 0)
-	for _, ignoredType := range strings.Split(strings.ToUpper(c.config.IgnoredHealthChecks), ",") {
+	for _, ignoredType := range strings.Split(strings.ToUpper(raw), ",") {
 		var ignoredType = strings.TrimSpace(ignoredType)
 		if ignoredType != "" {
 			ignoredTypes = append(ignoredTypes, ignoredType)


Test patch:
diff --git a/consul/consul_test.go b/consul/consul_test.go
index 768e714..0c17f55 100644
--- a/consul/consul_test.go
+++ b/consul/consul_test.go
@@ -693,7 +693,7 @@ func TestGetIgnoredHealthCheckTypes(t *testing.T) {
 		consul := New(Config{IgnoredHealthChecks: types.config})
 
 		// then
-		assert.Equal(t, types.parsed, consul.getIgnoredHealthCheckTypes())
+		assert.Equal(t, types.parsed, consul.ignoredHealthCheckTypes)
 	}
 }