Skip to content

Commit

Permalink
set related metrics in ts
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jun 6, 2024
1 parent ec10ba9 commit 4a5192d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions zetaclient/chains/bitcoin/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ func (ob *Observer) GetLastBlockHeight() int64 {

func (ob *Observer) SetLastBlockHeightScanned(height int64) {
atomic.StoreInt64(&ob.lastBlockScanned, height)
ob.ts.SetLastScannedBlockNumber((ob.chain.ChainId), uint64(height))
metrics.LastScannedBlockNumber.WithLabelValues(ob.chain.ChainName.String()).Set(float64(height))
ob.ts.SetLastScannedBlockNumber((ob.chain.ChainName), uint64(height))
}

func (ob *Observer) GetLastBlockHeightScanned() int64 {
Expand Down Expand Up @@ -596,7 +595,6 @@ func (ob *Observer) FetchUTXOS() error {

ob.Mu.Lock()
ob.ts.SetNumberOfUTXOs(len(utxosFiltered))
metrics.NumberOfUTXO.Set(float64(len(utxosFiltered)))
ob.utxos = utxosFiltered
ob.Mu.Unlock()
return nil
Expand Down
3 changes: 1 addition & 2 deletions zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ func (ob *Observer) CheckTxInclusion(tx *ethtypes.Transaction, receipt *ethtypes
// SetLastBlockHeightScanned set last block height scanned (not necessarily caught up with external block; could be slow/paused)
func (ob *Observer) SetLastBlockHeightScanned(height uint64) {
atomic.StoreUint64(&ob.lastBlockScanned, height)
ob.ts.SetLastScannedBlockNumber(ob.chain.ChainId, height)
metrics.LastScannedBlockNumber.WithLabelValues(ob.chain.ChainName.String()).Set(float64(height))
ob.ts.SetLastScannedBlockNumber(ob.chain.ChainName, height)
}

// GetLastBlockHeightScanned get last block height scanned (not necessarily caught up with external block; could be slow/paused)
Expand Down
16 changes: 10 additions & 6 deletions zetaclient/metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gorilla/mux"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/constant"
"github.com/zeta-chain/zetacore/zetaclient/types"
)
Expand All @@ -21,7 +22,7 @@ type TelemetryServer struct {
logger zerolog.Logger
s *http.Server
p2pid string
lastScannedBlockNumber map[int64]uint64 // chainid => block number
lastScannedBlockNumber map[string]uint64 // chainName => block number
lastCoreBlockNumber int64
mu sync.Mutex
lastStartTimestamp time.Time
Expand All @@ -34,7 +35,7 @@ type TelemetryServer struct {
func NewTelemetryServer() *TelemetryServer {
hs := &TelemetryServer{
logger: log.With().Str("module", "http").Logger(),
lastScannedBlockNumber: make(map[int64]uint64),
lastScannedBlockNumber: make(map[string]uint64),
lastStartTimestamp: time.Now(),
HotKeyBurnRate: NewBurnRate(100),
}
Expand Down Expand Up @@ -82,21 +83,23 @@ func (t *TelemetryServer) GetLastStartTimestamp() time.Time {
return t.lastStartTimestamp
}

func (t *TelemetryServer) SetLastScannedBlockNumber(chainID int64, blockNumber uint64) {
func (t *TelemetryServer) SetLastScannedBlockNumber(chainName chains.ChainName, blockNumber uint64) {
t.mu.Lock()
t.lastScannedBlockNumber[chainID] = blockNumber
t.lastScannedBlockNumber[chainName.String()] = blockNumber
LastScannedBlockNumber.WithLabelValues(chainName.String()).Set(float64(blockNumber))
t.mu.Unlock()
}

func (t *TelemetryServer) GetLastScannedBlockNumber(chainID int64) uint64 {
func (t *TelemetryServer) GetLastScannedBlockNumber(chainName chains.ChainName) uint64 {
t.mu.Lock()
defer t.mu.Unlock()
return t.lastScannedBlockNumber[chainID]
return t.lastScannedBlockNumber[chainName.String()]
}

func (t *TelemetryServer) SetCoreBlockNumber(blockNumber int64) {
t.mu.Lock()
t.lastCoreBlockNumber = blockNumber
LastCoreBlockNumber.Set(float64(blockNumber))
t.mu.Unlock()
}

Expand All @@ -109,6 +112,7 @@ func (t *TelemetryServer) GetCoreBlockNumber() int64 {
func (t *TelemetryServer) SetNumberOfUTXOs(numberOfUTXOs int) {
t.mu.Lock()
t.status.BTCNumberOfUTXOs = numberOfUTXOs
NumberOfUTXO.Set(float64(numberOfUTXOs))
t.mu.Unlock()
}

Expand Down
1 change: 0 additions & 1 deletion zetaclient/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ func (oc *Orchestrator) StartCctxScheduler(appContext *context.AppContext) {
// update last processed block number
lastBlockNum = bn
oc.ts.SetCoreBlockNumber(lastBlockNum)
metrics.LastCoreBlockNumber.Set(float64(lastBlockNum))
}
}
}
Expand Down

0 comments on commit 4a5192d

Please sign in to comment.