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