Skip to content

Commit

Permalink
remove type assert
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss authored and Wondertan committed Jun 18, 2024
1 parent e2d2498 commit 5b5dc86
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions nodebuilder/p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
func WithMetrics() fx.Option {
return fx.Options(
fx.Provide(resourceManagerOpt(traceReporter)),
fx.Provide(prometheusRegisterer),
fx.Invoke(prometheusMetrics),
)
}
Expand All @@ -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)
Expand All @@ -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)
}

0 comments on commit 5b5dc86

Please sign in to comment.