Skip to content

Commit

Permalink
Timed healthcheck, parallel GTG.
Browse files Browse the repository at this point in the history
Adjusted memory requests and limit.
  • Loading branch information
bogdanguranda committed Jan 16, 2018
1 parent 70454be commit de10cd6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
21 changes: 13 additions & 8 deletions app.go
Expand Up @@ -119,13 +119,18 @@ func runServer(neoURL string, port string, cacheDuration string, env string) {
servicesRouter := mux.NewRouter()

// Health checks and standards first
var checks []fthealth.Check = []fthealth.Check{people.HealthCheck()}
servicesRouter.HandleFunc("/__health", fthealth.Handler(fthealth.HealthCheck{
SystemCode: "public-people-api",
Name: "public-people-api",
Description: "Public API for serving information on People within UPP",
Checks: checks,
}))
checks := []fthealth.Check{people.HealthCheck()}
timedHC := fthealth.TimedHealthCheck{
HealthCheck: fthealth.HealthCheck{
SystemCode: "public-people-api",
Name: "Public people api",
Description: "Public API for serving information on People within UPP",
Checks: checks,
},
Timeout: 10 * time.Second,
}

servicesRouter.HandleFunc("/__health", fthealth.Handler(timedHC))

// Then API specific ones:
servicesRouter.HandleFunc("/people/{uuid}", people.GetPerson).Methods("GET")
Expand All @@ -139,7 +144,7 @@ func runServer(neoURL string, port string, cacheDuration string, env string) {
// The top one of these build info endpoints feels more correct, but the lower one matches what we have in Dropwizard,
// so it's what apps expect currently same as ping, the content of build-info needs more definition
http.HandleFunc(status.BuildInfoPath, status.BuildInfoHandler)
http.HandleFunc("/__gtg", people.GoodToGo)
http.HandleFunc("/__gtg", status.NewGoodToGoHandler(people.GTG))
http.Handle("/", monitoringRouter)

if err := http.ListenAndServe(":"+port, nil); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions helm/public-people-api/values.yaml
Expand Up @@ -11,8 +11,8 @@ image:
cache_duration: 10m
resources:
requests:
memory: 12Mi
memory: 32Mi
limits:
memory: 72Mi
memory: 128Mi


17 changes: 13 additions & 4 deletions people/handlers.go
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
"regexp"
"strings"
"github.com/Financial-Times/service-status-go/gtg"
)

const (
Expand Down Expand Up @@ -46,11 +47,19 @@ func Checker() (string, error) {
return "Error connecting to neo4j", err
}

//GoodToGo returns a 503 if the healthcheck fails - suitable for use from varnish to check availability of a node
func GoodToGo(writer http.ResponseWriter, req *http.Request) {
if _, err := Checker(); err != nil {
writer.WriteHeader(http.StatusServiceUnavailable)
func GTG() gtg.Status {
statusCheck := func() gtg.Status {
return gtgCheck(Checker)
}

return gtg.FailFastParallelCheck([]gtg.StatusChecker{statusCheck})()
}

func gtgCheck(handler func() (string, error)) gtg.Status {
if _, err := handler(); err != nil {
return gtg.Status{GoodToGo: false, Message: err.Error()}
}
return gtg.Status{GoodToGo: true}
}

// MethodNotAllowedHandler handles 405
Expand Down
16 changes: 6 additions & 10 deletions vendor/vendor.json
Expand Up @@ -17,16 +17,12 @@
"versionExact": "1.4.0"
},
{
"checksumSHA1": "fNgRM8ZlaDzdvSpuhSdGxEOrWi4=",
"checksumSHA1": "G8lW8pPVLieqh/MTJZkvI/i/WyM=",
"path": "github.com/Financial-Times/go-fthealth/v1_1",
"revision": "e7ccca038327a0091303a52445ec1f0fb66cb97b",
"revisionTime": "2017-05-25T09:50:41Z"
},
{
"checksumSHA1": "FUhczVSvt/VQAlWfzATo1YLez2E=",
"path": "github.com/Financial-Times/go-fthealth/v1a",
"revision": "e7ccca038327a0091303a52445ec1f0fb66cb97b",
"revisionTime": "2017-05-25T09:50:41Z"
"revision": "1b007e2b37b7936dfb6671fa17e5a29fd35a08ea",
"revisionTime": "2017-12-04T12:48:31Z",
"version": "0.4.0",
"versionExact": "0.4.0"
},
{
"checksumSHA1": "dqF1g4reeLPNN10qTXgDJj3fHm4=",
Expand Down Expand Up @@ -227,7 +223,7 @@
"revisionTime": "2017-07-19T21:11:51Z"
},
{
"checksumSHA1": "N6Wj304ePwjAJRZCSlbtA2lev6o=",
"checksumSHA1": "3h7O5ut4va7qUnw70cdlf2bvjjE=",
"path": "golang.org/x/sys/unix",
"revision": "14ac33bf8474b62c65cae263af2e4d3b543cc699",
"revisionTime": "2017-07-25T14:33:55Z"
Expand Down

0 comments on commit de10cd6

Please sign in to comment.