-
Notifications
You must be signed in to change notification settings - Fork 4k
op-proposer: add l2 block height metrics #5189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 13 commits into
ethereum-optimism:develop
from
shrimalmadhur:madhur/op-proposer/add-l2-proposed-metrics
Mar 22, 2023
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
98c1994
op-proposer: add l2 block height metrics
shrimalmadhur ec1c035
imports lint
shrimalmadhur 6a033e0
refactor to make it extensible
shrimalmadhur 9f453e7
remove namespace
shrimalmadhur 43519a2
refactor to use ref metrics
shrimalmadhur 8a2d7f5
missing noop
shrimalmadhur 1bc9f6e
test fix
shrimalmadhur e6d58cd
record l2 block
shrimalmadhur eda69a4
emit from the caller
shrimalmadhur 2920aae
remove unnecessary fields
shrimalmadhur 47eeb69
reorder import
shrimalmadhur 595d89c
move else section outside
shrimalmadhur 4551be4
Merge branch 'develop' into madhur/op-proposer/add-l2-proposed-metrics
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.