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 ( ...@@ -9,6 +9,8 @@ import (
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message" bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid" cid "gx/ipfs/QmV5gPoRsjN1Gid3LMdNZTyfCtP2DsvqEbMAmz82RmmiGk/go-cid"
peer "gx/ipfs/QmZcUPvPhD1Xvk6mwijYF8AfR3mG31S1YsEfHG4khrFPRr/go-libp2p-peer" peer "gx/ipfs/QmZcUPvPhD1Xvk6mwijYF8AfR3mG31S1YsEfHG4khrFPRr/go-libp2p-peer"
) )
...@@ -27,20 +29,25 @@ type WantManager struct { ...@@ -27,20 +29,25 @@ type WantManager struct {
network bsnet.BitSwapNetwork network bsnet.BitSwapNetwork
ctx context.Context ctx context.Context
cancel func() cancel func()
metricWantlist metrics.Gauge
} }
func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager { func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
wantlistGauge := metrics.NewCtx(ctx, "wanlist_total",
"Number of items in wantlist.").Gauge()
return &WantManager{ return &WantManager{
incoming: make(chan []*bsmsg.Entry, 10), incoming: make(chan []*bsmsg.Entry, 10),
connect: make(chan peer.ID, 10), connect: make(chan peer.ID, 10),
disconnect: make(chan peer.ID, 10), disconnect: make(chan peer.ID, 10),
peerReqs: make(chan chan []peer.ID), peerReqs: make(chan chan []peer.ID),
peers: make(map[peer.ID]*msgQueue), peers: make(map[peer.ID]*msgQueue),
wl: wantlist.NewThreadSafe(), wl: wantlist.NewThreadSafe(),
network: network, network: network,
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
metricWantlist: wantlistGauge,
} }
} }
...@@ -282,10 +289,12 @@ func (pm *WantManager) Run() { ...@@ -282,10 +289,12 @@ func (pm *WantManager) Run() {
for _, e := range entries { for _, e := range entries {
if e.Cancel { if e.Cancel {
if pm.wl.Remove(e.Cid) { if pm.wl.Remove(e.Cid) {
pm.metricWantlist.Dec()
filtered = append(filtered, e) filtered = append(filtered, e)
} }
} else { } else {
if pm.wl.AddEntry(e.Entry) { if pm.wl.AddEntry(e.Entry) {
pm.metricWantlist.Inc()
filtered = append(filtered, e) 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