metrics.go 1.47 KB
Newer Older
1 2
package testutils

3 4 5
import (
	"github.com/ethereum-optimism/optimism/op-node/eth"
)
6 7 8 9

// TestDerivationMetrics implements the metrics used in the derivation pipeline as no-op operations.
// Optionally a test may hook into the metrics
type TestDerivationMetrics struct {
10 11 12 13
	FnRecordL1ReorgDepth      func(d uint64)
	FnRecordL1Ref             func(name string, ref eth.L1BlockRef)
	FnRecordL2Ref             func(name string, ref eth.L2BlockRef)
	FnRecordUnsafePayloads    func(length uint64, memSize uint64, next eth.BlockID)
Sanghee Choi's avatar
Sanghee Choi committed
14
	FnRecordChannelInputBytes func(inputCompressedBytes int)
15 16
}

17 18 19 20 21 22
func (t *TestDerivationMetrics) RecordL1ReorgDepth(d uint64) {
	if t.FnRecordL1ReorgDepth != nil {
		t.FnRecordL1ReorgDepth(d)
	}
}

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
func (t *TestDerivationMetrics) RecordL1Ref(name string, ref eth.L1BlockRef) {
	if t.FnRecordL1Ref != nil {
		t.FnRecordL1Ref(name, ref)
	}
}

func (t *TestDerivationMetrics) RecordL2Ref(name string, ref eth.L2BlockRef) {
	if t.FnRecordL2Ref != nil {
		t.FnRecordL2Ref(name, ref)
	}
}

func (t *TestDerivationMetrics) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) {
	if t.FnRecordUnsafePayloads != nil {
		t.FnRecordUnsafePayloads(length, memSize, next)
	}
}
40

Sanghee Choi's avatar
Sanghee Choi committed
41
func (t *TestDerivationMetrics) RecordChannelInputBytes(inputCompressedBytes int) {
42
	if t.FnRecordChannelInputBytes != nil {
Sanghee Choi's avatar
Sanghee Choi committed
43
		t.FnRecordChannelInputBytes(inputCompressedBytes)
44 45 46
	}
}

47 48 49 50 51
type TestRPCMetrics struct{}

func (n *TestRPCMetrics) RecordRPCServerRequest(method string) func() {
	return func() {}
}