Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Included default TCP check in tasks that has not check defined #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (c *Consul) Register(service *registry.Service) {
Script: service.Check.Script,
HTTP: service.Check.HTTP,
Interval: service.Check.Interval,
TCP: service.Check.TCP,
Timeout: service.Check.Timeout,
},
}

Expand Down
27 changes: 26 additions & 1 deletion mesos/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,57 @@ type CheckVar struct {

var globalCV *CheckVar

const defaultInterval = "2s"
const defaultTimeout = "60s"

// Task Methods

// GetCheck()
// Build a Check structure from the Task labels
//
func GetCheck(t *state.Task, cv *CheckVar) *registry.Check {
matched := false
c := registry.DefaultCheck()

for _, l := range t.Labels {
k := strings.ToLower(l.Key)

switch k {
case "check_http":
c.HTTP = interpolate(cv, l.Value)
matched = true
case "check_script":
c.Script = interpolate(cv, l.Value)
matched = true
case "check_ttl":
c.TTL = interpolate(cv, l.Value)
matched = true
case "check_interval":
c.Interval = l.Value
matched = true
}
}

if !matched {
c.TCP = interpolate(cv, hostPortToString(cv))
c.Interval = defaultInterval
c.Timeout = defaultTimeout

}

return c
}

// Returns a CheckVar struct in "IP:PORT" format
//
func hostPortToString(cv *CheckVar) string {
strResult := ""
if cv.Host != "" && cv.Port != "" {
strResult = strings.Join([]string{cv.Host, ":", cv.Port}, "")
}

return strResult
}

// Replace {variables} with values
//
func interpolate(cv *CheckVar, s string) string {
Expand Down
4 changes: 4 additions & 0 deletions registry/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type Check struct {
TTL string
HTTP string
Interval string
TCP string
Timeout string
}

type Service struct {
Expand Down Expand Up @@ -34,5 +36,7 @@ func DefaultCheck() *Check {
Script: "",
HTTP: "",
Interval: "",
TCP: "",
Timeout: "",
}
}