Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Commit

Permalink
GTG parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanguranda committed Nov 22, 2017
1 parent bcc053a commit d56154b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
65 changes: 48 additions & 17 deletions healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func (service *healthService) writerCheck() health.Check {
PanicGuide: "https://dewey.ft.com/upp-content-collection-rw-neo4j.html",
Severity: 1,
TechnicalSummary: "Checks if the service responsible with writing content collections to Neo4j is healthy",
Checker: func() (string, error) {
return service.httpAvailabilityChecker(service.config.writerHealthURI)
},
Checker: service.writerChecker,
}
}

Expand All @@ -69,9 +67,7 @@ func (service *healthService) contentResolverCheck() health.Check {
PanicGuide: "https://dewey.ft.com/document-store-api.html",
Severity: 1,
TechnicalSummary: "Checks if the service responsible with saving and retrieving content is healthy",
Checker: func() (string, error) {
return service.httpAvailabilityChecker(service.config.contentResolverHealthURI)
},
Checker: service.contentResolverChecker,
}
}

Expand All @@ -82,9 +78,7 @@ func (service *healthService) relationsResolverCheck() health.Check {
PanicGuide: "https://dewey.ft.com/upp-relations-api.html",
Severity: 1,
TechnicalSummary: "Checks if the service responsible with collection relations is healthy",
Checker: func() (string, error) {
return service.httpAvailabilityChecker(service.config.relationsResolverHealthURI)
},
Checker: service.relationsResolverChecker,
}
}

Expand All @@ -95,12 +89,26 @@ func (service *healthService) producerCheck() health.Check {
PanicGuide: "https://dewey.ft.com/kafka-proxy.html",
Severity: 1,
TechnicalSummary: "Checks if Kafka can be accessed through http proxy",
Checker: func() (string, error) {
return service.config.producer.ConnectivityCheck()
},
Checker: service.producerChecker,
}
}

func (service *healthService) writerChecker() (string, error) {
return service.httpAvailabilityChecker(service.config.writerHealthURI)
}

func (service *healthService) contentResolverChecker() (string, error) {
return service.httpAvailabilityChecker(service.config.contentResolverHealthURI)
}

func (service *healthService) relationsResolverChecker() (string, error) {
return service.httpAvailabilityChecker(service.config.relationsResolverHealthURI)
}

func (service *healthService) producerChecker() (string, error) {
return service.config.producer.ConnectivityCheck()
}

func (service *healthService) httpAvailabilityChecker(healthUri string) (string, error) {
req, err := http.NewRequest(http.MethodGet, healthUri, nil)
if err != nil {
Expand All @@ -123,11 +131,34 @@ func (service *healthService) httpAvailabilityChecker(healthUri string) (string,
return "OK", nil
}

func (service *healthService) gtgCheck() gtg.Status {
for _, check := range service.checks {
if _, err := check.Checker(); err != nil {
return gtg.Status{GoodToGo: false, Message: err.Error()}
}
func (service *healthService) GTG() gtg.Status {
writerCheck := func() gtg.Status {
return gtgCheck(service.writerChecker)
}

contentResolverCheck := func() gtg.Status {
return gtgCheck(service.contentResolverChecker)
}

relationsResolverCheck := func() gtg.Status {
return gtgCheck(service.relationsResolverChecker)
}

producerCheck := func() gtg.Status {
return gtgCheck(service.producerChecker)
}

return gtg.FailFastParallelCheck([]gtg.StatusChecker{
writerCheck,
contentResolverCheck,
relationsResolverCheck,
producerCheck,
})()
}

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}
}
2 changes: 1 addition & 1 deletion routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func newRouting(unfolder *unfolder, health *healthService) *routing {

func (r routing) routAdminEndpoints() {
r.router.HandleFunc(healthPath, health.Handler(r.healthService.buildHealthCheck())).Methods(http.MethodGet)
r.router.HandleFunc(status.GTGPath, status.NewGoodToGoHandler(r.healthService.gtgCheck)).Methods(http.MethodGet)
r.router.HandleFunc(status.GTGPath, status.NewGoodToGoHandler(r.healthService.GTG)).Methods(http.MethodGet)
r.router.HandleFunc(status.BuildInfoPath, status.BuildInfoHandler).Methods(http.MethodGet)
r.router.HandleFunc(status.BuildInfoPathDW, status.BuildInfoHandler).Methods(http.MethodGet)
r.router.HandleFunc(status.PingPath, status.PingHandler).Methods(http.MethodGet)
Expand Down

0 comments on commit d56154b

Please sign in to comment.