• Adrian Sutton's avatar
    op-supervisor: Wire in head tracking (#11139) · 98e1cf26
    Adrian Sutton authored
    * op-supervisor: Introduce head tracker
    
    * op-supervisor: Move log db to subpackage of db.
    
    * op-supervisor: Route all updates through a common db that can track heads
    
    * op-supervisor: Remove unused error.
    
    * op-supervisor: Remove operations - it fits into a later PR.
    
    * op-supervisor: Fix semgrep
    
    * op-supervisor: Move resuming databases into ChainsDB so it can later update the chain heads too.
    98e1cf26
chain_metrics.go 1.49 KB
package backend

import (
	"github.com/ethereum-optimism/optimism/op-service/sources/caching"
	"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/backend/db/logs"
	"github.com/ethereum-optimism/optimism/op-supervisor/supervisor/types"
)

type Metrics interface {
	CacheAdd(chainID types.ChainID, label string, cacheSize int, evicted bool)
	CacheGet(chainID types.ChainID, label string, hit bool)

	RecordDBEntryCount(chainID types.ChainID, count int64)
	RecordDBSearchEntriesRead(chainID types.ChainID, count int64)
}

// chainMetrics is an adapter between the metrics API expected by clients that assume there's only a single chain
// and the actual metrics implementation which requires a chain ID to identify the source chain.
type chainMetrics struct {
	chainID  types.ChainID
	delegate Metrics
}

func newChainMetrics(chainID types.ChainID, delegate Metrics) *chainMetrics {
	return &chainMetrics{
		chainID:  chainID,
		delegate: delegate,
	}
}

func (c *chainMetrics) CacheAdd(label string, cacheSize int, evicted bool) {
	c.delegate.CacheAdd(c.chainID, label, cacheSize, evicted)
}

func (c *chainMetrics) CacheGet(label string, hit bool) {
	c.delegate.CacheGet(c.chainID, label, hit)
}

func (c *chainMetrics) RecordDBEntryCount(count int64) {
	c.delegate.RecordDBEntryCount(c.chainID, count)
}

func (c *chainMetrics) RecordDBSearchEntriesRead(count int64) {
	c.delegate.RecordDBSearchEntriesRead(c.chainID, count)
}

var _ caching.Metrics = (*chainMetrics)(nil)
var _ logs.Metrics = (*chainMetrics)(nil)