Skip to content

Commit

Permalink
healthcheck for aws load balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Turcan committed Oct 10, 2022
1 parent b9c853f commit 6fe5d5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/rpc/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/health", NodeHealthRequestHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/blocks/{height}", BlockRequestHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(clientCtx)).Methods("GET")
Expand Down
6 changes: 6 additions & 0 deletions client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func (s *IntegrationTestSuite) TestLatestBlocks() {
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) TestHealth() {
val0 := s.network.Validators[0]
_, err := rest.GetRequest(fmt.Sprintf("%s/health", val0.APIAddress))
s.Require().NoError(err)
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
}
15 changes: 15 additions & 0 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,18 @@ func NodeSyncingRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
rest.PostProcessResponseBare(w, clientCtx, SyncingResponse{Syncing: status.SyncInfo.CatchingUp})
}
}

// REST handler for node health check - aws recognizes only http status codes
func NodeHealthRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus(clientCtx)
if rest.CheckInternalServerError(w, err) {
return
}
if status.SyncInfo.CatchingUp {
rest.WriteErrorResponse(w, http.StatusServiceUnavailable, "NOK")
} else {
rest.PostProcessResponseBare(w, clientCtx, []byte("OK"))
}
}
}

0 comments on commit 6fe5d5d

Please sign in to comment.