forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-challenger: Add basic metrics & pprof setup
This adds metrics & pprof to the op-challenger. I had to add a default config option to the metrics & pprof in order to make the tests work (because it verifies that the result of the CLI parsing is as expected when compared to an config struct which is constructed). This also had to modify how the challenger stores its version information because we include that information in the metrics when we record that it is up. Unlike the proposer & batcher, the challenger has a different initialization flow which does not easily make the version information accessible.
- Loading branch information
1 parent
9d9a79a
commit 532d8ce
Showing
12 changed files
with
204 additions
and
12 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,86 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
|
||
"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" | ||
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" | ||
) | ||
|
||
const Namespace = "op_challenger" | ||
|
||
type Metricer interface { | ||
RecordInfo(version string) | ||
RecordUp() | ||
|
||
// Record Tx metrics | ||
txmetrics.TxMetricer | ||
} | ||
|
||
type Metrics struct { | ||
ns string | ||
registry *prometheus.Registry | ||
factory opmetrics.Factory | ||
|
||
txmetrics.TxMetrics | ||
|
||
info prometheus.GaugeVec | ||
up prometheus.Gauge | ||
} | ||
|
||
var _ Metricer = (*Metrics)(nil) | ||
|
||
func NewMetrics() *Metrics { | ||
registry := opmetrics.NewRegistry() | ||
factory := opmetrics.With(registry) | ||
|
||
return &Metrics{ | ||
ns: Namespace, | ||
registry: registry, | ||
factory: factory, | ||
|
||
TxMetrics: txmetrics.MakeTxMetrics(Namespace, factory), | ||
|
||
info: *factory.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: Namespace, | ||
Name: "info", | ||
Help: "Pseudo-metric tracking version and config info", | ||
}, []string{ | ||
"version", | ||
}), | ||
up: factory.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: Namespace, | ||
Name: "up", | ||
Help: "1 if the op-challenger 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) | ||
} | ||
|
||
func (m *Metrics) Document() []opmetrics.DocumentedMetric { | ||
return m.factory.Document() | ||
} |
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,14 @@ | ||
package metrics | ||
|
||
import ( | ||
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics" | ||
) | ||
|
||
type noopMetrics struct { | ||
txmetrics.NoopTxMetrics | ||
} | ||
|
||
var NoopMetrics Metricer = new(noopMetrics) | ||
|
||
func (*noopMetrics) RecordInfo(version string) {} | ||
func (*noopMetrics) RecordUp() {} |
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
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