Skip to content

Commit

Permalink
Adding alive check to Task. Adding labels and split id to App. This d…
Browse files Browse the repository at this point in the history
…ata is available in the haproxy config template to make richer decisions
  • Loading branch information
dkesler committed Sep 2, 2016
1 parent 9645270 commit 0dd5815
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion services/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Task struct {
Host string
Port int
Ports []int
Alive bool
}

// A health check on the application
Expand All @@ -40,6 +41,7 @@ type App struct {
ServicePorts []int
Env map[string]string
Labels map[string]string
SplitId []string
}

type AppList []App
Expand All @@ -62,6 +64,10 @@ type marathonTasks struct {
Tasks marathonTaskList `json:"tasks"`
}

type HealthCheckResult struct {
Alive bool
}

type marathonTask struct {
AppId string
Id string
Expand All @@ -71,6 +77,7 @@ type marathonTask struct {
StartedAt string
StagedAt string
Version string
HealthCheckResults []HealthCheckResult
}

func (slice marathonTaskList) Len() int {
Expand Down Expand Up @@ -184,8 +191,20 @@ func fetchTasks(endpoint string, conf *configuration.Configuration) (map[string]
return tasksById, nil
}

func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]marathonApp) AppList {
func calculateTaskHealth(healthCheckResults []HealthCheckResult, healthChecks []HealthChecks) bool {
//If we don't even have health check results for every health check, don't count the task as healthy
if len(healthChecks) > len(healthCheckResults) {
return false;
}
for _, healthCheck := range healthCheckResults {
if !healthCheck.Alive {
return false;
}
}
return true;
}

func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]marathonApp) AppList {
apps := AppList{}

for appId, mApp := range marathonApps {
Expand All @@ -205,6 +224,7 @@ func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]m
HealthCheckProtocol: parseHealthCheckProtocol(mApp.HealthChecks),
Env: mApp.Env,
Labels: mApp.Labels,
SplitId: strings.Split(appId, "/"),
}

app.HealthChecks = make([]HealthCheck, 0, len(mApp.HealthChecks))
Expand All @@ -231,6 +251,7 @@ func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]m
Host: mTask.Host,
Port: mTask.Ports[0],
Ports: mTask.Ports,
Alive: calculateTaskHealth(mTask.healthCheckResults, mApp.HealthChecks)
}
tasks = append(tasks, t)
}
Expand Down

0 comments on commit 0dd5815

Please sign in to comment.