Skip to content

Commit

Permalink
rcmgr: enable metrics by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Jun 23, 2023
1 parent a808b9d commit 26b6839
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion p2p/host/resource-manager/obs/obs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ var MustRegisterWith = rcmgr.MustRegisterWith
// StatsTraceReporter reports stats on the resource manager using its traces.
type StatsTraceReporter = rcmgr.StatsTraceReporter

var NewStatsTraceReporter = rcmgr.NewStatsTraceReporter
func NewStatsTraceReporter() (StatsTraceReporter, error) {
return rcmgr.StatsTraceReporter{}, nil
}
22 changes: 20 additions & 2 deletions p2p/host/resource-manager/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ var log = logging.Logger("rcmgr")
type resourceManager struct {
limits Limiter

trace *trace
metrics *metrics
trace *trace
metrics *metrics
disableMetrics bool

allowlist *Allowlist

Expand Down Expand Up @@ -141,6 +142,23 @@ func NewResourceManager(limits Limiter, opts ...Option) (network.ResourceManager
}
}

if !r.disableMetrics {
if r.trace == nil {
r.trace = &trace{}
}
var sr TraceReporter = StatsTraceReporter{}
found := false
for _, rep := range r.trace.reporters {
if rep == sr {
found = true
break
}
}
if !found {
r.trace.reporters = append(r.trace.reporters, sr)
}
}

if err := r.trace.Start(limits); err != nil {
return nil, err
}
Expand Down
12 changes: 7 additions & 5 deletions p2p/host/resource-manager/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ func MustRegisterWith(reg prometheus.Registerer) {
)
}

func DisableMetrics() Option {
return func(r *resourceManager) error {
r.disableMetrics = true
return nil
}
}

// StatsTraceReporter reports stats on the resource manager using its traces.
type StatsTraceReporter struct{}

func NewStatsTraceReporter() (StatsTraceReporter, error) {
// TODO tell prometheus the system limits
return StatsTraceReporter{}, nil
}

func (r StatsTraceReporter) ConsumeEvent(evt TraceEvt) {
tags := metricshelper.GetStringSlice()
defer metricshelper.PutStringSlice(tags)
Expand Down

0 comments on commit 26b6839

Please sign in to comment.