From 992c9b81b2c6d8852a4764fe13285fec115de6fe Mon Sep 17 00:00:00 2001 From: dmarzzz Date: Thu, 5 Sep 2024 18:30:36 -0400 Subject: [PATCH] pull builder metrics out --- op-node/metrics/metrics.go | 86 +++------------------- op-node/metrics/metrics_builder.go | 110 +++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 75 deletions(-) create mode 100644 op-node/metrics/metrics_builder.go diff --git a/op-node/metrics/metrics.go b/op-node/metrics/metrics.go index 80817cba84b5..72fa5b379d83 100644 --- a/op-node/metrics/metrics.go +++ b/op-node/metrics/metrics.go @@ -128,17 +128,7 @@ type Metrics struct { SequencerSealingDurationSeconds prometheus.Histogram SequencerSealingTotal prometheus.Counter - SequencerBuilderRequestDurationSeconds prometheus.Histogram - SequencerBuilderRequestTotal prometheus.Counter - SequencerBuilderRequestErrors prometheus.Counter - SequencerBuilderRequestTimeouts prometheus.Counter - SequencerBuilderPayloadBytes prometheus.Gauge - - SequencerProfit *prometheus.GaugeVec - - SequencerPayloadInserted *prometheus.CounterVec - SequencerPayloadGas *prometheus.GaugeVec - SequencerPayloadGasTotal *prometheus.GaugeVec + BuilderMetrics *BuilderMetrics UnsafePayloadsBufferLen prometheus.Gauge UnsafePayloadsBufferMemSize prometheus.Gauge @@ -194,6 +184,8 @@ func NewMetrics(procName string) *Metrics { registry.MustRegister(collectors.NewGoCollector()) factory := metrics.With(registry) + builderMetrics := NewBuilderMetrics(ns, factory) + return &Metrics{ Info: factory.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ns, @@ -403,61 +395,7 @@ func NewMetrics(procName string) *Metrics { Help: "Number of sequencer block sealing jobs", }), - SequencerBuilderRequestDurationSeconds: factory.NewHistogram(prometheus.HistogramOpts{ - Namespace: ns, - Name: "sequencer_builder_request_seconds", - Buckets: []float64{ - .001, .0025, .005, .01, .025, .05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}, - Help: "Duration of sequencer builder requests", - }), - SequencerBuilderRequestTotal: factory.NewCounter(prometheus.CounterOpts{ - Namespace: ns, - Name: "sequencer_builder_request_total", - Help: "Number of sequencer builder requests", - }), - SequencerBuilderRequestErrors: factory.NewCounter(prometheus.CounterOpts{ - Namespace: ns, - Name: "sequencer_builder_request_errors", - Help: "Number of sequencer builder request errors", - }), - SequencerBuilderRequestTimeouts: factory.NewCounter(prometheus.CounterOpts{ - Namespace: ns, - Name: "sequencer_builder_request_timeout", - Help: "Number of sequencer builder request timeouts", - }), - SequencerBuilderPayloadBytes: factory.NewGauge(prometheus.GaugeOpts{ - Namespace: ns, - Name: "sequencer_builder_payload_bytes", - Help: "Size of sequencer builder payloads by source", - }), - SequencerProfit: factory.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: ns, - Name: "sequencer_profit", - Help: "Sequencer profit by source.", - }, []string{ - "source", - }), - SequencerPayloadInserted: factory.NewCounterVec(prometheus.CounterOpts{ - Namespace: ns, - Name: "sequencer_payload_inserted", - Help: "Count of sequencer payloads inserted to engine by source", - }, []string{ - "source", - }), - SequencerPayloadGas: factory.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: ns, - Name: "sequencer_payload_gas", - Help: "Gas used by sequencer payloads by source", - }, []string{ - "source", - }), - SequencerPayloadGasTotal: factory.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: ns, - Name: "sequencer_payload_gas_total", - Help: "Total gas used by sequencer payloads by source", - }, []string{ - "source", - }), + BuilderMetrics: builderMetrics, ProtocolVersionDelta: factory.NewGaugeVec(prometheus.GaugeOpts{ Namespace: ns, @@ -632,34 +570,32 @@ func (m *Metrics) RecordSequencerSealingTime(duration time.Duration) { } func (m *Metrics) RecordBuilderRequestTime(duration time.Duration) { - m.SequencerBuilderRequestTotal.Inc() - m.SequencerBuilderRequestDurationSeconds.Observe(float64(duration) / float64(time.Second)) + m.BuilderMetrics.RecordBuilderRequestTime(duration) } func (m *Metrics) RecordBuilderRequestFail() { - m.SequencerBuilderRequestErrors.Inc() + m.BuilderMetrics.RecordBuilderRequestFail() } func (m *Metrics) RecordBuilderRequestTimeout() { - m.SequencerBuilderRequestTimeouts.Inc() + m.BuilderMetrics.RecordBuilderRequestTimeout() } func (m *Metrics) RecordBuilderPayloadBytes(num int) { - m.SequencerBuilderPayloadBytes.Add(float64(num)) + m.BuilderMetrics.RecordBuilderPayloadBytes(num) } // RecordSequencerProfit measures the profit made by the sequencer by source: engine and external builders. func (m *Metrics) RecordSequencerProfit(profit float64, source PayloadSource) { - m.SequencerProfit.WithLabelValues(string(source)).Set(profit) + m.BuilderMetrics.RecordSequencerProfit(profit, source) } func (m *Metrics) RecordSequencerPayloadInserted(source PayloadSource) { - m.SequencerPayloadInserted.WithLabelValues(string(source)).Inc() + m.BuilderMetrics.RecordSequencerPayloadInserted(source) } func (m *Metrics) RecordPayloadGas(gas float64, source string) { - m.SequencerPayloadGas.WithLabelValues(source).Set(gas) - m.SequencerPayloadGasTotal.WithLabelValues(source).Add(gas) + m.BuilderMetrics.RecordPayloadGas(gas, source) } // StartServer starts the metrics server on the given hostname and port. diff --git a/op-node/metrics/metrics_builder.go b/op-node/metrics/metrics_builder.go new file mode 100644 index 000000000000..75d91ccd7372 --- /dev/null +++ b/op-node/metrics/metrics_builder.go @@ -0,0 +1,110 @@ +package metrics + +import ( + "time" + + "github.com/ethereum-optimism/optimism/op-service/metrics" + "github.com/prometheus/client_golang/prometheus" +) + +type BuilderMetrics struct { + SequencerBuilderRequestDurationSeconds prometheus.Histogram + SequencerBuilderRequestTotal prometheus.Counter + SequencerBuilderRequestErrors prometheus.Counter + SequencerBuilderRequestTimeouts prometheus.Counter + SequencerBuilderPayloadBytes prometheus.Gauge + SequencerProfit *prometheus.GaugeVec + SequencerPayloadInserted *prometheus.CounterVec + SequencerPayloadGas *prometheus.GaugeVec + SequencerPayloadGasTotal *prometheus.GaugeVec +} + +func NewBuilderMetrics(ns string, factory metrics.Factory) *BuilderMetrics { + return &BuilderMetrics{ + SequencerBuilderRequestDurationSeconds: factory.NewHistogram(prometheus.HistogramOpts{ + Namespace: ns, + Name: "sequencer_builder_request_seconds", + Buckets: []float64{ + .001, .0025, .005, .01, .025, .05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}, + Help: "Duration of sequencer builder requests", + }), + SequencerBuilderRequestTotal: factory.NewCounter(prometheus.CounterOpts{ + Namespace: ns, + Name: "sequencer_builder_request_total", + Help: "Number of sequencer builder requests", + }), + SequencerBuilderRequestErrors: factory.NewCounter(prometheus.CounterOpts{ + Namespace: ns, + Name: "sequencer_builder_request_errors", + Help: "Number of sequencer builder request errors", + }), + SequencerBuilderRequestTimeouts: factory.NewCounter(prometheus.CounterOpts{ + Namespace: ns, + Name: "sequencer_builder_request_timeout", + Help: "Number of sequencer builder request timeouts", + }), + SequencerBuilderPayloadBytes: factory.NewGauge(prometheus.GaugeOpts{ + Namespace: ns, + Name: "sequencer_builder_payload_bytes", + Help: "Size of sequencer builder payloads by source", + }), + SequencerProfit: factory.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: ns, + Name: "sequencer_profit", + Help: "Sequencer profit by source.", + }, []string{ + "source", + }), + SequencerPayloadInserted: factory.NewCounterVec(prometheus.CounterOpts{ + Namespace: ns, + Name: "sequencer_payload_inserted", + Help: "Count of sequencer payloads inserted to engine by source", + }, []string{ + "source", + }), + SequencerPayloadGas: factory.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: ns, + Name: "sequencer_payload_gas", + Help: "Gas used by sequencer payloads by source", + }, []string{ + "source", + }), + SequencerPayloadGasTotal: factory.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: ns, + Name: "sequencer_payload_gas_total", + Help: "Total gas used by sequencer payloads by source", + }, []string{ + "source", + }), + } +} + +func (bm *BuilderMetrics) RecordBuilderRequestTime(duration time.Duration) { + bm.SequencerBuilderRequestTotal.Inc() + bm.SequencerBuilderRequestDurationSeconds.Observe(float64(duration) / float64(time.Second)) +} + +func (bm *BuilderMetrics) RecordBuilderRequestFail() { + bm.SequencerBuilderRequestErrors.Inc() +} + +func (bm *BuilderMetrics) RecordBuilderRequestTimeout() { + bm.SequencerBuilderRequestTimeouts.Inc() +} + +func (bm *BuilderMetrics) RecordBuilderPayloadBytes(num int) { + bm.SequencerBuilderPayloadBytes.Add(float64(num)) +} + +func (bm *BuilderMetrics) RecordSequencerProfit(profit float64, source PayloadSource) { + bm.SequencerProfit.WithLabelValues(string(source)).Set(profit) +} + +func (bm *BuilderMetrics) RecordSequencerPayloadInserted(source PayloadSource) { + bm.SequencerPayloadInserted.WithLabelValues(string(source)).Inc() +} + +func (bm *BuilderMetrics) RecordPayloadGas(gas float64, source string) { + bm.SequencerPayloadGas.WithLabelValues(source).Set(gas) + bm.SequencerPayloadGasTotal.WithLabelValues(source).Add(gas) +}