Commit f2056c03 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

op-node: Add Metrics (#12408)

* op-node: Create metrics to record if sequencer is active

* op-node: Update transactions_sequenced_total metric

---------
Co-authored-by: default avatarprotolambda <proto@protolambda.com>
parent d728f268
...@@ -35,6 +35,7 @@ type Metricer interface { ...@@ -35,6 +35,7 @@ type Metricer interface {
RecordRPCClientRequest(method string) func(err error) RecordRPCClientRequest(method string) func(err error)
RecordRPCClientResponse(method string, err error) RecordRPCClientResponse(method string, err error)
SetDerivationIdle(status bool) SetDerivationIdle(status bool)
SetSequencerState(active bool)
RecordPipelineReset() RecordPipelineReset()
RecordSequencingError() RecordSequencingError()
RecordPublishingError() RecordPublishingError()
...@@ -48,7 +49,7 @@ type Metricer interface { ...@@ -48,7 +49,7 @@ type Metricer interface {
RecordL2Ref(name string, ref eth.L2BlockRef) RecordL2Ref(name string, ref eth.L2BlockRef)
RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)
RecordDerivedBatches(batchType string) RecordDerivedBatches(batchType string)
CountSequencedTxs(count int) CountSequencedTxsInBlock(txns int, deposits int)
RecordL1ReorgDepth(d uint64) RecordL1ReorgDepth(d uint64)
RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID) RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID)
RecordSequencerReset() RecordSequencerReset()
...@@ -94,6 +95,7 @@ type Metrics struct { ...@@ -94,6 +95,7 @@ type Metrics struct {
DerivationErrors *metrics.Event DerivationErrors *metrics.Event
SequencingErrors *metrics.Event SequencingErrors *metrics.Event
PublishingErrors *metrics.Event PublishingErrors *metrics.Event
SequencerActive prometheus.Gauge
EmittedEvents *prometheus.CounterVec EmittedEvents *prometheus.CounterVec
ProcessedEvents *prometheus.CounterVec ProcessedEvents *prometheus.CounterVec
...@@ -133,7 +135,7 @@ type Metrics struct { ...@@ -133,7 +135,7 @@ type Metrics struct {
L1ReorgDepth prometheus.Histogram L1ReorgDepth prometheus.Histogram
TransactionsSequencedTotal prometheus.Counter TransactionsSequencedTotal *prometheus.CounterVec
AltDAMetrics altda.Metricer AltDAMetrics altda.Metricer
...@@ -209,6 +211,11 @@ func NewMetrics(procName string) *Metrics { ...@@ -209,6 +211,11 @@ func NewMetrics(procName string) *Metrics {
DerivationErrors: metrics.NewEvent(factory, ns, "", "derivation_errors", "derivation errors"), DerivationErrors: metrics.NewEvent(factory, ns, "", "derivation_errors", "derivation errors"),
SequencingErrors: metrics.NewEvent(factory, ns, "", "sequencing_errors", "sequencing errors"), SequencingErrors: metrics.NewEvent(factory, ns, "", "sequencing_errors", "sequencing errors"),
PublishingErrors: metrics.NewEvent(factory, ns, "", "publishing_errors", "p2p publishing errors"), PublishingErrors: metrics.NewEvent(factory, ns, "", "publishing_errors", "p2p publishing errors"),
SequencerActive: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "sequencer_active",
Help: "1 if sequencer active, 0 otherwise",
}),
EmittedEvents: factory.NewCounterVec( EmittedEvents: factory.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
...@@ -261,12 +268,11 @@ func NewMetrics(procName string) *Metrics { ...@@ -261,12 +268,11 @@ func NewMetrics(procName string) *Metrics {
Help: "Histogram of L1 Reorg Depths", Help: "Histogram of L1 Reorg Depths",
}), }),
TransactionsSequencedTotal: factory.NewGauge(prometheus.GaugeOpts{ TransactionsSequencedTotal: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns, Namespace: ns,
Name: "transactions_sequenced_total", Name: "transactions_sequenced_total",
Help: "Count of total transactions sequenced", Help: "Count of total transactions sequenced",
}), }, []string{"type"}),
PeerCount: factory.NewGauge(prometheus.GaugeOpts{ PeerCount: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns, Namespace: ns,
Subsystem: "p2p", Subsystem: "p2p",
...@@ -470,6 +476,14 @@ func (m *Metrics) SetDerivationIdle(status bool) { ...@@ -470,6 +476,14 @@ func (m *Metrics) SetDerivationIdle(status bool) {
m.DerivationIdle.Set(val) m.DerivationIdle.Set(val)
} }
func (m *Metrics) SetSequencerState(active bool) {
var val float64
if active {
val = 1
}
m.SequencerActive.Set(val)
}
func (m *Metrics) RecordPipelineReset() { func (m *Metrics) RecordPipelineReset() {
m.PipelineResets.Record() m.PipelineResets.Record()
} }
...@@ -516,8 +530,9 @@ func (m *Metrics) RecordDerivedBatches(batchType string) { ...@@ -516,8 +530,9 @@ func (m *Metrics) RecordDerivedBatches(batchType string) {
m.DerivedBatches.Record(batchType) m.DerivedBatches.Record(batchType)
} }
func (m *Metrics) CountSequencedTxs(count int) { func (m *Metrics) CountSequencedTxsInBlock(txns int, deposits int) {
m.TransactionsSequencedTotal.Add(float64(count)) m.TransactionsSequencedTotal.WithLabelValues("deposits").Add(float64(deposits))
m.TransactionsSequencedTotal.WithLabelValues("txns").Add(float64(txns - deposits))
} }
func (m *Metrics) RecordL1ReorgDepth(d uint64) { func (m *Metrics) RecordL1ReorgDepth(d uint64) {
...@@ -686,6 +701,9 @@ func (n *noopMetricer) RecordUp() { ...@@ -686,6 +701,9 @@ func (n *noopMetricer) RecordUp() {
func (n *noopMetricer) SetDerivationIdle(status bool) { func (n *noopMetricer) SetDerivationIdle(status bool) {
} }
func (m *noopMetricer) SetSequencerState(active bool) {
}
func (n *noopMetricer) RecordPipelineReset() { func (n *noopMetricer) RecordPipelineReset() {
} }
...@@ -725,7 +743,7 @@ func (n *noopMetricer) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, ...@@ -725,7 +743,7 @@ func (n *noopMetricer) RecordUnsafePayloadsBuffer(length uint64, memSize uint64,
func (n *noopMetricer) RecordDerivedBatches(batchType string) { func (n *noopMetricer) RecordDerivedBatches(batchType string) {
} }
func (n *noopMetricer) CountSequencedTxs(count int) { func (n *noopMetricer) CountSequencedTxsInBlock(txns int, deposits int) {
} }
func (n *noopMetricer) RecordL1ReorgDepth(d uint64) { func (n *noopMetricer) RecordL1ReorgDepth(d uint64) {
......
...@@ -55,6 +55,7 @@ func (p *ActiveConfigPersistence) SequencerStopped() error { ...@@ -55,6 +55,7 @@ func (p *ActiveConfigPersistence) SequencerStopped() error {
func (p *ActiveConfigPersistence) persist(sequencerStarted bool) error { func (p *ActiveConfigPersistence) persist(sequencerStarted bool) error {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
data, err := json.Marshal(persistedState{SequencerStarted: &sequencerStarted}) data, err := json.Marshal(persistedState{SequencerStarted: &sequencerStarted})
if err != nil { if err != nil {
return fmt.Errorf("marshall new config: %w", err) return fmt.Errorf("marshall new config: %w", err)
......
...@@ -49,6 +49,7 @@ type Metrics interface { ...@@ -49,6 +49,7 @@ type Metrics interface {
RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)
SetDerivationIdle(idle bool) SetDerivationIdle(idle bool)
SetSequencerState(active bool)
RecordL1ReorgDepth(d uint64) RecordL1ReorgDepth(d uint64)
......
...@@ -110,10 +110,11 @@ func (eq *EngDeriver) onBuildSeal(ev BuildSealEvent) { ...@@ -110,10 +110,11 @@ func (eq *EngDeriver) onBuildSeal(ev BuildSealEvent) {
eq.metrics.RecordSequencerBuildingDiffTime(buildTime - time.Duration(eq.cfg.BlockTime)*time.Second) eq.metrics.RecordSequencerBuildingDiffTime(buildTime - time.Duration(eq.cfg.BlockTime)*time.Second)
txnCount := len(envelope.ExecutionPayload.Transactions) txnCount := len(envelope.ExecutionPayload.Transactions)
eq.metrics.CountSequencedTxs(txnCount) depositCount, _ := lastDeposit(envelope.ExecutionPayload.Transactions)
eq.metrics.CountSequencedTxsInBlock(txnCount, depositCount)
eq.log.Debug("Processed new L2 block", "l2_unsafe", ref, "l1_origin", ref.L1Origin, eq.log.Debug("Processed new L2 block", "l2_unsafe", ref, "l1_origin", ref.L1Origin,
"txs", txnCount, "time", ref.Time, "seal_time", sealTime, "build_time", buildTime) "txs", txnCount, "deposits", depositCount, "time", ref.Time, "seal_time", sealTime, "build_time", buildTime)
eq.emitter.Emit(BuildSealedEvent{ eq.emitter.Emit(BuildSealedEvent{
Concluding: ev.Concluding, Concluding: ev.Concluding,
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
) )
type Metrics interface { type Metrics interface {
CountSequencedTxs(count int) CountSequencedTxsInBlock(txns int, deposits int)
RecordSequencerBuildingDiffTime(duration time.Duration) RecordSequencerBuildingDiffTime(duration time.Duration)
RecordSequencerSealingTime(duration time.Duration) RecordSequencerSealingTime(duration time.Duration)
......
...@@ -33,6 +33,7 @@ type L1OriginSelectorIface interface { ...@@ -33,6 +33,7 @@ type L1OriginSelectorIface interface {
} }
type Metrics interface { type Metrics interface {
SetSequencerState(active bool)
RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID) RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID)
RecordSequencerReset() RecordSequencerReset()
RecordSequencingError() RecordSequencingError()
...@@ -619,6 +620,7 @@ func (d *Sequencer) Init(ctx context.Context, active bool) error { ...@@ -619,6 +620,7 @@ func (d *Sequencer) Init(ctx context.Context, active bool) error {
if active { if active {
return d.forceStart() return d.forceStart()
} else { } else {
d.metrics.SetSequencerState(false)
if err := d.listener.SequencerStopped(); err != nil { if err := d.listener.SequencerStopped(); err != nil {
return fmt.Errorf("failed to notify sequencer-state listener of initial stopped state: %w", err) return fmt.Errorf("failed to notify sequencer-state listener of initial stopped state: %w", err)
} }
...@@ -652,6 +654,7 @@ func (d *Sequencer) forceStart() error { ...@@ -652,6 +654,7 @@ func (d *Sequencer) forceStart() error {
d.nextActionOK = true d.nextActionOK = true
d.nextAction = d.timeNow() d.nextAction = d.timeNow()
d.active.Store(true) d.active.Store(true)
d.metrics.SetSequencerState(true)
d.log.Info("Sequencer has been started", "next action", d.nextAction) d.log.Info("Sequencer has been started", "next action", d.nextAction)
return nil return nil
} }
...@@ -697,6 +700,7 @@ func (d *Sequencer) Stop(ctx context.Context) (common.Hash, error) { ...@@ -697,6 +700,7 @@ func (d *Sequencer) Stop(ctx context.Context) (common.Hash, error) {
d.nextActionOK = false d.nextActionOK = false
d.active.Store(false) d.active.Store(false)
d.metrics.SetSequencerState(false)
d.log.Info("Sequencer has been stopped") d.log.Info("Sequencer has been stopped")
return d.latestHead.Hash, nil return d.latestHead.Hash, nil
} }
......
...@@ -17,7 +17,7 @@ type TestDerivationMetrics struct { ...@@ -17,7 +17,7 @@ type TestDerivationMetrics struct {
FnRecordChannelTimedOut func() FnRecordChannelTimedOut func()
} }
func (t *TestDerivationMetrics) CountSequencedTxs(count int) { func (t *TestDerivationMetrics) CountSequencedTxsInBlock(txns int, deposits int) {
} }
func (t *TestDerivationMetrics) RecordSequencerBuildingDiffTime(duration time.Duration) { func (t *TestDerivationMetrics) RecordSequencerBuildingDiffTime(duration time.Duration) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment