Skip to content

Commit

Permalink
Support HTTPS Marathon health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mastron committed Jun 11, 2016
1 parent fe4545d commit 6a8b75f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions config/haproxy_template.cfg
Expand Up @@ -70,7 +70,7 @@ backend {{ $app.EscapedId }}-cluster{{ if $app.HealthCheckPath }}
option httpclose
option forwardfor
{{ range $page, $task := .Tasks }}
server {{ $app.EscapedId}}-{{ $task.Host }}-{{ $task.Port }} {{ $task.Host }}:{{ $task.Port }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }} {{ end }}
server {{ $app.EscapedId}}-{{ $task.Host }}-{{ $task.Port }} {{ $task.Host }}:{{ $task.Port }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }} {{ if eq $app.HealthCheckProtocol "HTTPS" }} ssl verify none {{ end }} {{ end }}
{{ end }}

##
Expand All @@ -89,6 +89,6 @@ backend {{ $app.EscapedId }}-cluster{{ if $app.HealthCheckPath }}
## balance leastconn
## option forwardfor
## {{ range $page, $task := $app.Tasks }}
## server {{ $app.EscapedId }}-{{ $task.Host }}-{{ index $task.Ports $serviceIndex }} {{ $task.Host }}:{{ index $task.Ports $serviceIndex }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }} {{ end }}
## server {{ $app.EscapedId }}-{{ $task.Host }}-{{ index $task.Ports $serviceIndex }} {{ $task.Host }}:{{ index $task.Ports $serviceIndex }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }} {{ if eq $app.HealthCheckProtocol "HTTPS" }} ssl verify none {{ end }} {{ end }}
## {{ end }}
## {{ end }}
47 changes: 30 additions & 17 deletions services/marathon/marathon.go
Expand Up @@ -28,16 +28,17 @@ type HealthCheck struct {

// An app may have multiple processes
type App struct {
Id string
MesosDnsId string
EscapedId string
HealthCheckPath string
HealthChecks []HealthCheck
Tasks []Task
ServicePort int
ServicePorts []int
Env map[string]string
Labels map[string]string
Id string
MesosDnsId string
EscapedId string
HealthCheckPath string
HealthCheckProtocol string
HealthChecks []HealthCheck
Tasks []Task
ServicePort int
ServicePorts []int
Env map[string]string
Labels map[string]string
}

type AppList []App
Expand Down Expand Up @@ -196,12 +197,13 @@ func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]m

// build App from marathonApp
app := App{
Id: appPath,
MesosDnsId: getMesosDnsId(appPath),
EscapedId: strings.Replace(appId, "/", "::", -1),
HealthCheckPath: parseHealthCheckPath(mApp.HealthChecks),
Env: mApp.Env,
Labels: mApp.Labels,
Id: appPath,
MesosDnsId: getMesosDnsId(appPath),
EscapedId: strings.Replace(appId, "/", "::", -1),
HealthCheckPath: parseHealthCheckPath(mApp.HealthChecks),
HealthCheckProtocol: parseHealthCheckProtocol(mApp.HealthChecks),
Env: mApp.Env,
Labels: mApp.Labels,
}

app.HealthChecks = make([]HealthCheck, 0, len(mApp.HealthChecks))
Expand Down Expand Up @@ -253,14 +255,25 @@ func getMesosDnsId(appPath string) string {

func parseHealthCheckPath(checks []marathonHealthCheck) string {
for _, check := range checks {
if check.Protocol != "HTTP" {
if check.Protocol != "HTTP" && check.Protocol != "HTTPS" {
continue
}
return check.Path
}
return ""
}

/* maybe combine this with the above? */
func parseHealthCheckProtocol(checks []marathonHealthCheck) string {
for _, check := range checks {
if check.Protocol != "HTTP" && check.Protocol != "HTTPS" {
continue
}
return check.Protocol
}
return ""
}

/*
Apps returns a struct that describes Marathon current app and their
sub tasks information.
Expand Down

0 comments on commit 6a8b75f

Please sign in to comment.