Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Remove dummy workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
eitu5ami committed Feb 16, 2024
1 parent deca40a commit 366d575
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
36 changes: 8 additions & 28 deletions internal/proxy/healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import (

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
)

const (
MetricBlockNumber int = iota
MetricGasLimit
)

const (
userAgent = "rpc-gateway-health-check"
)
Expand All @@ -26,11 +20,11 @@ type Healthchecker interface {
Stop(ctx context.Context) error
IsHealthy() bool
BlockNumber() uint64
GasLimit() uint64
Taint()
RemoveTaint()
IsTainted() bool
Name() string
SetMetric(int, interface{})
}

type RPCHealthcheckerConfig struct {
Expand Down Expand Up @@ -84,10 +78,6 @@ type RPCHealthchecker struct {
// health check ticker
ticker *time.Ticker
mu sync.RWMutex

// metrics
metricRPCProviderBlockNumber *prometheus.GaugeVec
metricRPCProviderGasLimit *prometheus.GaugeVec
}

func NewHealthchecker(config RPCHealthcheckerConfig) (Healthchecker, error) {
Expand All @@ -113,17 +103,6 @@ func (h *RPCHealthchecker) Name() string {
return h.config.Name
}

func (h *RPCHealthchecker) SetMetric(i int, metric interface{}) {
switch i {
case MetricBlockNumber:
h.metricRPCProviderBlockNumber = metric.(*prometheus.GaugeVec)
case MetricGasLimit:
h.metricRPCProviderGasLimit = metric.(*prometheus.GaugeVec)
default:
zap.L().Warn("invalid metric type, ignoring.")
}
}

func (h *RPCHealthchecker) checkBlockNumber(ctx context.Context) (uint64, error) {
// First we check the block number reported by the node. This is later
// used to evaluate a single RPC node against others
Expand All @@ -134,9 +113,6 @@ func (h *RPCHealthchecker) checkBlockNumber(ctx context.Context) (uint64, error)
zap.L().Warn("error fetching the block number", zap.Error(err), zap.String("name", h.config.Name))
return 0, err
}
if h.metricRPCProviderBlockNumber != nil {
h.metricRPCProviderBlockNumber.WithLabelValues(h.config.Name).Set(float64(blockNumber))
}
zap.L().Debug("fetched block", zap.Uint64("blockNumber", uint64(blockNumber)), zap.String("rpcProvider", h.config.Name))

return uint64(blockNumber), nil
Expand All @@ -148,9 +124,6 @@ func (h *RPCHealthchecker) checkBlockNumber(ctx context.Context) (uint64, error)
// RPC provider's side.
func (h *RPCHealthchecker) checkGasLimit(ctx context.Context) (uint64, error) {
gasLimit, err := performGasLeftCall(ctx, h.httpClient, h.config.URL)
if h.metricRPCProviderGasLimit != nil {
h.metricRPCProviderGasLimit.WithLabelValues(h.config.Name).Set(float64(gasLimit))
}
zap.L().Debug("fetched gas limit", zap.Uint64("gasLimit", gasLimit), zap.String("rpcProvider", h.config.Name))
if err != nil {
zap.L().Warn("failed fetching the gas limit", zap.Error(err), zap.String("rpcProvider", h.config.Name))
Expand Down Expand Up @@ -244,6 +217,13 @@ func (h *RPCHealthchecker) BlockNumber() uint64 {
return h.blockNumber
}

func (h *RPCHealthchecker) GasLimit() uint64 {
h.mu.Lock()
defer h.mu.Unlock()

return h.gasLimit
}

func (h *RPCHealthchecker) IsTainted() bool {
h.mu.RLock()
defer h.mu.RUnlock()
Expand Down
5 changes: 2 additions & 3 deletions internal/proxy/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ func NewHealthcheckManager(config HealthcheckManagerConfig) *HealthcheckManager
SuccessThreshold: config.Config.SuccessThreshold,
})

healthchecker.SetMetric(MetricBlockNumber, healthcheckManager.metricRPCProviderBlockNumber)
healthchecker.SetMetric(MetricGasLimit, healthcheckManager.metricRPCProviderGasLimit)

if err != nil {
panic(err)
}
Expand Down Expand Up @@ -109,6 +106,8 @@ func (h *HealthcheckManager) reportStatusMetrics() {
if healthchecker.IsTainted() {
tainted = 1
}
h.metricRPCProviderGasLimit.WithLabelValues(healthchecker.Name()).Set(float64(healthchecker.BlockNumber()))
h.metricRPCProviderBlockNumber.WithLabelValues(healthchecker.Name()).Set(float64(healthchecker.BlockNumber()))
h.metricRPCProviderStatus.WithLabelValues(healthchecker.Name(), "healthy").Set(float64(healthy))
h.metricRPCProviderStatus.WithLabelValues(healthchecker.Name(), "tainted").Set(float64(tainted))
}
Expand Down

0 comments on commit 366d575

Please sign in to comment.