Commit 87359fd2 authored by Conner Fromknecht's avatar Conner Fromknecht

feat: extend bsscore metrics for sequencer driver

The BatchPruneCount metric is not used by the proposer, so this is moved
into he sequencer's extended metrics. Also adds additional tooling for
extending metrics.
parent 224b69c2
---
'@eth-optimism/batch-submitter-service': patch
---
Refactors the bss-core service to use a metrics interface to allow
driver-specific metric extensions
......@@ -82,7 +82,7 @@ func NewDriver(cfg Config) (*Driver, error) {
rawSccContract: rawSccContract,
ctcContract: ctcContract,
walletAddr: walletAddr,
metrics: metrics.NewBase(cfg.Name),
metrics: metrics.NewBase("batch_submitter", cfg.Name),
}, nil
}
......
......@@ -44,7 +44,7 @@ type Driver struct {
rawCtcContract *bind.BoundContract
walletAddr common.Address
ctcABI *abi.ABI
metrics *metrics.Base
metrics *Metrics
}
func NewDriver(cfg Config) (*Driver, error) {
......@@ -80,7 +80,7 @@ func NewDriver(cfg Config) (*Driver, error) {
rawCtcContract: rawCtcContract,
walletAddr: walletAddr,
ctcABI: ctcABI,
metrics: metrics.NewBase(cfg.Name),
metrics: NewMetrics(cfg.Name),
}, nil
}
......@@ -220,7 +220,7 @@ func (d *Driver) CraftBatchTx(
}
d.metrics.NumElementsPerBatch().Observe(float64(len(batchElements)))
d.metrics.BatchPruneCount().Set(float64(pruneCount))
d.metrics.BatchPruneCount.Set(float64(pruneCount))
log.Info(name+" batch constructed", "num_txs", len(batchElements), "length", len(batchCallData))
......
package sequencer
import (
"github.com/ethereum-optimism/optimism/go/bss-core/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// Metrics extends the BSS core metrics with additional metrics tracked by the
// sequencer driver.
type Metrics struct {
*metrics.Base
// BatchPruneCount tracks the number of times a batch of sequencer
// transactions is pruned in order to meet the desired size requirements.
BatchPruneCount prometheus.Gauge
}
// NewMetrics initializes a new, extended metrics object.
func NewMetrics(subsystem string) *Metrics {
base := metrics.NewBase("batch_submitter", subsystem)
return &Metrics{
Base: base,
BatchPruneCount: promauto.NewGauge(prometheus.GaugeOpts{
Name: "batch_prune_count",
Help: "Number of times a batch is pruned",
Subsystem: base.SubsystemName(),
}),
}
}
......@@ -7,6 +7,7 @@ require (
github.com/ethereum-optimism/optimism/l2geth v1.0.0
github.com/ethereum/go-ethereum v1.10.16
github.com/getsentry/sentry-go v0.11.0
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.5
)
......
......@@ -3,6 +3,9 @@ package metrics
import "github.com/prometheus/client_golang/prometheus"
type Metrics interface {
// SubsystemName returns the subsystem name for the metrics group.
SubsystemName() string
// BalanceETH tracks the amount of ETH in the submitter's account.
BalanceETH() prometheus.Gauge
......@@ -32,8 +35,4 @@ type Metrics interface {
// BatchConfirmationTimeMs tracks the duration it takes to confirm a batch
// transaction.
BatchConfirmationTimeMs() prometheus.Gauge
// BatchPruneCount tracks the number of times a batch of sequencer
// transactions is pruned in order to meet the desired size requirements.
BatchPruneCount() prometheus.Gauge
}
package metrics
import (
"fmt"
"strings"
"github.com/prometheus/client_golang/prometheus"
......@@ -8,6 +9,11 @@ import (
)
type Base struct {
// subsystemName stores the name that will prefix all metrics. This can be
// used by drivers to futher extend the core metrics and ensure they use the
// same prefix.
subsystemName string
// balanceETH tracks the amount of ETH in the submitter's account.
balanceETH prometheus.Gauge
......@@ -37,17 +43,12 @@ type Base struct {
// batchConfirmationTimeMs tracks the duration it takes to confirm a batch
// transaction.
batchConfirmationTimeMs prometheus.Gauge
// batchPruneCount tracks the number of times a batch of sequencer
// transactions is pruned in order to meet the desired size requirements.
//
// NOTE: This is currently only active in the sequencer driver.
batchPruneCount prometheus.Gauge
}
func NewBase(subsystem string) *Base {
subsystem = "batch_submitter_" + strings.ToLower(subsystem)
func NewBase(serviceName, subServiceName string) *Base {
subsystem := MakeSubsystemName(serviceName, subServiceName)
return &Base{
subsystemName: subsystem,
balanceETH: promauto.NewGauge(prometheus.GaugeOpts{
Name: "balance_eth",
Help: "ETH balance of the batch submitter",
......@@ -95,14 +96,14 @@ func NewBase(subsystem string) *Base {
Help: "Time to confirm batch transactions",
Subsystem: subsystem,
}),
batchPruneCount: promauto.NewGauge(prometheus.GaugeOpts{
Name: "batch_prune_count",
Help: "Number of times a batch is pruned",
Subsystem: subsystem,
}),
}
}
// SubsystemName returns the subsystem name for the metrics group.
func (b *Base) SubsystemName() string {
return b.subsystemName
}
// BalanceETH tracks the amount of ETH in the submitter's account.
func (b *Base) BalanceETH() prometheus.Gauge {
return b.balanceETH
......@@ -151,10 +152,27 @@ func (b *Base) BatchConfirmationTimeMs() prometheus.Gauge {
return b.batchConfirmationTimeMs
}
// BatchPruneCount tracks the number of times a batch of sequencer transactions
// is pruned in order to meet the desired size requirements.
// MakeSubsystemName builds the subsystem name for a group of metrics, which
// prometheus will use to prefix all metrics in the group. If two non-empty
// strings are provided, they are joined with an underscore. If only one
// non-empty string is provided, that name will be used alone. Otherwise an
// empty string is returned after converting the characters to lower case.
//
// NOTE: This is currently only active in the sequencer driver.
func (b *Base) BatchPruneCount() prometheus.Gauge {
return b.batchPruneCount
// NOTE: This method panics if spaces are included in either string.
func MakeSubsystemName(serviceName string, subServiceName string) string {
var subsystem string
switch {
case serviceName != "" && subServiceName != "":
subsystem = fmt.Sprintf("%s_%s", serviceName, subServiceName)
case serviceName != "":
subsystem = serviceName
default:
subsystem = subServiceName
}
if strings.ContainsAny(subsystem, " ") {
panic(fmt.Sprintf("metrics name \"%s\"cannot have spaces", subsystem))
}
return strings.ToLower(subsystem)
}
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