Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dot/network): introduce libp2p resource manager + prometheus metrics #3333

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
"github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoreds"
rm "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
rmObs "github.com/libp2p/go-libp2p/p2p/host/resource-manager/obs"
ma "github.com/multiformats/go-multiaddr"
"github.com/prometheus/client_golang/prometheus"
)

func newPrivateIPFilters() (privateIPs *ma.Filters, err error) {
Expand Down Expand Up @@ -178,8 +181,27 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
return nil, fmt.Errorf("failed to create peerstore: %w", err)
}

limiter := rm.NewFixedLimiter(rm.DefaultLimits.AutoScale())
var managerOptions []rm.Option

if cfg.Metrics.Publish {
rmObs.MustRegisterWith(prometheus.DefaultRegisterer)
reporter, err := rmObs.NewStatsTraceReporter()
if err != nil {
return nil, fmt.Errorf("while creating resource manager stats trace reporter: %w", err)
}

managerOptions = append(managerOptions, rm.WithTraceReporter(reporter))
}

manager, err := rm.NewResourceManager(limiter, managerOptions...)
if err != nil {
return nil, fmt.Errorf("while creating the resource manager: %w", err)
}

// set libp2p host options
opts := []libp2p.Option{
libp2p.ResourceManager(manager),
libp2p.ListenAddrs(addr),
libp2p.DisableRelay(),
libp2p.Identity(cfg.privateKey),
Expand Down