Commit c4f7e855 authored by Jakub Sztandera's avatar Jakub Sztandera

Add metric of number of elements in the wantlist

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protonmail.ch>
parent 78ce3724
......@@ -9,6 +9,8 @@ import (
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
peer "gx/ipfs/QmZcUPvPhD1Xvk6mwijYF8AfR3mG31S1YsEfHG4khrFPRr/go-libp2p-peer"
)
......@@ -27,10 +29,14 @@ type WantManager struct {
network bsnet.BitSwapNetwork
ctx context.Context
cancel func()
metricWantlist metrics.Gauge
}
func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager {
ctx, cancel := context.WithCancel(ctx)
wantlistGauge := metrics.NewCtx(ctx, "wanlist_total",
"Number of items in wantlist.").Gauge()
return &WantManager{
incoming: make(chan []*bsmsg.Entry, 10),
connect: make(chan peer.ID, 10),
......@@ -41,6 +47,7 @@ func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantMana
network: network,
ctx: ctx,
cancel: cancel,
metricWantlist: wantlistGauge,
}
}
......@@ -282,10 +289,12 @@ func (pm *WantManager) Run() {
for _, e := range entries {
if e.Cancel {
if pm.wl.Remove(e.Cid) {
pm.metricWantlist.Dec()
filtered = append(filtered, e)
}
} else {
if pm.wl.AddEntry(e.Entry) {
pm.metricWantlist.Inc()
filtered = append(filtered, e)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment