Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
add latency / size metrics for error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott committed Feb 19, 2023
1 parent adbe481 commit d2d30ed
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,18 @@ func (p *pool) doFetch(ctx context.Context, from string, c cid.Cid) (b blocks.Bl
requestId := uuid.NewString()
goLogger.Debugw("doing fetch", "from", from, "of", c, "requestId", requestId)
start := time.Now()
fb := time.Now()
fb := time.Unix(0, 0)
code := 0
proto := "unknown"
respReq := &http.Request{}
received := 0
defer func() {
goLogger.Debugw("fetch result", "from", from, "of", c, "status", code, "size", received, "ttfb", int(fb.Sub(start).Milliseconds()), "duration", time.Since(start).Seconds())
fetchResponseMetric.WithLabelValues(fmt.Sprintf("%d", code)).Add(1)
if e == nil {
if fb.After(start) {
fetchLatencyMetric.Observe(float64(fb.Sub(start).Milliseconds()))
}
if received > 0 {
fetchSpeedMetric.Observe(float64(received) / time.Since(start).Seconds())
fetchSizeMetric.Observe(float64(received))
}
Expand Down

0 comments on commit d2d30ed

Please sign in to comment.