Skip to content

Commit 7c5022c

Browse files
committed
Introduce sent blocks histogram
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
1 parent f91697b commit 7c5022c

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

exchange/bitswap/bitswap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
7979
// exclusively. We should probably find another way to share logging data
8080
ctx, cancelFunc := context.WithCancel(parent)
8181
ctx = metrics.CtxSubScope(ctx, "bitswap")
82-
dupHist := metrics.NewCtx(ctx, "dup_blocks_bytes", "Summary of duplicate"+
82+
dupHist := metrics.NewCtx(ctx, "recv_dup_blocks_bytes", "Summary of duplicate"+
8383
" data blocks recived").Histogram(metricsBuckets)
84-
allHist := metrics.NewCtx(ctx, "all_blocks_bytes", "Summary of all"+
84+
allHist := metrics.NewCtx(ctx, "recv_all_blocks_bytes", "Summary of all"+
8585
" data blocks recived").Histogram(metricsBuckets)
8686

8787
notif := notifications.New()

exchange/bitswap/wantmanager.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ type WantManager struct {
3030
ctx context.Context
3131
cancel func()
3232

33-
metricWantlist metrics.Gauge
33+
wantlistGauge metrics.Gauge
34+
sentHistogram metrics.Histogram
3435
}
3536

3637
func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager {
3738
ctx, cancel := context.WithCancel(ctx)
3839
wantlistGauge := metrics.NewCtx(ctx, "wanlist_total",
3940
"Number of items in wantlist.").Gauge()
41+
sentHistogram := metrics.NewCtx(ctx, "sent_all_blocks_bytes", "Histogram of blocks sent by"+
42+
" this bitswap").Histogram(metricsBuckets)
4043
return &WantManager{
41-
incoming: make(chan []*bsmsg.Entry, 10),
42-
connect: make(chan peer.ID, 10),
43-
disconnect: make(chan peer.ID, 10),
44-
peerReqs: make(chan chan []peer.ID),
45-
peers: make(map[peer.ID]*msgQueue),
46-
wl: wantlist.NewThreadSafe(),
47-
network: network,
48-
ctx: ctx,
49-
cancel: cancel,
50-
metricWantlist: wantlistGauge,
44+
incoming: make(chan []*bsmsg.Entry, 10),
45+
connect: make(chan peer.ID, 10),
46+
disconnect: make(chan peer.ID, 10),
47+
peerReqs: make(chan chan []peer.ID),
48+
peers: make(map[peer.ID]*msgQueue),
49+
wl: wantlist.NewThreadSafe(),
50+
network: network,
51+
ctx: ctx,
52+
cancel: cancel,
53+
wantlistGauge: wantlistGauge,
54+
sentHistogram: sentHistogram,
5155
}
5256
}
5357

@@ -116,6 +120,8 @@ func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope) {
116120
// throughout the network stack
117121
defer env.Sent()
118122

123+
pm.sentHistogram.Observe(float64(len(env.Block.RawData())))
124+
119125
msg := bsmsg.New(false)
120126
msg.AddBlock(env.Block)
121127
log.Infof("Sending block %s to %s", env.Block, env.Peer)
@@ -289,12 +295,12 @@ func (pm *WantManager) Run() {
289295
for _, e := range entries {
290296
if e.Cancel {
291297
if pm.wl.Remove(e.Cid) {
292-
pm.metricWantlist.Dec()
298+
pm.wantlistGauge.Dec()
293299
filtered = append(filtered, e)
294300
}
295301
} else {
296302
if pm.wl.AddEntry(e.Entry) {
297-
pm.metricWantlist.Inc()
303+
pm.wantlistGauge.Inc()
298304
filtered = append(filtered, e)
299305
}
300306
}

0 commit comments

Comments
 (0)