From 5b5dc86d169e5e86a4609e40ee702325b091e75a Mon Sep 17 00:00:00 2001 From: Vlad <13818348+walldiss@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:35:25 +0500 Subject: [PATCH] remove type assert --- nodebuilder/p2p/metrics.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/nodebuilder/p2p/metrics.go b/nodebuilder/p2p/metrics.go index 925aa18183..b75492c120 100644 --- a/nodebuilder/p2p/metrics.go +++ b/nodebuilder/p2p/metrics.go @@ -18,7 +18,6 @@ import ( func WithMetrics() fx.Option { return fx.Options( fx.Provide(resourceManagerOpt(traceReporter)), - fx.Provide(prometheusRegisterer), fx.Invoke(prometheusMetrics), ) } @@ -33,11 +32,21 @@ const ( ) // prometheusMetrics option sets up native libp2p metrics up -func prometheusMetrics(lifecycle fx.Lifecycle, registerer prometheus.Registerer) error { - registry := registerer.(*prometheus.Registry) +func prometheusMetrics(lifecycle fx.Lifecycle, + peerID peer.ID, + nodeType node.Type, + network Network, +) error { + reg := prometheus.NewRegistry() + labels := prometheus.Labels{ + networkLabel: network.String(), + nodeTypeLabel: nodeType.String(), + peerIDLabel: peerID.String(), + } + wrapped := prometheus.WrapRegistererWith(labels, reg) mux := http.NewServeMux() - handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{Registry: registerer}) + handler := promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: wrapped}) mux.Handle(promAgentEndpoint, handler) // TODO(@Wondertan): Unify all the servers into one (See #2007) @@ -64,17 +73,3 @@ func prometheusMetrics(lifecycle fx.Lifecycle, registerer prometheus.Registerer) }) return nil } - -func prometheusRegisterer( - peerID peer.ID, - nodeType node.Type, - network Network, -) prometheus.Registerer { - reg := prometheus.NewRegistry() - labels := prometheus.Labels{ - networkLabel: network.String(), - nodeTypeLabel: nodeType.String(), - peerIDLabel: peerID.String(), - } - return prometheus.WrapRegistererWith(labels, reg) -}