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] health check UI on Tenscan #1719

Merged
merged 10 commits into from
Jan 8, 2024
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.
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 @@ -181,7 +181,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())
}
}
Expand Down
2 changes: 1 addition & 1 deletion testnet/launcher/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,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/tenscan/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
7 changes: 7 additions & 0 deletions tools/tenscan/backend/webserver/webserver_routes_items.go
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
14 changes: 14 additions & 0 deletions tools/tenscan/frontend/api/general.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can another name be used for this ? Seems to be a bag of holding file.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ResponseDataInterface } from "@/src/types/interfaces";
import { httpRequest } from ".";
import { pathToUrl } from "@/src/routes/router";
import { apiRoutes } from "@/src/routes";

export const fetchTestnetStatus = async (): Promise<
ResponseDataInterface<any>
> => {
return await httpRequest<ResponseDataInterface<any>>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do anything with the error ooc ? Should we ?

method: "post",
url: pathToUrl(apiRoutes.getHealthStatus),
data: { jsonrpc: "2.0", method: "obscuro_health", params: [], id: 1 },
});
};
24 changes: 24 additions & 0 deletions tools/tenscan/frontend/src/components/health-indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import { Badge, badgeVariants } from "./ui/badge";
import { useGeneralService } from "../services/useGeneralService";

const HealthIndicator = () => {
const { testnetStatus } = useGeneralService();

return (
<div className="flex items-center space-x-2 border rounded-lg p-2">
<h3 className="text-sm">Testnet Status: </h3>
<Badge
variant={
(testnetStatus?.result
? "success"
: "destructive") as keyof typeof badgeVariants
}
>
{testnetStatus?.result ? "Live" : "Down"}
</Badge>
</div>
);
};

export default HealthIndicator;
2 changes: 2 additions & 0 deletions tools/tenscan/frontend/src/components/layouts/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Link from "next/link";
import { HamburgerMenuIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import { Button } from "../ui/button";
import HealthIndicator from "../health-indicator";

export default function Header() {
return (
Expand All @@ -16,6 +17,7 @@ export default function Header() {
<div className="hidden md:flex items-center space-x-4">
<MainNav className="mx-6" />
<div className="flex items-center space-x-4">
<HealthIndicator />
<ModeToggle />
<ConnectWalletButton />
</div>
Expand Down
3 changes: 3 additions & 0 deletions tools/tenscan/frontend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const apiRoutes = {
// **** ROLLUPS ****
getRollups: "/items/rollup/latest/",
decryptEncryptedRollup: "/actions/decryptTxBlob/",

// **** INFO ****
getHealthStatus: "/info/health/",
};

export const ethMethods = {
Expand Down
19 changes: 19 additions & 0 deletions tools/tenscan/frontend/src/services/useGeneralService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { fetchTestnetStatus } from "@/api/general";
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";

export const useGeneralService = () => {
const [noPolling, setNoPolling] = useState(false);

const {
data: testnetStatus,
isLoading: isStatusLoading,
refetch: refetchTestnetStatus,
} = useQuery({
queryKey: ["testnetStatus"],
queryFn: () => fetchTestnetStatus(),
// refetchInterval: noPolling ? false : pollingInterval,
});

return { testnetStatus, isStatusLoading, setNoPolling, refetchTestnetStatus };
};
Loading