@cryptotaxi247 / kubo / commits / 679d3d21b

Add obs to resource manager

Marco Munizaga committed Jun 21, 2022 at 08:00 UTC 679d3d21b986814982858de417f5f379c191b952
1 file changed +17 -1
core/node/libp2p/rcmgr.go
+17 -1
@@ -7,6 +7,7 @@ import (
7 "path/filepath"
8 "strings"
9
10 + ocprom "contrib.go.opencensus.io/exporter/prometheus"
11 "github.com/benbjohnson/clock"
12 logging "github.com/ipfs/go-log/v2"
13 config "github.com/ipfs/kubo/config"
@@ -18,6 +19,9 @@ import (
19 "github.com/libp2p/go-libp2p-core/peer"
20 "github.com/libp2p/go-libp2p-core/protocol"
21 rcmgr "github.com/libp2p/go-libp2p-resource-manager"
22 + rcmgrObs "github.com/libp2p/go-libp2p-resource-manager/obs"
23 + "github.com/prometheus/client_golang/prometheus"
24 + "go.opencensus.io/stats/view"
25
26 "go.uber.org/fx"
27 )
@@ -62,7 +66,19 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
66
67 limiter := rcmgr.NewFixedLimiter(limits)
68
65 - ropts := []rcmgr.Option{rcmgr.WithMetrics(createRcmgrMetrics())}
69 + str, err := rcmgrObs.NewStatsTraceReporter()
70 + if err != nil {
71 + return nil, opts, err
72 + }
73 +
74 + ropts := []rcmgr.Option{rcmgr.WithMetrics(createRcmgrMetrics()), rcmgr.WithTraceReporter(str)}
75 +
76 + // Hook up the trace reporter metrics
77 + view.Register(rcmgrObs.DefaultViews...)
78 + ocprom.NewExporter(ocprom.Options{
79 + Registry: prometheus.DefaultRegisterer.(*prometheus.Registry),
80 + Namespace: "rcmgr_trace_metrics",
81 + })
82
83 if os.Getenv("LIBP2P_DEBUG_RCMGR") != "" {
84 traceFilePath := filepath.Join(repoPath, NetLimitTraceFilename)