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 {
RecordRPCClientRequest(method string) func(err error)
RecordRPCClientResponse(method string, err error)
SetDerivationIdle(status bool)
SetSequencerState(active bool)
RecordPipelineReset()
RecordSequencingError()
RecordPublishingError()
......@@ -48,7 +49,7 @@ type Metricer interface {
RecordL2Ref(name string, ref eth.L2BlockRef)
RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)
RecordDerivedBatches(batchType string)
CountSequencedTxs(count int)
CountSequencedTxsInBlock(txns int, deposits int)
RecordL1ReorgDepth(d uint64)
RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID)
RecordSequencerReset()
......@@ -94,6 +95,7 @@ type Metrics struct {
DerivationErrors *metrics.Event
SequencingErrors *metrics.Event
PublishingErrors *metrics.Event
SequencerActive prometheus.Gauge
EmittedEvents *prometheus.CounterVec
ProcessedEvents *prometheus.CounterVec
......@@ -133,7 +135,7 @@ type Metrics struct {
L1ReorgDepth prometheus.Histogram
TransactionsSequencedTotal prometheus.Counter
TransactionsSequencedTotal *prometheus.CounterVec
AltDAMetrics altda.Metricer
......@@ -209,6 +211,11 @@ func NewMetrics(procName string) *Metrics {
DerivationErrors: metrics.NewEvent(factory, ns, "", "derivation_errors", "derivation errors"),
SequencingErrors: metrics.NewEvent(factory, ns, "", "sequencing_errors", "sequencing 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(
prometheus.CounterOpts{
......@@ -261,12 +268,11 @@ func NewMetrics(procName string) *Metrics {
Help: "Histogram of L1 Reorg Depths",
}),
TransactionsSequencedTotal: factory.NewGauge(prometheus.GaugeOpts{
TransactionsSequencedTotal: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Name: "transactions_sequenced_total",
Help: "Count of total transactions sequenced",
}),
}, []string{"type"}),
PeerCount: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Subsystem: "p2p",
......@@ -470,6 +476,14 @@ func (m *Metrics) SetDerivationIdle(status bool) {
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() {
m.PipelineResets.Record()
}
......@@ -516,8 +530,9 @@ func (m *Metrics) RecordDerivedBatches(batchType string) {
m.DerivedBatches.Record(batchType)
}
func (m *Metrics) CountSequencedTxs(count int) {
m.TransactionsSequencedTotal.Add(float64(count))
func (m *Metrics) CountSequencedTxsInBlock(txns int, deposits int) {
m.TransactionsSequencedTotal.WithLabelValues("deposits").Add(float64(deposits))
m.TransactionsSequencedTotal.WithLabelValues("txns").Add(float64(txns - deposits))
}
func (m *Metrics) RecordL1ReorgDepth(d uint64) {
......@@ -686,6 +701,9 @@ func (n *noopMetricer) RecordUp() {
func (n *noopMetricer) SetDerivationIdle(status bool) {
}
func (m *noopMetricer) SetSequencerState(active bool) {
}
func (n *noopMetricer) RecordPipelineReset() {
}
......@@ -725,7 +743,7 @@ func (n *noopMetricer) RecordUnsafePayloadsBuffer(length uint64, memSize uint64,
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) {
......
......@@ -55,6 +55,7 @@ func (p *ActiveConfigPersistence) SequencerStopped() error {
func (p *ActiveConfigPersistence) persist(sequencerStarted bool) error {
p.lock.Lock()
defer p.lock.Unlock()
data, err := json.Marshal(persistedState{SequencerStarted: &sequencerStarted})
if err != nil {
return fmt.Errorf("marshall new config: %w", err)
......
......@@ -49,6 +49,7 @@ type Metrics interface {
RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID)
SetDerivationIdle(idle bool)
SetSequencerState(active bool)
RecordL1ReorgDepth(d uint64)
......
......@@ -110,10 +110,11 @@ func (eq *EngDeriver) onBuildSeal(ev BuildSealEvent) {
eq.metrics.RecordSequencerBuildingDiffTime(buildTime - time.Duration(eq.cfg.BlockTime)*time.Second)
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,
"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{
Concluding: ev.Concluding,
......
......@@ -15,7 +15,7 @@ import (
)
type Metrics interface {
CountSequencedTxs(count int)
CountSequencedTxsInBlock(txns int, deposits int)
RecordSequencerBuildingDiffTime(duration time.Duration)
RecordSequencerSealingTime(duration time.Duration)
......
......@@ -33,6 +33,7 @@ type L1OriginSelectorIface interface {
}
type Metrics interface {
SetSequencerState(active bool)
RecordSequencerInconsistentL1Origin(from eth.BlockID, to eth.BlockID)
RecordSequencerReset()
RecordSequencingError()
......@@ -619,6 +620,7 @@ func (d *Sequencer) Init(ctx context.Context, active bool) error {
if active {
return d.forceStart()
} else {
d.metrics.SetSequencerState(false)
if err := d.listener.SequencerStopped(); err != nil {
return fmt.Errorf("failed to notify sequencer-state listener of initial stopped state: %w", err)
}
......@@ -652,6 +654,7 @@ func (d *Sequencer) forceStart() error {
d.nextActionOK = true
d.nextAction = d.timeNow()
d.active.Store(true)
d.metrics.SetSequencerState(true)
d.log.Info("Sequencer has been started", "next action", d.nextAction)
return nil
}
......@@ -697,6 +700,7 @@ func (d *Sequencer) Stop(ctx context.Context) (common.Hash, error) {
d.nextActionOK = false
d.active.Store(false)
d.metrics.SetSequencerState(false)
d.log.Info("Sequencer has been stopped")
return d.latestHead.Hash, nil
}
......
......@@ -17,7 +17,7 @@ type TestDerivationMetrics struct {
FnRecordChannelTimedOut func()
}
func (t *TestDerivationMetrics) CountSequencedTxs(count int) {
func (t *TestDerivationMetrics) CountSequencedTxsInBlock(txns int, deposits int) {
}
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