From 7a02e10950c075d73e12ae62abaa406a855eda54 Mon Sep 17 00:00:00 2001 From: Alexxxxxx <118710506+alexgao001@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:38:34 +0800 Subject: [PATCH] feat: add metrics for relayer (#24) * add metrics for relayer * re-format * renaming --- app/app.go | 22 ++- assembler/bsc_assembler.go | 14 +- assembler/greenfield_assembler.go | 17 +- config/config.go | 6 +- integrationtest/config/config_test.json | 2 +- listener/bsc_listener.go | 14 +- listener/greenfield_listener.go | 12 +- metric/metric_service.go | 224 ++++++++++++++++++++++++ 8 files changed, 288 insertions(+), 23 deletions(-) create mode 100644 metric/metric_service.go diff --git a/app/app.go b/app/app.go index c035e71..b12654f 100644 --- a/app/app.go +++ b/app/app.go @@ -13,13 +13,15 @@ import ( "github.com/bnb-chain/greenfield-relayer/db/model" "github.com/bnb-chain/greenfield-relayer/executor" "github.com/bnb-chain/greenfield-relayer/listener" + "github.com/bnb-chain/greenfield-relayer/metric" "github.com/bnb-chain/greenfield-relayer/relayer" "github.com/bnb-chain/greenfield-relayer/vote" ) type App struct { - BSCRelayer *relayer.BSCRelayer - GnfdRelayer *relayer.GreenfieldRelayer + BSCRelayer *relayer.BSCRelayer + GnfdRelayer *relayer.GreenfieldRelayer + metricService *metric.MetricService } func NewApp(cfg *config.Config) *App { @@ -44,9 +46,11 @@ func NewApp(cfg *config.Config) *App { greenfieldExecutor.SetBSCExecutor(bscExecutor) bscExecutor.SetGreenfieldExecutor(greenfieldExecutor) + metricService := metric.NewMetricService(cfg) + // listeners - greenfieldListener := listener.NewGreenfieldListener(cfg, greenfieldExecutor, bscExecutor, daoManager) - bscListener := listener.NewBSCListener(cfg, bscExecutor, greenfieldExecutor, daoManager) + greenfieldListener := listener.NewGreenfieldListener(cfg, greenfieldExecutor, bscExecutor, daoManager, metricService) + bscListener := listener.NewBSCListener(cfg, bscExecutor, greenfieldExecutor, daoManager, metricService) // vote signer signer := vote.NewVoteSigner(ethcommon.Hex2Bytes(cfg.GreenfieldConfig.BlsPrivateKey)) @@ -56,20 +60,22 @@ func NewApp(cfg *config.Config) *App { bscVoteProcessor := vote.NewBSCVoteProcessor(cfg, daoManager, signer, bscExecutor) // assemblers - greenfieldAssembler := assembler.NewGreenfieldAssembler(cfg, greenfieldExecutor, daoManager, bscExecutor) - bscAssembler := assembler.NewBSCAssembler(cfg, bscExecutor, daoManager, greenfieldExecutor) + greenfieldAssembler := assembler.NewGreenfieldAssembler(cfg, greenfieldExecutor, daoManager, bscExecutor, metricService) + bscAssembler := assembler.NewBSCAssembler(cfg, bscExecutor, daoManager, greenfieldExecutor, metricService) // relayers gnfdRelayer := relayer.NewGreenfieldRelayer(greenfieldListener, greenfieldExecutor, bscExecutor, greenfieldVoteProcessor, greenfieldAssembler) bscRelayer := relayer.NewBSCRelayer(bscListener, greenfieldExecutor, bscExecutor, bscVoteProcessor, bscAssembler) return &App{ - BSCRelayer: bscRelayer, - GnfdRelayer: gnfdRelayer, + BSCRelayer: bscRelayer, + GnfdRelayer: gnfdRelayer, + metricService: metricService, } } func (a *App) Start() { a.GnfdRelayer.Start() a.BSCRelayer.Start() + a.metricService.Start() } diff --git a/assembler/bsc_assembler.go b/assembler/bsc_assembler.go index cb1ad9e..88be3b9 100644 --- a/assembler/bsc_assembler.go +++ b/assembler/bsc_assembler.go @@ -3,6 +3,7 @@ package assembler import ( "encoding/hex" "fmt" + "github.com/bnb-chain/greenfield-relayer/metric" "time" "github.com/bnb-chain/greenfield-relayer/common" @@ -23,15 +24,17 @@ type BSCAssembler struct { bscExecutor *executor.BSCExecutor daoManager *dao.DaoManager blsPubKey string + metricService *metric.MetricService } -func NewBSCAssembler(cfg *config.Config, executor *executor.BSCExecutor, dao *dao.DaoManager, greenfieldExecutor *executor.GreenfieldExecutor) *BSCAssembler { +func NewBSCAssembler(cfg *config.Config, executor *executor.BSCExecutor, dao *dao.DaoManager, greenfieldExecutor *executor.GreenfieldExecutor, ms *metric.MetricService) *BSCAssembler { return &BSCAssembler{ config: cfg, bscExecutor: executor, daoManager: dao, greenfieldExecutor: greenfieldExecutor, blsPubKey: hex.EncodeToString(util.BlsPubKeyFromPrivKeyStr(cfg.GreenfieldConfig.BlsPrivateKey)), + metricService: ms, } } @@ -55,6 +58,7 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error { return err } isInturnRelyer := inturnRelayer.BlsPubKey == a.blsPubKey + a.metricService.SetGnfdInturnRelayerMetrics(isInturnRelyer, inturnRelayer.RelayInterval.Start, inturnRelayer.RelayInterval.End) var startSequence uint64 if isInturnRelyer { seq, err := a.daoManager.SequenceDao.GetByChannelId(uint8(channelId)) @@ -81,6 +85,12 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error { } } logging.Logger.Debug("bsc relay as in-turn relayer") + a.metricService.SetNextSequenceForChannelFromDB(uint8(channelId), startSequence) + seqFromChain, err := a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry() + if err != nil { + return err + } + a.metricService.SetNextSequenceForChannelFromChain(uint8(channelId), seqFromChain) } else { // non-inturn relayer retries every 10 second, gets the sequence from chain time.Sleep(time.Duration(a.config.RelayConfig.GreenfieldSequenceUpdateLatency) * time.Second) @@ -162,6 +172,7 @@ func (a *BSCAssembler) processPkgs(pkgs []*model.BscRelayPackage, channelId uint for _, p := range pkgs { pkgIds = append(pkgIds, p.Id) } + a.metricService.SetBSCProcessedBlockHeight(pkgs[0].Height) if !isInturnRelyer { if err = a.daoManager.BSCDao.UpdateBatchPackagesClaimedTxHash(pkgIds, txHash); err != nil { return err @@ -176,6 +187,5 @@ func (a *BSCAssembler) processPkgs(pkgs []*model.BscRelayPackage, channelId uint if err = a.daoManager.SequenceDao.Upsert(channelId, sequence+1); err != nil { return err } - return nil } diff --git a/assembler/greenfield_assembler.go b/assembler/greenfield_assembler.go index 2b7bd12..182c114 100644 --- a/assembler/greenfield_assembler.go +++ b/assembler/greenfield_assembler.go @@ -12,6 +12,7 @@ import ( "github.com/bnb-chain/greenfield-relayer/db/model" "github.com/bnb-chain/greenfield-relayer/executor" "github.com/bnb-chain/greenfield-relayer/logging" + "github.com/bnb-chain/greenfield-relayer/metric" "github.com/bnb-chain/greenfield-relayer/types" "github.com/bnb-chain/greenfield-relayer/util" "github.com/bnb-chain/greenfield-relayer/vote" @@ -23,15 +24,18 @@ type GreenfieldAssembler struct { greenfieldExecutor *executor.GreenfieldExecutor daoManager *dao.DaoManager blsPubKey string + metricService *metric.MetricService } -func NewGreenfieldAssembler(cfg *config.Config, executor *executor.GreenfieldExecutor, dao *dao.DaoManager, bscExecutor *executor.BSCExecutor) *GreenfieldAssembler { +func NewGreenfieldAssembler(cfg *config.Config, executor *executor.GreenfieldExecutor, dao *dao.DaoManager, bscExecutor *executor.BSCExecutor, + ms *metric.MetricService) *GreenfieldAssembler { return &GreenfieldAssembler{ config: cfg, greenfieldExecutor: executor, daoManager: dao, bscExecutor: bscExecutor, blsPubKey: hex.EncodeToString(util.BlsPubKeyFromPrivKeyStr(cfg.GreenfieldConfig.BlsPrivateKey)), + metricService: ms, } } @@ -58,6 +62,7 @@ func (a *GreenfieldAssembler) process(channelId types.ChannelId) error { return err } isInturnRelyer := inturnRelayer.BlsPublicKey == a.blsPubKey + a.metricService.SetBSCInturnRelayerMetrics(isInturnRelyer, inturnRelayer.Start, inturnRelayer.End) var startSequence uint64 if isInturnRelyer { // get next delivered sequence from DB @@ -85,7 +90,12 @@ func (a *GreenfieldAssembler) process(channelId types.ChannelId) error { return err } } - logging.Logger.Debug("gnfd relay as in-turn relayer") + a.metricService.SetNextSequenceForChannelFromDB(uint8(channelId), startSequence) + seqFromChain, err := a.greenfieldExecutor.GetNextDeliverySequenceForChannelWithRetry(channelId) + if err != nil { + return err + } + a.metricService.SetNextSequenceForChannelFromChain(uint8(channelId), seqFromChain) } else { time.Sleep(time.Duration(a.config.RelayConfig.BSCSequenceUpdateLatency) * time.Second) startSequence, err = a.greenfieldExecutor.GetNextDeliverySequenceForChannelWithRetry(channelId) @@ -131,6 +141,7 @@ func (a *GreenfieldAssembler) process(channelId types.ChannelId) error { return err } logging.Logger.Infof("relayed tx with channel id %d and sequence %d ", tx.ChannelId, tx.Sequence) + nonce++ } return nil @@ -157,6 +168,7 @@ func (a *GreenfieldAssembler) processTx(tx *model.GreenfieldRelayTransaction, no return err } logging.Logger.Infof("relayed transaction with channel id %d and sequence %d, get txHash %s", tx.ChannelId, tx.Sequence, txHash) + a.metricService.SetGnfdProcessedBlockHeight(tx.Height) // update next delivery sequence in DB for inturn relayer, for non-inturn relayer, there is enough time for // sequence update, so they can track next start seq from chain @@ -173,7 +185,6 @@ func (a *GreenfieldAssembler) processTx(tx *model.GreenfieldRelayTransaction, no if err = a.daoManager.SequenceDao.Upsert(tx.ChannelId, tx.Sequence+1); err != nil { return err } - return nil } diff --git a/config/config.go b/config/config.go index 79aaf4b..91cb5cf 100644 --- a/config/config.go +++ b/config/config.go @@ -18,12 +18,12 @@ type Config struct { } type AdminConfig struct { - ListenAddr string `json:"listen_addr"` + Port uint16 `json:"port"` } func (cfg *AdminConfig) Validate() { - if cfg.ListenAddr == "" { - panic("listen address should not be empty") + if cfg.Port <= 0 || cfg.Port > 65535 { + panic("port should be within (0, 65535]") } } diff --git a/integrationtest/config/config_test.json b/integrationtest/config/config_test.json index af1a11e..43ad108 100644 --- a/integrationtest/config/config_test.json +++ b/integrationtest/config/config_test.json @@ -54,7 +54,7 @@ "compress": false }, "admin_config": { - "listen_addr": "0.0.0.0:8080" + "port": 8080 }, "db_config": { "dialect": "mysql", diff --git a/listener/bsc_listener.go b/listener/bsc_listener.go index 2429424..2a45abd 100644 --- a/listener/bsc_listener.go +++ b/listener/bsc_listener.go @@ -18,6 +18,7 @@ import ( "github.com/bnb-chain/greenfield-relayer/executor" "github.com/bnb-chain/greenfield-relayer/executor/crosschain" "github.com/bnb-chain/greenfield-relayer/logging" + "github.com/bnb-chain/greenfield-relayer/metric" rtypes "github.com/bnb-chain/greenfield-relayer/types" ) @@ -27,9 +28,10 @@ type BSCListener struct { greenfieldExecutor *executor.GreenfieldExecutor DaoManager *dao.DaoManager crossChainAbi abi.ABI + monitorService *metric.MetricService } -func NewBSCListener(cfg *config.Config, bscExecutor *executor.BSCExecutor, gnfdExecutor *executor.GreenfieldExecutor, dao *dao.DaoManager) *BSCListener { +func NewBSCListener(cfg *config.Config, bscExecutor *executor.BSCExecutor, gnfdExecutor *executor.GreenfieldExecutor, dao *dao.DaoManager, ms *metric.MetricService) *BSCListener { crossChainAbi, err := abi.JSON(strings.NewReader(crosschain.CrosschainMetaData.ABI)) if err != nil { panic("marshal abi error") @@ -40,6 +42,7 @@ func NewBSCListener(cfg *config.Config, bscExecutor *executor.BSCExecutor, gnfdE greenfieldExecutor: gnfdExecutor, DaoManager: dao, crossChainAbi: crossChainAbi, + monitorService: ms, } } @@ -130,14 +133,17 @@ func (l *BSCListener) monitorCrossChainPkgAt(nextHeight uint64, latestPolledBloc relayPkgs = append(relayPkgs, relayPkg) } - return l.DaoManager.BSCDao.SaveBlockAndBatchPackages( + if err := l.DaoManager.BSCDao.SaveBlockAndBatchPackages( &model.BscBlock{ BlockHash: nextHeightBlockHeader.Hash().String(), ParentHash: nextHeightBlockHeader.ParentHash.String(), Height: nextHeight, BlockTime: int64(nextHeightBlockHeader.Time), - }, - relayPkgs) + }, relayPkgs); err != nil { + return err + } + l.monitorService.SetBSCSavedBlockHeight(nextHeight) + return nil } func (l *BSCListener) queryCrossChainLogs(blockHash ethcommon.Hash) ([]types.Log, error) { diff --git a/listener/greenfield_listener.go b/listener/greenfield_listener.go index 581f412..8b558cd 100644 --- a/listener/greenfield_listener.go +++ b/listener/greenfield_listener.go @@ -17,6 +17,7 @@ import ( "github.com/bnb-chain/greenfield-relayer/db/model" "github.com/bnb-chain/greenfield-relayer/executor" "github.com/bnb-chain/greenfield-relayer/logging" + "github.com/bnb-chain/greenfield-relayer/metric" "github.com/bnb-chain/greenfield-relayer/util" ) @@ -25,14 +26,17 @@ type GreenfieldListener struct { greenfieldExecutor *executor.GreenfieldExecutor bscExecutor *executor.BSCExecutor DaoManager *dao.DaoManager + metricService *metric.MetricService } -func NewGreenfieldListener(cfg *config.Config, gnfdExecutor *executor.GreenfieldExecutor, bscExecutor *executor.BSCExecutor, dao *dao.DaoManager) *GreenfieldListener { +func NewGreenfieldListener(cfg *config.Config, gnfdExecutor *executor.GreenfieldExecutor, bscExecutor *executor.BSCExecutor, + dao *dao.DaoManager, ms *metric.MetricService) *GreenfieldListener { return &GreenfieldListener{ config: cfg, greenfieldExecutor: gnfdExecutor, bscExecutor: bscExecutor, DaoManager: dao, + metricService: ms, } } @@ -83,7 +87,11 @@ func (l *GreenfieldListener) poll() error { Height: uint64(block.Height), BlockTime: block.Time.Unix(), } - return l.DaoManager.GreenfieldDao.SaveBlockAndBatchTransactions(b, txs) + if err := l.DaoManager.GreenfieldDao.SaveBlockAndBatchTransactions(b, txs); err != nil { + return err + } + l.metricService.SetGnfdSavedBlockHeight(uint64(block.Height)) + return nil } } } diff --git a/metric/metric_service.go b/metric/metric_service.go new file mode 100644 index 0000000..094e109 --- /dev/null +++ b/metric/metric_service.go @@ -0,0 +1,224 @@ +package metric + +import ( + "fmt" + "net/http" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" + + "github.com/bnb-chain/greenfield-relayer/config" +) + +const ( + MetricNameGnfdSavedBlock = "Greenfield_saved_block_height" + MetricNameGnfdProcessedBlock = "Greenfield_processed_block_height" + MetricNameIsGnfdInturnRelayer = "is_Greenfield_inturn_relayer" + MetricNameGnfdRelayerStartTime = "Greenfield_relayer_start_time" // inturn relayer start time + MetricNameGnfdRelayerEndTime = "Greenfield_relayer_end_time" // inturn relayer end time + + MetricNameBSCSavedBlock = "BSC_saved_block_height" + MetricNameBSCProcessedBlock = "BSC_processed_block_height" + MetricNameIsBSCInturnRelayer = "is_BSC_inturn_relayer" + MetricNameBSCRelayerStartTime = "BSC_relayer_start_time" // inturn relayer start time + MetricNameBSCRelayerEndTime = "BSC_relayer_end_time" // inturn relayer end time + + MetricNameNextSequenceForChannelFromDB = "next_seq_from_DB_for_channel" + MetricNameNextSequenceForChannelFromChain = "next_seq_from_chain_for_channel" +) + +type MetricService struct { + MetricsMap map[string]prometheus.Metric + cfg *config.Config +} + +func NewMetricService(config *config.Config) *MetricService { + ms := make(map[string]prometheus.Metric, 0) + + // Greenfield + gnfdSavedBlockMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameGnfdSavedBlock, + Help: "Saved block height for Greenfield in Database", + }) + ms[MetricNameGnfdSavedBlock] = gnfdSavedBlockMetric + prometheus.MustRegister(gnfdSavedBlockMetric) + + gnfdProcessedBlockMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameGnfdProcessedBlock, + Help: "Processed block height for Greenfield in Database", + }) + ms[MetricNameGnfdProcessedBlock] = gnfdProcessedBlockMetric + prometheus.MustRegister(gnfdProcessedBlockMetric) + + gnfdIsInturnRelayerMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameIsGnfdInturnRelayer, + Help: "Whether relayer is inturn to relay transaction from BSC to Greenfield", + }) + ms[MetricNameIsGnfdInturnRelayer] = gnfdIsInturnRelayerMetric + prometheus.MustRegister(gnfdIsInturnRelayerMetric) + + // Greenfield relayer(BSC -> Greenfield) relay interval metrics + gnfdRelayerStartTimeMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameGnfdRelayerStartTime, + Help: "inturn gnfd relayer start time or out-turn relayer previous start time", + }) + ms[MetricNameGnfdRelayerStartTime] = gnfdRelayerStartTimeMetric + prometheus.MustRegister(gnfdRelayerStartTimeMetric) + + gnfdRelayerEndTimeMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameGnfdRelayerEndTime, + Help: "inturn gnfd relayer end time or out-turn relayer previous end time", + }) + ms[MetricNameGnfdRelayerEndTime] = gnfdRelayerEndTimeMetric + prometheus.MustRegister(gnfdRelayerEndTimeMetric) + + // BSC + bscSavedBlockMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameBSCSavedBlock, + Help: "Saved block height for BSC in Database", + }) + ms[MetricNameBSCSavedBlock] = bscSavedBlockMetric + prometheus.MustRegister(bscSavedBlockMetric) + + bscProcessedBlockMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameBSCProcessedBlock, + Help: "Processed block height for BSC in Database", + }) + ms[MetricNameBSCProcessedBlock] = bscProcessedBlockMetric + prometheus.MustRegister(bscProcessedBlockMetric) + + bscIsInturnRelayerMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameIsBSCInturnRelayer, + Help: "Whether relayer is inturn to relay transaction from Greenfield to BSC", + }) + ms[MetricNameIsBSCInturnRelayer] = bscIsInturnRelayerMetric + prometheus.MustRegister(bscIsInturnRelayerMetric) + + // BSC relayer(Greenfield -> BSC) relay interval metrics + bscRelayerStartTimeMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameBSCRelayerStartTime, + Help: "inturn BSC relayer start time or out-turn relayer previous start time", + }) + ms[MetricNameBSCRelayerStartTime] = bscRelayerStartTimeMetric + prometheus.MustRegister(bscRelayerStartTimeMetric) + + bscRelayerEndTimeMetric := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: MetricNameBSCRelayerEndTime, + Help: "inturn BSC relayer end time or out-turn relayer previous end time", + }) + ms[MetricNameBSCRelayerEndTime] = bscRelayerEndTimeMetric + prometheus.MustRegister(bscRelayerEndTimeMetric) + + // register greenfield oracle channel + nextSeqFromDB := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromDB, 0), + Help: fmt.Sprintf("Next delivery sequence read from DB for channel %d", 0), + }) + ms[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromDB, 0)] = nextSeqFromDB + prometheus.MustRegister(nextSeqFromDB) + + nextSeqFromChain := prometheus.NewGauge(prometheus.GaugeOpts{ + Name: fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromChain, 0), + Help: fmt.Sprintf("Next delivery sequence read from chain for channel %d", 0), + }) + ms[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromChain, 0)] = nextSeqFromChain + prometheus.MustRegister(nextSeqFromChain) + + // register gnfd -> bsc channels + for _, c := range config.GreenfieldConfig.MonitorChannelList { + nextSeqFromDB = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromDB, c), + Help: fmt.Sprintf("Next delivery sequence retreived from DB for channel %d", c), + }) + ms[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromDB, c)] = nextSeqFromDB + prometheus.MustRegister(nextSeqFromDB) + + nextSeqFromChain = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromChain, c), + Help: fmt.Sprintf("Next delivery sequence retreived from chain for channel %d", c), + }) + ms[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromChain, c)] = nextSeqFromChain + prometheus.MustRegister(nextSeqFromChain) + } + + return &MetricService{ + MetricsMap: ms, + cfg: config, + } +} + +func (m *MetricService) Start() { + http.Handle("/metrics", promhttp.Handler()) + err := http.ListenAndServe(fmt.Sprintf(":%d", m.cfg.AdminConfig.Port), nil) + if err != nil { + panic(err) + } +} + +func (m *MetricService) SetGnfdSavedBlockHeight(height uint64) { + m.MetricsMap[MetricNameGnfdSavedBlock].(prometheus.Gauge).Set(float64(height)) +} + +func (m *MetricService) SetGnfdProcessedBlockHeight(height uint64) { + m.MetricsMap[MetricNameGnfdProcessedBlock].(prometheus.Gauge).Set(float64(height)) +} + +func (m *MetricService) SetBSCSavedBlockHeight(height uint64) { + m.MetricsMap[MetricNameBSCSavedBlock].(prometheus.Gauge).Set(float64(height)) +} + +func (m *MetricService) SetBSCProcessedBlockHeight(height uint64) { + m.MetricsMap[MetricNameBSCProcessedBlock].(prometheus.Gauge).Set(float64(height)) +} + +func (m *MetricService) SetBSCInturnRelayerMetrics(isInturn bool, start, end uint64) { + m.setIsBSCInturnRelayer(isInturn) + m.setBSCInturnRelayerStartTime(start) + m.setBSCInturnRelayerEndTime(end) +} + +func (m *MetricService) setIsBSCInturnRelayer(isInturn bool) { + var flag float64 + if isInturn { + flag = 1 + } + m.MetricsMap[MetricNameIsBSCInturnRelayer].(prometheus.Gauge).Set(flag) +} + +func (m *MetricService) setBSCInturnRelayerStartTime(start uint64) { + m.MetricsMap[MetricNameBSCRelayerStartTime].(prometheus.Gauge).Set(float64(start)) +} + +func (m *MetricService) setBSCInturnRelayerEndTime(end uint64) { + m.MetricsMap[MetricNameBSCRelayerEndTime].(prometheus.Gauge).Set(float64(end)) +} + +func (m *MetricService) SetGnfdInturnRelayerMetrics(isInturn bool, start, end uint64) { + m.setIsGnfdInturnRelayer(isInturn) + m.setGnfdInturnRelayerStartTime(start) + m.setGnfdInturnRelayerEndTime(end) +} + +func (m *MetricService) setIsGnfdInturnRelayer(isInturn bool) { + var flag float64 + if isInturn { + flag = 1 + } + m.MetricsMap[MetricNameIsGnfdInturnRelayer].(prometheus.Gauge).Set(flag) +} + +func (m *MetricService) setGnfdInturnRelayerStartTime(start uint64) { + m.MetricsMap[MetricNameGnfdRelayerStartTime].(prometheus.Gauge).Set(float64(start)) +} + +func (m *MetricService) setGnfdInturnRelayerEndTime(end uint64) { + m.MetricsMap[MetricNameGnfdRelayerEndTime].(prometheus.Gauge).Set(float64(end)) +} + +func (m *MetricService) SetNextSequenceForChannelFromDB(channel uint8, seq uint64) { + m.MetricsMap[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromDB, channel)].(prometheus.Gauge).Set(float64(seq)) +} + +func (m *MetricService) SetNextSequenceForChannelFromChain(channel uint8, seq uint64) { + m.MetricsMap[fmt.Sprintf("%s_%d", MetricNameNextSequenceForChannelFromChain, channel)].(prometheus.Gauge).Set(float64(seq)) +}