Skip to content

Commit

Permalink
Add and start health checks on portal start
Browse files Browse the repository at this point in the history
🎆
  • Loading branch information
glinton committed Jul 3, 2017
1 parent 2a7d436 commit bdc701a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
8 changes: 8 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ type (
Targets []string `json:"targets"` // ips of servers - ["http://127.0.0.1:8080/app1","http://127.0.0.2"] (optional)
FwdPath string `json:"fwdpath"` // path to forward to targets - "/goadmin" incoming req: test.com/admin -> 127.0.0.1/goadmin (optional)
Page string `json:"page"` // page to serve instead of routing to targets - "<HTML>We are fixing it</HTML>" (optional)
// defines health check
Endpoint string `json:"endpoint"` // url path to check for health (todo: what to do when fwdpath is set) (non blank enables health checks)
ExpectedCode int `json:"expected_code"` // expected http response code (default 200)
ExpectedBody string `json:"expected_body"` // expected body
ExpectedHeader string `json:"expected_header"` // expected http header (field:value)
Host string `json:"host"` // 'host' header to use when performing health check
Timeout int `json:"timeout"` // milliseconds before connection times out (default 3000 (3s))
Attempts int `json:"attempts"` // number of times to try before marking dead
}

CertBundle struct {
Expand Down
35 changes: 33 additions & 2 deletions proxymgr/nanobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (self Nanobox) Init() error {
}
config.Log.Info("Proxy listening at https://%s...", config.RouteTls)

// start proxy health checker (todo: make check interval(pulse) configurable)
go router.StartHealth(20)

return nil
}

Expand Down Expand Up @@ -128,15 +131,43 @@ func (self Nanobox) keysToC(certs []router.KeyPair) []core.CertBundle {
func (self Nanobox) rToRoutes(routes []core.Route) []router.Route {
var rts []router.Route
for i := range routes {
rts = append(rts, router.Route{SubDomain: routes[i].SubDomain, Domain: routes[i].Domain, Path: routes[i].Path, Targets: routes[i].Targets, FwdPath: routes[i].FwdPath, Page: routes[i].Page})
rts = append(rts, router.Route{
SubDomain: routes[i].SubDomain,
Domain: routes[i].Domain,
Path: routes[i].Path,
Targets: routes[i].Targets,
FwdPath: routes[i].FwdPath,
Page: routes[i].Page,
Endpoint: routes[i].Endpoint,
ExpectedCode: routes[i].ExpectedCode,
ExpectedBody: routes[i].ExpectedBody,
ExpectedHeader: routes[i].ExpectedHeader,
Host: routes[i].Host,
Timeout: routes[i].Timeout,
Attempts: routes[i].Attempts,
})
}
return rts
}

func (self Nanobox) routesToR(routes []router.Route) []core.Route {
var rts []core.Route
for i := range routes {
rts = append(rts, core.Route{SubDomain: routes[i].SubDomain, Domain: routes[i].Domain, Path: routes[i].Path, Targets: routes[i].Targets, FwdPath: routes[i].FwdPath, Page: routes[i].Page})
rts = append(rts, core.Route{
SubDomain: routes[i].SubDomain,
Domain: routes[i].Domain,
Path: routes[i].Path,
Targets: routes[i].Targets,
FwdPath: routes[i].FwdPath,
Page: routes[i].Page,
Endpoint: routes[i].Endpoint,
ExpectedCode: routes[i].ExpectedCode,
ExpectedBody: routes[i].ExpectedBody,
ExpectedHeader: routes[i].ExpectedHeader,
Host: routes[i].Host,
Timeout: routes[i].Timeout,
Attempts: routes[i].Attempts,
})
}
return rts
}
Expand Down
6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@
"revisionTime": "2017-03-27T21:44:30Z"
},
{
"checksumSHA1": "0J1NLSmuczwouZtUqEuPxLTuPRA=",
"checksumSHA1": "xKA5NvBoR4p257SEXsEzbYKhYV0=",
"path": "github.com/nanobox-io/nanobox-router",
"revision": "3802731d4f79d6df47e740947050729a5b926f45",
"revisionTime": "2017-05-17T20:41:27Z"
"revision": "059779d975f5d9ed9913423d5e074e54edf4b501",
"revisionTime": "2017-07-03T23:17:23Z"
},
{
"checksumSHA1": "65+hx0QlLzpWe5pnjAzteKBnC10=",
Expand Down

0 comments on commit bdc701a

Please sign in to comment.