metrics.go 2.28 KB
Newer Older
1 2
package testutils

3
import (
4 5
	"time"

6
	"github.com/ethereum-optimism/optimism/op-service/eth"
7
)
8 9 10 11

// TestDerivationMetrics implements the metrics used in the derivation pipeline as no-op operations.
// Optionally a test may hook into the metrics
type TestDerivationMetrics struct {
12 13 14 15
	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
16
	FnRecordChannelInputBytes func(inputCompressedBytes int)
17 18
}

19 20 21 22 23 24 25 26 27
func (t *TestDerivationMetrics) CountSequencedTxs(count int) {
}

func (t *TestDerivationMetrics) RecordSequencerBuildingDiffTime(duration time.Duration) {
}

func (t *TestDerivationMetrics) RecordSequencerSealingTime(duration time.Duration) {
}

28 29 30 31 32 33
func (t *TestDerivationMetrics) RecordL1ReorgDepth(d uint64) {
	if t.FnRecordL1ReorgDepth != nil {
		t.FnRecordL1ReorgDepth(d)
	}
}

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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)
	}
}
51

Sanghee Choi's avatar
Sanghee Choi committed
52
func (t *TestDerivationMetrics) RecordChannelInputBytes(inputCompressedBytes int) {
53
	if t.FnRecordChannelInputBytes != nil {
Sanghee Choi's avatar
Sanghee Choi committed
54
		t.FnRecordChannelInputBytes(inputCompressedBytes)
55 56 57
	}
}

58 59 60 61 62 63 64 65 66
func (t *TestDerivationMetrics) RecordHeadChannelOpened() {
}

func (t *TestDerivationMetrics) RecordChannelTimedOut() {
}

func (t *TestDerivationMetrics) RecordFrame() {
}

67
func (n *TestDerivationMetrics) RecordDerivedBatches(batchType string) {
Tei Im's avatar
Tei Im committed
68 69
}

70 71 72 73 74
type TestRPCMetrics struct{}

func (n *TestRPCMetrics) RecordRPCServerRequest(method string) func() {
	return func() {}
}
75 76 77 78 79 80

func (n *TestRPCMetrics) RecordRPCClientRequest(method string) func(err error) {
	return func(err error) {}
}

func (n *TestRPCMetrics) RecordRPCClientResponse(method string, err error) {}
81 82

func (t *TestDerivationMetrics) SetDerivationIdle(idle bool) {}
83 84 85

func (t *TestDerivationMetrics) RecordPipelineReset() {
}