Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tenscan] Endpoint for health check #1718

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions go/obsclient/obsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (oc *ObsClient) BatchHeaderByHash(hash gethcommon.Hash) (*common.BatchHeade
return batchHeader, err
}

// Health returns the health of the node.
func (oc *ObsClient) Health() (bool, error) {
// HealthStatusOfNode returns the health of the node.
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
func (oc *ObsClient) HealthStatusOfNode() (bool, error) {
var healthy *hostcommon.HealthCheck
err := oc.rpcClient.Call(&healthy, rpc.Health)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/networktest/env/dev_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func awaitHealthStatus(rpcAddress string, timeout time.Duration) error {
return fmt.Errorf("failed dial host (%s): %w", rpcAddress, err)
}
defer c.Close()
healthy, err := c.Health()
healthy, err := c.HealthStatusOfNode()
if err != nil {
return fmt.Errorf("failed to get host health (%s): %w", rpcAddress, err)
}
Expand Down
2 changes: 1 addition & 1 deletion integration/networktest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NodeHealthCheck(rpcAddress string) error {
if err != nil {
return err
}
health, err := client.Health()
health, err := client.HealthStatusOfNode()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/network/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (n *networkOfSocketNodes) createConnections(simParams *params.SimParams) er
startTime := time.Now()
healthy := false
for ; !healthy; time.Sleep(500 * time.Millisecond) {
healthy, _ = client.Health()
healthy, _ = client.HealthStatusOfNode()
if time.Now().After(startTime.Add(3 * time.Minute)) {
return fmt.Errorf("nodes not healthy after 3 minutes")
}
Expand Down
2 changes: 1 addition & 1 deletion integration/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (s *Simulation) prefundL1Accounts() {

func (s *Simulation) checkHealthStatus() {
for _, client := range s.RPCHandles.ObscuroClients {
if healthy, err := client.Health(); !healthy || err != nil {
if healthy, err := client.HealthStatusOfNode(); !healthy || err != nil {
panic("Client is not healthy: " + err.Error())
Jennievon marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func waitForHealthyNode(port int) error { // todo: hook the cfg
defer client.Stop()

obsClient := obsclient.NewObsClient(client)
health, err := obsClient.Health()
health, err := obsClient.HealthStatusOfNode()
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions tools/obscuroscan_v2/backend/obscuroscan_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (b *Backend) GetLatestBatch() (*common.BatchHeader, error) {
return b.obsClient.BatchHeaderByNumber(nil)
}

func (b *Backend) GetHealthStatus() (bool, error) {
return b.obsClient.HealthStatusOfNode()
}

func (b *Backend) GetLatestRollup() (*common.RollupHeader, error) {
return &common.RollupHeader{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func routeItems(r *gin.Engine, server *WebServer) {
r.GET("/items/batches/", server.getBatchListing)
r.GET("/items/blocks/", server.getBlockListing)
r.GET("/info/obscuro/", server.getConfig)
r.POST("/info/health/", server.getHealthStatus)
}

func (w *WebServer) getHealthStatus(c *gin.Context) {
healthStatus, err := w.backend.GetHealthStatus()

c.JSON(http.StatusOK, gin.H{"result": healthStatus, "errors": fmt.Sprintf("%s", err)})
}

func (w *WebServer) getLatestBatch(c *gin.Context) {
Expand Down
Loading