Skip to content

Commit

Permalink
feat(guardian-prover-health-check): Guardian prover metrics (#15377)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Dec 13, 2023
1 parent 975c882 commit 97f83f0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/guardian-prover-health-check/guardianprover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prometheus/client_golang/prometheus"
)

type GuardianProver struct {
Address common.Address
ID *big.Int
Address common.Address
ID *big.Int
HealthCheckCounter prometheus.Counter
SignedBlockCounter prometheus.Counter
}

func SignatureToGuardianProver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
guardianproverhealthcheck "github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check"
"github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/bindings/guardianprover"
hchttp "github.com/taikoxyz/taiko-mono/packages/guardian-prover-health-check/http"
Expand Down Expand Up @@ -108,9 +111,19 @@ func InitFromConfig(ctx context.Context, h *HealthChecker, cfg *Config) (err err
return err
}

log.Info("setting guardian prover address", "address", guardianAddress.Hex(), "id", guardianId.Uint64())

guardianProvers = append(guardianProvers, guardianproverhealthcheck.GuardianProver{
Address: guardianAddress,
ID: guardianId,
HealthCheckCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: fmt.Sprintf("guardian_prover_%v_health_checks_ops_total", guardianId.Uint64()),
Help: "The total number of health checks",
}),
SignedBlockCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: fmt.Sprintf("guardian_prover_%v_signed_block_ops_total", guardianId.Uint64()),
Help: "The total number of signed blocks",
}),
})
}

Expand Down
10 changes: 10 additions & 0 deletions packages/guardian-prover-health-check/http/post_health_check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"log/slog"
"net/http"

"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -61,5 +62,14 @@ func (srv *Server) PostHealthCheck(c echo.Context) error {
return c.JSON(http.StatusBadRequest, err)
}

// increment health check metric
for _, v := range srv.guardianProvers {
if v.Address.Hex() == recoveredGuardianProver.Address.Hex() {
v.HealthCheckCounter.Inc()
}
}

slog.Info("successful health check", "guardianProver", recoveredGuardianProver.Address.Hex())

return c.JSON(http.StatusOK, nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@ func (srv *Server) PostSignedBlock(c echo.Context) error {
return c.JSON(http.StatusBadRequest, err)
}

// increment signed block metric
for _, v := range srv.guardianProvers {
if v.Address.Hex() == recoveredGuardianProver.Address.Hex() {
v.SignedBlockCounter.Inc()
}
}

slog.Info("successful signed block", "guardianProver", recoveredGuardianProver.Address.Hex())

return c.JSON(http.StatusOK, nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS signed_blocks (
guardian_prover_id int NOT NULL,
block_id int NOT NULL,
signature varchar(5000) NOT NULL,
block_hash varchar (42) NOT NULL,
block_hash VARCHAR(255) NOT NULL,
recovered_address varchar(42) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
Expand Down

0 comments on commit 97f83f0

Please sign in to comment.