-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5189 from shrimalmadhur/madhur/op-proposer/add-l2…
…-proposed-metrics op-proposer: add l2 block height metrics
- Loading branch information
Showing
7 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum-optimism/optimism/op-node/eth" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" | ||
) | ||
|
||
const Namespace = "op_proposer" | ||
|
||
type Metricer interface { | ||
RecordInfo(version string) | ||
RecordUp() | ||
|
||
// Records all L1 and L2 block events | ||
opmetrics.RefMetricer | ||
|
||
RecordL2BlocksProposed(l2ref eth.L2BlockRef) | ||
} | ||
|
||
type Metrics struct { | ||
ns string | ||
registry *prometheus.Registry | ||
factory opmetrics.Factory | ||
|
||
opmetrics.RefMetrics | ||
|
||
Info prometheus.GaugeVec | ||
Up prometheus.Gauge | ||
} | ||
|
||
var _ Metricer = (*Metrics)(nil) | ||
|
||
func NewMetrics(procName string) *Metrics { | ||
if procName == "" { | ||
procName = "default" | ||
} | ||
ns := Namespace + "_" + procName | ||
|
||
registry := opmetrics.NewRegistry() | ||
factory := opmetrics.With(registry) | ||
|
||
return &Metrics{ | ||
ns: ns, | ||
registry: registry, | ||
factory: factory, | ||
|
||
RefMetrics: opmetrics.MakeRefMetrics(ns, factory), | ||
|
||
Info: *factory.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: ns, | ||
Name: "info", | ||
Help: "Pseudo-metric tracking version and config info", | ||
}, []string{ | ||
"version", | ||
}), | ||
Up: factory.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: ns, | ||
Name: "up", | ||
Help: "1 if the op-proposer has finished starting up", | ||
}), | ||
} | ||
} | ||
|
||
func (m *Metrics) Serve(ctx context.Context, host string, port int) error { | ||
return opmetrics.ListenAndServe(ctx, m.registry, host, port) | ||
} | ||
|
||
func (m *Metrics) StartBalanceMetrics(ctx context.Context, | ||
l log.Logger, client *ethclient.Client, account common.Address) { | ||
opmetrics.LaunchBalanceMetrics(ctx, l, m.registry, m.ns, client, account) | ||
} | ||
|
||
// RecordInfo sets a pseudo-metric that contains versioning and | ||
// config info for the op-proposer. | ||
func (m *Metrics) RecordInfo(version string) { | ||
m.Info.WithLabelValues(version).Set(1) | ||
} | ||
|
||
// RecordUp sets the up metric to 1. | ||
func (m *Metrics) RecordUp() { | ||
prometheus.MustRegister() | ||
m.Up.Set(1) | ||
} | ||
|
||
const ( | ||
BlockProposed = "proposed" | ||
) | ||
|
||
// RecordL2BlocksProposed should be called when new L2 block is proposed | ||
func (m *Metrics) RecordL2BlocksProposed(l2ref eth.L2BlockRef) { | ||
m.RecordL2Ref(BlockProposed, l2ref) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/ethereum-optimism/optimism/op-node/eth" | ||
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" | ||
) | ||
|
||
type noopMetrics struct{ opmetrics.NoopRefMetrics } | ||
|
||
var NoopMetrics Metricer = new(noopMetrics) | ||
|
||
func (*noopMetrics) RecordInfo(version string) {} | ||
func (*noopMetrics) RecordUp() {} | ||
|
||
func (*noopMetrics) RecordL2BlocksProposed(l2ref eth.L2BlockRef) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters