From ea1da8baa62f8d4e373235e3d4b8ef9d75375bd4 Mon Sep 17 00:00:00 2001 From: skosito Date: Mon, 26 Feb 2024 17:04:14 +0000 Subject: [PATCH] refactor: zetaclient metrics (#1783) * Refactor zetaclient metrics * Fix blame counter init * Add changelog entry * Add unreleased to changelog * Remove blank line --- changelog.md | 3 + cmd/zetaclientd/keygen_tss.go | 10 +-- cmd/zetaclientd/start.go | 12 +-- cmd/zetaclientd/utils.go | 5 +- zetaclient/bitcoin/bitcoin_client.go | 17 +---- zetaclient/bitcoin/bitcoin_client_rpc_test.go | 3 +- zetaclient/evm/evm_client.go | 54 +++----------- zetaclient/interfaces/interfaces.go | 3 - zetaclient/metrics/chainmetrics.go | 51 ------------- zetaclient/metrics/metrics.go | 73 ++++++++----------- zetaclient/metrics/metrics_test.go | 6 +- zetaclient/tss/tss_signer.go | 40 ++-------- zetaclient/zetacore_observer.go | 49 +------------ 13 files changed, 73 insertions(+), 253 deletions(-) delete mode 100644 zetaclient/metrics/chainmetrics.go diff --git a/changelog.md b/changelog.md index 9116cc3651..e16dc3acf2 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,9 @@ ## Unreleased +### Refactor +* [1783](https://github.com/zeta-chain/node/pull/1783) - refactor zetaclient metrics naming and structure + ### Tests * [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker diff --git a/cmd/zetaclientd/keygen_tss.go b/cmd/zetaclientd/keygen_tss.go index 215f680a99..119a547a3a 100644 --- a/cmd/zetaclientd/keygen_tss.go +++ b/cmd/zetaclientd/keygen_tss.go @@ -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() @@ -49,7 +48,6 @@ func GenerateTss(logger zerolog.Logger, cfg, zetaBridge, tssHistoricalList, - metrics, bitcoinChainID, tssPassword, hotkeyPassword, @@ -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 @@ -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) diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index e22d86b356..911dd9a3dc 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -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 @@ -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 { @@ -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 @@ -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 } @@ -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 @@ -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 diff --git a/cmd/zetaclientd/utils.go b/cmd/zetaclientd/utils.go index 87c009c11b..648f592a56 100644 --- a/cmd/zetaclientd/utils.go +++ b/cmd/zetaclientd/utils.go @@ -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, @@ -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 @@ -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()) diff --git a/zetaclient/bitcoin/bitcoin_client.go b/zetaclient/bitcoin/bitcoin_client.go index b0e409b756..7b9c18becb 100644 --- a/zetaclient/bitcoin/bitcoin_client.go +++ b/zetaclient/bitcoin/bitcoin_client.go @@ -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" @@ -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 @@ -76,7 +74,7 @@ type BTCChainClient struct { db *gorm.DB stop chan struct{} logger BTCLog - ts *metricsPkg.TelemetryServer + ts *metrics.TelemetryServer BlockCache *lru.Cache } @@ -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 @@ -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 { diff --git a/zetaclient/bitcoin/bitcoin_client_rpc_test.go b/zetaclient/bitcoin/bitcoin_client_rpc_test.go index 83ba9b426c..8c5ffd43b1 100644 --- a/zetaclient/bitcoin/bitcoin_client_rpc_test.go +++ b/zetaclient/bitcoin/bitcoin_client_rpc_test.go @@ -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) diff --git a/zetaclient/evm/evm_client.go b/zetaclient/evm/evm_client.go index db13df1f6f..5d4defb0d3 100644 --- a/zetaclient/evm/evm_client.go +++ b/zetaclient/evm/evm_client.go @@ -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" @@ -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" @@ -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 @@ -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{ @@ -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 @@ -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 { @@ -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) @@ -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 diff --git a/zetaclient/interfaces/interfaces.go b/zetaclient/interfaces/interfaces.go index 2d4ecff7c6..088016ef39 100644 --- a/zetaclient/interfaces/interfaces.go +++ b/zetaclient/interfaces/interfaces.go @@ -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" @@ -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() } diff --git a/zetaclient/metrics/chainmetrics.go b/zetaclient/metrics/chainmetrics.go deleted file mode 100644 index df721d9d43..0000000000 --- a/zetaclient/metrics/chainmetrics.go +++ /dev/null @@ -1,51 +0,0 @@ -package metrics - -import ( - "errors" - - "github.com/prometheus/client_golang/prometheus" -) - -const MetricGroup = "zetaclient" - -type ChainMetrics struct { - chain string - metrics *Metrics -} - -func NewChainMetrics(chain string, metrics *Metrics) *ChainMetrics { - return &ChainMetrics{ - chain, - metrics, - } -} - -func (m *ChainMetrics) GetPromGauge(name string) (prometheus.Gauge, error) { - gauge, found := Gauges[m.buildGroupName(name)] - if !found { - return nil, errors.New("gauge not found") - } - return gauge, nil -} - -func (m *ChainMetrics) RegisterPromGauge(name string, help string) error { - gaugeName := m.buildGroupName(name) - return m.metrics.RegisterGauge(gaugeName, help) -} - -func (m *ChainMetrics) GetPromCounter(name string) (prometheus.Counter, error) { - if cnt, found := Counters[m.buildGroupName(name)]; found { - return cnt, nil - } - return nil, errors.New("counter not found") - -} - -func (m *ChainMetrics) RegisterPromCounter(name string, help string) error { - cntName := m.buildGroupName(name) - return m.metrics.RegisterCounter(cntName, help) -} - -func (m *ChainMetrics) buildGroupName(name string) string { - return MetricGroup + "_" + name + "_" + m.chain -} diff --git a/zetaclient/metrics/metrics.go b/zetaclient/metrics/metrics.go index a3a78564ce..a99db9f760 100644 --- a/zetaclient/metrics/metrics.go +++ b/zetaclient/metrics/metrics.go @@ -2,11 +2,12 @@ package metrics import ( "context" - "fmt" "net/http" "time" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/zerolog/log" ) @@ -15,19 +16,36 @@ type Metrics struct { s *http.Server } -type MetricName int - -const ( - //GAUGE_PENDING_TX MetricName = iota - // - //COUNTER_NUM_RPCS - PendingTxs = "pending_txs" -) - var ( - Counters = map[string]prometheus.Counter{} - - Gauges = map[string]prometheus.Gauge{} + PendingTxsPerChain = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "zetaclient", + Name: "pending_txs_total", + Help: "Number of pending transactions per chain", + }, []string{"chain"}) + + GetFilterLogsPerChain = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: "zetaclient", + Name: "rpc_getFilterLogs_count", + Help: "Count of getLogs per chain", + }, []string{"chain"}) + + GetBlockByNumberPerChain = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: "zetaclient", + Name: "rpc_getBlockByNumber_count", + Help: "Count of getLogs per chain", + }, []string{"chain"}) + + TssNodeBlamePerPubKey = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: "zetaclient", + Name: "tss_node_blame_count", + Help: "Tss node blame counter per pubkey", + }, []string{"pubkey"}) + + HotKeyBurnRate = promauto.NewGauge(prometheus.GaugeOpts{ + Namespace: "zetaclient", + Name: "hotkey_burn_rate", + Help: "Fee burn rate of the hotkey", + }) ) func NewMetrics() (*Metrics, error) { @@ -43,7 +61,7 @@ func NewMetrics() (*Metrics, error) { ) s := &http.Server{ - Addr: fmt.Sprintf(":8886"), + Addr: ":8886", Handler: server, ReadTimeout: 5 * time.Second, ReadHeaderTimeout: 5 * time.Second, @@ -54,33 +72,6 @@ func NewMetrics() (*Metrics, error) { }, nil } -func (m *Metrics) RegisterCounter(name string, help string) error { - if _, found := Counters[name]; found { - return fmt.Errorf("counter %s already registered", name) - } - counter := prometheus.NewCounter(prometheus.CounterOpts{ - Name: name, - Help: help, - }) - prometheus.MustRegister(counter) - Counters[name] = counter - return nil -} - -func (m *Metrics) RegisterGauge(name string, help string) error { - if _, found := Gauges[name]; found { - return fmt.Errorf("gauge %s already registered", name) - } - - var gauge = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: name, - Help: help, - }) - prometheus.MustRegister(gauge) - Gauges[name] = gauge - return nil -} - func (m *Metrics) Start() { log.Info().Msg("metrics server starting") go func() { diff --git a/zetaclient/metrics/metrics_test.go b/zetaclient/metrics/metrics_test.go index ef2aaa760c..f40001bbee 100644 --- a/zetaclient/metrics/metrics_test.go +++ b/zetaclient/metrics/metrics_test.go @@ -24,9 +24,9 @@ func (ms *MetricsSuite) SetUpSuite(c *C) { } func (ms *MetricsSuite) TestMetrics(c *C) { - err := ms.m.RegisterCounter("cnt1", "help to cnt1") - c.Assert(err, IsNil) - Counters["cnt1"].Inc() + GetFilterLogsPerChain.WithLabelValues("chain1").Inc() + GetFilterLogsPerChain.WithLabelValues("chain2").Inc() + GetFilterLogsPerChain.WithLabelValues("chain2").Inc() time.Sleep(1 * time.Second) res, err := http.Get("http://127.0.0.1:8886/metrics") c.Assert(err, IsNil) diff --git a/zetaclient/tss/tss_signer.go b/zetaclient/tss/tss_signer.go index 8fba8315f3..00bdd43d6c 100644 --- a/zetaclient/tss/tss_signer.go +++ b/zetaclient/tss/tss_signer.go @@ -32,7 +32,7 @@ import ( zcommon "github.com/zeta-chain/zetacore/common/cosmos" observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient/config" - zetametrics "github.com/zeta-chain/zetacore/zetaclient/metrics" + "github.com/zeta-chain/zetacore/zetaclient/metrics" ) const ( @@ -73,7 +73,6 @@ type TSS struct { logger zerolog.Logger Signers []string CoreBridge interfaces.ZetaCoreBridger - Metrics *zetametrics.ChainMetrics // TODO: support multiple Bitcoin network, not just one network // https://github.com/zeta-chain/node/issues/1397 @@ -88,7 +87,6 @@ func NewTSS( cfg *config.Config, bridge interfaces.ZetaCoreBridger, tssHistoricalList []observertypes.TSS, - metrics *zetametrics.Metrics, bitcoinChainID int64, tssPassword string, hotkeyPassword string, @@ -118,12 +116,13 @@ func NewTSS( if err != nil { bridge.GetLogger().Error().Err(err).Msg("VerifyKeysharesForPubkeys fail") } - err = newTss.RegisterMetrics(metrics) + keygenRes, err := newTss.CoreBridge.GetKeyGen() if err != nil { - bridge.GetLogger().Err(err).Msg("tss.RegisterMetrics") return nil, err } - + for _, key := range keygenRes.GranteePubkeys { + metrics.TssNodeBlamePerPubKey.WithLabelValues(key).Inc() + } return &newTss, nil } @@ -224,12 +223,7 @@ func (tss *TSS) Sign(digest []byte, height uint64, nonce uint64, chain *common.C // Increment Blame counter for _, node := range ksRes.Blame.BlameNodes { - counter, err := tss.Metrics.GetPromCounter(node.Pubkey) - if err != nil { - log.Error().Err(err).Msgf("error getting counter: %s", node.Pubkey) - continue - } - counter.Inc() + metrics.TssNodeBlamePerPubKey.WithLabelValues(node.Pubkey).Inc() } } signature := ksRes.Signatures @@ -299,12 +293,7 @@ func (tss *TSS) SignBatch(digests [][]byte, height uint64, nonce uint64, chain * // Increment Blame counter for _, node := range ksRes.Blame.BlameNodes { - counter, err := tss.Metrics.GetPromCounter(node.Pubkey) - if err != nil { - log.Error().Err(err).Msgf("error getting counter: %s", node.Pubkey) - continue - } - counter.Inc() + metrics.TssNodeBlamePerPubKey.WithLabelValues(node.Pubkey).Inc() } } @@ -427,21 +416,6 @@ func (tss *TSS) InsertPubKey(pk string) error { return nil } -func (tss *TSS) RegisterMetrics(metrics *zetametrics.Metrics) error { - tss.Metrics = zetametrics.NewChainMetrics("tss", metrics) - keygenRes, err := tss.CoreBridge.GetKeyGen() - if err != nil { - return err - } - for _, key := range keygenRes.GranteePubkeys { - err := tss.Metrics.RegisterPromCounter(key, "tss node blame counter") - if err != nil { - return err - } - } - return nil -} - func (tss *TSS) VerifyKeysharesForPubkeys(tssList []observertypes.TSS, granteePubKey32 string) error { for _, t := range tssList { if wasNodePartOfTss(granteePubKey32, t.TssParticipantList) { diff --git a/zetaclient/zetacore_observer.go b/zetaclient/zetacore_observer.go index d37e2967cf..441081e34d 100644 --- a/zetaclient/zetacore_observer.go +++ b/zetaclient/zetacore_observer.go @@ -7,25 +7,21 @@ import ( "github.com/zeta-chain/zetacore/zetaclient/bitcoin" "github.com/zeta-chain/zetacore/zetaclient/interfaces" + "github.com/zeta-chain/zetacore/zetaclient/metrics" "github.com/zeta-chain/zetacore/zetaclient/outtxprocessor" observertypes "github.com/zeta-chain/zetacore/x/observer/types" sdkmath "cosmossdk.io/math" - "github.com/pkg/errors" - prom "github.com/prometheus/client_golang/prometheus" "github.com/rs/zerolog" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" "github.com/zeta-chain/zetacore/zetaclient/config" - "github.com/zeta-chain/zetacore/zetaclient/metrics" ) const ( - MaxLookaheadNonce = 120 - OutboundTxSignCount = "zetaclient_Outbound_tx_sign_count" - HotKeyBurnRate = "zetaclient_hotkey_burn_rate" + MaxLookaheadNonce = 120 ) type ZetaCoreLog struct { @@ -38,7 +34,6 @@ type CoreObserver struct { bridge interfaces.ZetaCoreBridger signerMap map[common.Chain]interfaces.ChainSigner clientMap map[common.Chain]interfaces.ChainClient - metrics *metrics.Metrics logger ZetaCoreLog cfg *config.Config ts *metrics.TelemetryServer @@ -51,7 +46,6 @@ func NewCoreObserver( bridge interfaces.ZetaCoreBridger, signerMap map[common.Chain]interfaces.ChainSigner, clientMap map[common.Chain]interfaces.ChainClient, - metrics *metrics.Metrics, logger zerolog.Logger, cfg *config.Config, ts *metrics.TelemetryServer, @@ -73,16 +67,7 @@ func NewCoreObserver( co.signerMap = signerMap co.clientMap = clientMap - co.metrics = metrics co.logger.ChainLogger.Info().Msg("starting core observer") - err := metrics.RegisterCounter(OutboundTxSignCount, "number of Outbound tx signed") - if err != nil { - co.logger.ChainLogger.Error().Err(err).Msg("error registering counter") - } - err = metrics.RegisterGauge(HotKeyBurnRate, "Fee burn rate of the hotkey") - if err != nil { - co.logger.ChainLogger.Error().Err(err).Msg("error registering gauge") - } balance, err := bridge.GetZetaHotKeyBalance() if err != nil { co.logger.ChainLogger.Error().Err(err).Msg("error getting last balance of the hot key") @@ -96,22 +81,6 @@ func (co *CoreObserver) Config() *config.Config { return co.cfg } -func (co *CoreObserver) GetPromCounter(name string) (prom.Counter, error) { - cnt, found := metrics.Counters[name] - if !found { - return nil, errors.New("counter not found") - } - return cnt, nil -} - -func (co *CoreObserver) GetPromGauge(name string) (prom.Gauge, error) { - gauge, found := metrics.Gauges[name] - if !found { - return nil, errors.New("gauge not found") - } - return gauge, nil -} - func (co *CoreObserver) MonitorCore() { myid := co.bridge.GetKeys().GetAddress() co.logger.ZetaChainWatcher.Info().Msgf("Starting Send Scheduler for %s", myid) @@ -170,12 +139,7 @@ func (co *CoreObserver) startCctxScheduler() { } // Set Current Hot key burn rate - gauge, err := co.GetPromGauge(HotKeyBurnRate) - if err != nil { - co.logger.ZetaChainWatcher.Error().Err(err).Msgf("scheduleCctxEVM: failed to get prometheus gauge: %s for observer", metrics.PendingTxs) - continue - } // Gauge only takes float values - gauge.Set(float64(co.ts.HotKeyBurnRate.GetBurnRate().Int64())) + metrics.HotKeyBurnRate.Set(float64(co.ts.HotKeyBurnRate.GetBurnRate().Int64())) // schedule keysign for pending cctxs on each chain supportedChains := co.Config().GetEnabledChains() @@ -196,12 +160,7 @@ func (co *CoreObserver) startCctxScheduler() { continue } // Set Pending transactions prometheus gauge - gauge, err := ob.GetPromGauge(metrics.PendingTxs) - if err != nil { - co.logger.ZetaChainWatcher.Error().Err(err).Msgf("scheduleCctxEVM: failed to get prometheus gauge: %s for chain %d", metrics.PendingTxs, c.ChainId) - continue - } - gauge.Set(float64(totalPending)) + metrics.PendingTxsPerChain.WithLabelValues(c.ChainName.String()).Set(float64(totalPending)) // #nosec G701 range is verified zetaHeight := uint64(bn)