From d888b4fcb5623d21d9ec5e80739e53ecce5a9330 Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 30 Oct 2015 00:15:03 +0100 Subject: [PATCH] Added healthcheck filter in marathon tasks --- marathon.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/marathon.go b/marathon.go index f79558d0a..1e1f4d22c 100644 --- a/marathon.go +++ b/marathon.go @@ -114,7 +114,7 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration { //filter tasks filteredTasks := fun.Filter(func(task marathon.Task) bool { if len(task.Ports) == 0 { - log.Debug("Filtering marathon task without port", task.AppID) + log.Debug("Filtering marathon task without port %s", task.AppID) return false } application, errApp := getApplication(task, applications.Apps) @@ -124,13 +124,28 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration { } _, err := strconv.Atoi(application.Labels["traefik.port"]) if len(application.Ports) > 1 && err != nil { - log.Debug("Filtering marathon task with more than 1 port and no traefik.port label", task.AppID) + log.Debugf("Filtering marathon task %s with more than 1 port and no traefik.port label", task.AppID) return false } if application.Labels["traefik.enable"] == "false" { - log.Debug("Filtering disabled marathon task", task.AppID) + log.Debugf("Filtering disabled marathon task %s", task.AppID) return false } + //filter healthchecks + if application.HasHealthChecks() { + if task.HasHealthCheckResults() { + for _, healthcheck := range task.HealthCheckResult { + // found one bad healthcheck, return false + if !healthcheck.Alive { + log.Debugf("Filtering marathon task %s with bad healthcheck", task.AppID) + return false + } + } + } else { + log.Debugf("Filtering marathon task %s with bad healthcheck", task.AppID) + return false + } + } return true }, tasks.Tasks).([]marathon.Task)