Skip to content

Commit 65d948d

Browse files
committed
bitswap/httnet: add response size metric
1 parent 016a7e5 commit 65d948d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

bitswap/network/httpnet/metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
var durationHistogramBuckets = []float64{0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60, 120, 240, 480, 960, 1920}
1010

11+
var blockSizesHistogramBuckets = []float64{1, 128 << 10, 256 << 10, 512 << 10, 1024 << 10, 2048 << 10, 4092 << 10}
12+
1113
type ctxKeyT string
1214

1315
var ctxKey ctxKeyT = ctxKeyT(imetrics.CtxScopeKey)
@@ -68,6 +70,10 @@ func requestTime(ctx context.Context) imetrics.Histogram {
6870
return imetrics.NewCtx(ctx, "httpnet_request_duration_seconds", "Histogram of request durations").Histogram(durationHistogramBuckets)
6971
}
7072

73+
func responseSize(ctx context.Context) imetrics.Histogram {
74+
return imetrics.NewCtx(ctx, "httpnet_response_bytes", "Histogram of http response sizes").Histogram(blockSizesHistogramBuckets)
75+
}
76+
7177
type metrics struct {
7278
RequestsInFlight imetrics.Gauge
7379
RequestsTotal imetrics.Counter
@@ -83,6 +89,7 @@ type metrics struct {
8389
StatusInternalServerError imetrics.Counter
8490
StatusOthers imetrics.Counter
8591
RequestTime imetrics.Histogram
92+
ResponseSize imetrics.Histogram
8693
}
8794

8895
func newMetrics() *metrics {
@@ -103,6 +110,7 @@ func newMetrics() *metrics {
103110
StatusInternalServerError: statusInternalServerError(ctx),
104111
StatusOthers: statusOthers(ctx),
105112
RequestTime: requestTime(ctx),
113+
ResponseSize: responseSize(ctx),
106114
}
107115
}
108116

bitswap/network/httpnet/msg_sender.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
254254
}
255255
}
256256
reqDuration := time.Since(reqStart)
257-
257+
sender.ht.metrics.ResponseSize.Observe(float64(len(body)))
258258
sender.ht.metrics.RequestsInFlight.Dec()
259259
sender.ht.metrics.RequestTime.Observe(float64(reqDuration) / float64(time.Second))
260260
sender.ht.metrics.updateStatusCounter(resp.StatusCode)

0 commit comments

Comments
 (0)