Skip to content

Commit

Permalink
Refactor zetaclient metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Feb 20, 2024
1 parent e72da59 commit be297dd
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 256 deletions.
10 changes: 1 addition & 9 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func GenerateTss(logger zerolog.Logger,
priKey secp256k1.PrivKey,
ts *metrics.TelemetryServer,
tssHistoricalList []observertypes.TSS,
metrics *metrics.Metrics,
tssPassword string,
hotkeyPassword string) (*mc.TSS, error) {
keygenLogger := logger.With().Str("module", "keygen").Logger()
Expand All @@ -49,7 +48,6 @@ func GenerateTss(logger zerolog.Logger,
cfg,
zetaBridge,
tssHistoricalList,
metrics,
bitcoinChainID,
tssPassword,
hotkeyPassword,
Expand Down Expand Up @@ -124,7 +122,6 @@ func GenerateTss(logger zerolog.Logger,
CurrentPubkey: tss.CurrentPubkey,
Signers: tss.Signers,
CoreBridge: nil,
Metrics: nil,
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
Expand Down Expand Up @@ -173,12 +170,7 @@ func keygenTss(cfg *config.Config, tss *mc.TSS, keygenLogger zerolog.Logger) err

// Increment Blame counter
for _, node := range res.Blame.BlameNodes {
counter, err := tss.Metrics.GetPromCounter(node.Pubkey)
if err != nil {
keygenLogger.Error().Err(err).Msgf("error getting counter: %s", node.Pubkey)
continue
}
counter.Inc()
metrics.TssNodeBlamePerPubKey.WithLabelValues(node.Pubkey).Inc()
}

keygenLogger.Info().Msgf("keygen posted blame data tx hash: %s", zetaHash)
Expand Down
12 changes: 6 additions & 6 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
"github.com/zeta-chain/zetacore/zetaclient/config"
metrics2 "github.com/zeta-chain/zetacore/zetaclient/metrics"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
)

type Multiaddr = core.Multiaddr
Expand Down Expand Up @@ -73,7 +73,7 @@ func start(_ *cobra.Command, _ []string) error {
waitForZetaCore(cfg, startLogger)
startLogger.Info().Msgf("ZetaCore is ready , Trying to connect to %s", cfg.Peer)

telemetryServer := metrics2.NewTelemetryServer()
telemetryServer := metrics.NewTelemetryServer()
go func() {
err := telemetryServer.Start()
if err != nil {
Expand Down Expand Up @@ -153,7 +153,7 @@ func start(_ *cobra.Command, _ []string) error {
}
}

metrics, err := metrics2.NewMetrics()
metrics, err := metrics.NewMetrics()
if err != nil {
log.Error().Err(err).Msg("NewMetrics")
return err
Expand All @@ -167,7 +167,7 @@ func start(_ *cobra.Command, _ []string) error {
}

telemetryServer.SetIPAddress(cfg.PublicIP)
tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer, tssHistoricalList, metrics, tssKeyPass, hotkeyPass)
tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer, tssHistoricalList, tssKeyPass, hotkeyPass)
if err != nil {
return err
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func start(_ *cobra.Command, _ []string) error {
dbpath := filepath.Join(userDir, ".zetaclient/chainobserver")

// CreateChainClientMap : This creates a map of all chain clients . Each chain client is responsible for listening to events on the chain and processing them
chainClientMap, err := CreateChainClientMap(zetaBridge, tss, dbpath, metrics, masterLogger, cfg, telemetryServer)
chainClientMap, err := CreateChainClientMap(zetaBridge, tss, dbpath, masterLogger, cfg, telemetryServer)
if err != nil {
startLogger.Err(err).Msg("CreateSignerMap")
return err
Expand All @@ -249,7 +249,7 @@ func start(_ *cobra.Command, _ []string) error {
}

// CreateCoreObserver : Core observer wraps the zetacore bridge and adds the client and signer maps to it . This is the high level object used for CCTX interactions
mo1 := mc.NewCoreObserver(zetaBridge, signerMap, chainClientMap, metrics, masterLogger, cfg, telemetryServer)
mo1 := mc.NewCoreObserver(zetaBridge, signerMap, chainClientMap, masterLogger, cfg, telemetryServer)
mo1.MonitorCore()

// start zeta supply checker
Expand Down
5 changes: 2 additions & 3 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func CreateChainClientMap(
bridge *zetabridge.ZetaCoreBridge,
tss interfaces.TSSSigner,
dbpath string,
metrics *metrics.Metrics,
logger zerolog.Logger,
cfg *config.Config,
ts *metrics.TelemetryServer,
Expand All @@ -99,7 +98,7 @@ func CreateChainClientMap(
if evmConfig.Chain.IsZetaChain() {
continue
}
co, err := evm.NewEVMChainClient(bridge, tss, dbpath, metrics, logger, cfg, *evmConfig, ts)
co, err := evm.NewEVMChainClient(bridge, tss, dbpath, logger, cfg, *evmConfig, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
continue
Expand All @@ -109,7 +108,7 @@ func CreateChainClientMap(
// BTC client
btcChain, btcConfig, enabled := cfg.GetBTCConfig()
if enabled {
co, err := bitcoin.NewBitcoinClient(btcChain, bridge, tss, dbpath, metrics, logger, btcConfig, ts)
co, err := bitcoin.NewBitcoinClient(btcChain, bridge, tss, dbpath, logger, btcConfig, ts)
if err != nil {
logger.Error().Err(err).Msgf("NewBitcoinClient error for chain %s", btcChain.String())

Expand Down
17 changes: 4 additions & 13 deletions zetaclient/bitcoin/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
metricsPkg "github.com/zeta-chain/zetacore/zetaclient/metrics"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
clienttypes "github.com/zeta-chain/zetacore/zetaclient/types"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
Expand All @@ -54,8 +54,6 @@ type BTCLog struct {
// BTCChainClient represents a chain configuration for Bitcoin
// Filled with above constants depending on chain
type BTCChainClient struct {
*metricsPkg.ChainMetrics

chain common.Chain
netParams *chaincfg.Params
rpcClient interfaces.BTCRPCClient
Expand All @@ -76,7 +74,7 @@ type BTCChainClient struct {
db *gorm.DB
stop chan struct{}
logger BTCLog
ts *metricsPkg.TelemetryServer
ts *metrics.TelemetryServer

BlockCache *lru.Cache
}
Expand Down Expand Up @@ -136,14 +134,12 @@ func NewBitcoinClient(
bridge interfaces.ZetaCoreBridger,
tss interfaces.TSSSigner,
dbpath string,
metrics *metricsPkg.Metrics,
logger zerolog.Logger,
btcCfg config.BTCConfig,
ts *metricsPkg.TelemetryServer,
ts *metrics.TelemetryServer,
) (*BTCChainClient, error) {
ob := BTCChainClient{
ChainMetrics: metricsPkg.NewChainMetrics(chain.ChainName.String(), metrics),
ts: ts,
ts: ts,
}
ob.stop = make(chan struct{})
ob.chain = chain
Expand Down Expand Up @@ -195,11 +191,6 @@ func NewBitcoinClient(
return nil, err
}

err = ob.RegisterPromGauge(metricsPkg.PendingTxs, "Number of pending transactions")
if err != nil {
return nil, err
}

//Load btc chain client DB
err = ob.loadDB(dbpath)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions zetaclient/bitcoin/bitcoin_client_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func (suite *BitcoinClientTestSuite) SetupTest() {
tss := interfaces.TestSigner{
PrivKey: privateKey,
}
//client, err := NewBitcoinClient(common.BtcTestNetChain(), nil, tss, "", nil)
client, err := NewBitcoinClient(common.BtcRegtestChain(), nil, tss, "/tmp", nil, log.Logger, config.BTCConfig{}, nil)
client, err := NewBitcoinClient(common.BtcRegtestChain(), nil, tss, "/tmp", log.Logger, config.BTCConfig{}, nil)
suite.Require().NoError(err)
suite.BitcoinChainClient = client
skBytes, err := hex.DecodeString(skHex)
Expand Down
54 changes: 10 additions & 44 deletions zetaclient/evm/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/zeta-chain/zetacore/zetaclient/interfaces"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
"github.com/zeta-chain/zetacore/zetaclient/zetabridge"

"github.com/ethereum/go-ethereum"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
metricsPkg "github.com/zeta-chain/zetacore/zetaclient/metrics"
clienttypes "github.com/zeta-chain/zetacore/zetaclient/types"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
Expand Down Expand Up @@ -73,7 +73,6 @@ const (
// ChainClient represents the chain configuration for an EVM chain
// Filled with above constants depending on chain
type ChainClient struct {
*metricsPkg.ChainMetrics
chain common.Chain
evmClient interfaces.EVMRPCClient
zetaClient interfaces.ZetaCoreBridger
Expand All @@ -96,29 +95,24 @@ type ChainClient struct {
logger Log
cfg *config.Config
params observertypes.ChainParams
ts *metricsPkg.TelemetryServer

blockCache *lru.Cache
blockCacheV3 *lru.Cache // blockCacheV3 caches blocks containing type-3 (BlobTxType) transactions
headerCache *lru.Cache
ts *metrics.TelemetryServer
blockCache *lru.Cache
blockCacheV3 *lru.Cache // blockCacheV3 caches blocks containing type-3 (BlobTxType) transactions
headerCache *lru.Cache
}

var _ interfaces.ChainClient = (*ChainClient)(nil)

// NewEVMChainClient returns a new configuration based on supplied target chain
func NewEVMChainClient(
bridge interfaces.ZetaCoreBridger,
tss interfaces.TSSSigner,
dbpath string,
metrics *metricsPkg.Metrics,
logger zerolog.Logger,
cfg *config.Config,
evmCfg config.EVMConfig,
ts *metricsPkg.TelemetryServer,
ts *metrics.TelemetryServer,
) (*ChainClient, error) {
ob := ChainClient{
ChainMetrics: metricsPkg.NewChainMetrics(evmCfg.Chain.ChainName.String(), metrics),
ts: ts,
ts: ts,
}
chainLogger := logger.With().Str("chain", evmCfg.Chain.ChainName.String()).Logger()
ob.logger = Log{
Expand Down Expand Up @@ -173,20 +167,6 @@ func NewEVMChainClient(
return nil, err
}

// create metric counters
err = ob.RegisterPromCounter("rpc_getFilterLogs_count", "Number of getLogs")
if err != nil {
return nil, err
}
err = ob.RegisterPromCounter("rpc_getBlockByNumber_count", "Number of getBlockByNumber")
if err != nil {
return nil, err
}
err = ob.RegisterPromGauge(metricsPkg.PendingTxs, "Number of pending transactions")
if err != nil {
return nil, err
}

err = ob.LoadDB(dbpath, ob.chain)
if err != nil {
return nil, err
Expand Down Expand Up @@ -941,11 +921,7 @@ func (ob *ChainClient) observeInTX(sampledLogger zerolog.Logger) error {
ob.SetLastBlockHeight(blockNumber)

// increment prom counter
counter, err := ob.GetPromCounter("rpc_getBlockByNumber_count")
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("GetPromCounter:")
}
counter.Inc()
metrics.GetBlockByNumberPerChain.WithLabelValues(ob.chain.ChainName.String()).Inc()

// skip if current height is too low
if blockNumber < ob.GetChainParams().ConfirmationCount {
Expand Down Expand Up @@ -1037,12 +1013,7 @@ func (ob *ChainClient) observeZetaSent(startBlock, toBlock uint64) uint64 {
})

// increment prom counter
cnt, err := ob.GetPromCounter("rpc_getFilterLogs_count")
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("GetPromCounter:")
} else {
cnt.Inc()
}
metrics.GetFilterLogsPerChain.WithLabelValues(ob.chain.ChainName.String()).Inc()

// post to zetabridge
beingScanned := uint64(0)
Expand Down Expand Up @@ -1114,12 +1085,7 @@ func (ob *ChainClient) observeERC20Deposited(startBlock, toBlock uint64) uint64
})

// increment prom counter
cnt, err := ob.GetPromCounter("rpc_getFilterLogs_count")
if err != nil {
ob.logger.ExternalChainWatcher.Error().Err(err).Msg("GetPromCounter:")
} else {
cnt.Inc()
}
metrics.GetFilterLogsPerChain.WithLabelValues(ob.chain.ChainName.String()).Inc()

// post to zetabridge
guard := make(map[string]bool) // guard against multiple events in the same tx
Expand Down
3 changes: 0 additions & 3 deletions zetaclient/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/zeta-chain/go-tss/blame"
"github.com/zeta-chain/zetacore/common"
Expand All @@ -40,8 +39,6 @@ type ChainClient interface {
IsSendOutTxProcessed(sendHash string, nonce uint64, cointype common.CoinType, logger zerolog.Logger) (bool, bool, error)
SetChainParams(observertypes.ChainParams)
GetChainParams() observertypes.ChainParams
GetPromGauge(name string) (prometheus.Gauge, error)
GetPromCounter(name string) (prometheus.Counter, error)
GetTxID(nonce uint64) string
ExternalChainWatcherForNewInboundTrackerSuggestions()
}
Expand Down
51 changes: 0 additions & 51 deletions zetaclient/metrics/chainmetrics.go

This file was deleted.

Loading

0 comments on commit be297dd

Please sign in to comment.