chain_metrics.go 1.49 KB
Newer Older
1
package backend
2 3 4

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

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

13 14
	RecordDBEntryCount(chainID types.ChainID, count int64)
	RecordDBSearchEntriesRead(chainID types.ChainID, count int64)
15 16
}

17 18 19
// 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 {
20
	chainID  types.ChainID
21 22 23
	delegate Metrics
}

24
func newChainMetrics(chainID types.ChainID, delegate Metrics) *chainMetrics {
25 26 27 28 29 30 31 32 33 34 35 36 37 38
	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)
}

39 40 41 42 43 44 45 46
func (c *chainMetrics) RecordDBEntryCount(count int64) {
	c.delegate.RecordDBEntryCount(c.chainID, count)
}

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

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