Commit 01af4459 authored by Seungju Lee's avatar Seungju Lee

refactor: use a single metrics instantiation instead of handling it per component

parent 9c4ff1e7
......@@ -12,7 +12,6 @@ import (
"github.com/ethereum-optimism/optimism/op-batcher/rpc"
opservice "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum-optimism/optimism/op-service/opio"
oppprof "github.com/ethereum-optimism/optimism/op-service/pprof"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
......@@ -83,8 +82,7 @@ func Main(version string, cliCtx *cli.Context) error {
oprpc.WithLogger(l),
)
if cfg.RPCFlag.EnableAdmin {
rpcMetrics := opmetrics.NewRPCMetrics(procName, metrics.Namespace)
adminAPI := rpc.NewAdminAPI(batchSubmitter, rpcMetrics, l)
adminAPI := rpc.NewAdminAPI(batchSubmitter, &m.RPCMetrics, l)
server.AddAPI(rpc.GetAdminAPI(adminAPI))
l.Info("Admin RPC enabled")
}
......
......@@ -51,6 +51,7 @@ type Metrics struct {
opmetrics.RefMetrics
txmetrics.TxMetrics
opmetrics.RPCMetrics
info prometheus.GaugeVec
up prometheus.Gauge
......@@ -93,6 +94,7 @@ func NewMetrics(procName string) *Metrics {
RefMetrics: opmetrics.MakeRefMetrics(ns, factory),
TxMetrics: txmetrics.MakeTxMetrics(ns, factory),
RPCMetrics: opmetrics.MakeRPCMetrics(ns, factory),
info: *factory.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ns,
......
......@@ -80,7 +80,7 @@ type Metrics struct {
Info *prometheus.GaugeVec
Up prometheus.Gauge
*metrics.RPCMetrics
metrics.RPCMetrics
L1SourceCache *CacheMetrics
L2SourceCache *CacheMetrics
......@@ -175,7 +175,7 @@ func NewMetrics(procName string) *Metrics {
Help: "1 if the op node has finished starting up",
}),
RPCMetrics: metrics.NewRPCMetrics(procName, Namespace),
RPCMetrics: metrics.MakeRPCMetrics(ns, factory),
L1SourceCache: NewCacheMetrics(factory, ns, "l1_source_cache", "L1 Source cache"),
L2SourceCache: NewCacheMetrics(factory, ns, "l2_source_cache", "L2 Source cache"),
......
......@@ -7,7 +7,6 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/rpc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
)
const (
......@@ -30,20 +29,10 @@ type RPCMetrics struct {
RPCClientResponsesTotal *prometheus.CounterVec
}
// NewRPCMetrics creates a new RPCMetrics instance with the given process name, and
// MakeRPCMetrics creates a new RPCMetrics instance with the given process name, and
// namespace for the service.
func NewRPCMetrics(procName, namespace string) *RPCMetrics {
if procName == "" {
procName = "default"
}
ns := namespace + "_" + procName
registry := prometheus.NewRegistry()
registry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
registry.MustRegister(collectors.NewGoCollector())
factory := With(registry)
return &RPCMetrics{
func MakeRPCMetrics(ns string, factory Factory) RPCMetrics {
return RPCMetrics{
RPCServerRequestsTotal: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: ns,
Subsystem: RPCServerSubsystem,
......
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