Skip to content

Commit

Permalink
swarm: add a basic metrics tracer (#1973)
Browse files Browse the repository at this point in the history
* swarm: add very basic metrics for opening and closing connections

* swarm: use a sync.Pool to make metrics collection allocation-free

* swarm: introduce a MetricsTracer interface

* swarm: add the transport to the dial error metric

* swarm: add Grafana dashboard

* swarm: use the prometheus namespace option
  • Loading branch information
marten-seemann committed Jan 27, 2023
1 parent d5a280e commit 3919359
Show file tree
Hide file tree
Showing 9 changed files with 2,521 additions and 8 deletions.
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Config struct {
HolePunchingOptions []holepunch.Option
}

func (cfg *Config) makeSwarm() (*swarm.Swarm, error) {
func (cfg *Config) makeSwarm(enableMetrics bool) (*swarm.Swarm, error) {
if cfg.Peerstore == nil {
return nil, fmt.Errorf("no peerstore specified")
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func (cfg *Config) makeSwarm() (*swarm.Swarm, error) {
return nil, err
}

opts := make([]swarm.Option, 0, 3)
opts := make([]swarm.Option, 0, 6)
if cfg.Reporter != nil {
opts = append(opts, swarm.WithMetrics(cfg.Reporter))
}
Expand All @@ -167,6 +167,9 @@ func (cfg *Config) makeSwarm() (*swarm.Swarm, error) {
if cfg.MultiaddrResolver != nil {
opts = append(opts, swarm.WithMultiaddrResolver(cfg.MultiaddrResolver))
}
if enableMetrics {
opts = append(opts, swarm.WithMetricsTracer(swarm.NewMetricsTracer()))
}
// TODO: Make the swarm implementation configurable.
return swarm.NewSwarm(pid, cfg.Peerstore, opts...)
}
Expand Down Expand Up @@ -276,7 +279,7 @@ func (cfg *Config) addTransports(h host.Host) error {
//
// This function consumes the config. Do not reuse it (really!).
func (cfg *Config) NewNode() (host.Host, error) {
swrm, err := cfg.makeSwarm()
swrm, err := cfg.makeSwarm(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -382,7 +385,7 @@ func (cfg *Config) NewNode() (host.Host, error) {
Peerstore: ps,
}

dialer, err := autoNatCfg.makeSwarm()
dialer, err := autoNatCfg.makeSwarm(false)
if err != nil {
h.Close()
return nil, err
Expand Down
Loading

0 comments on commit 3919359

Please sign in to comment.