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

add latency / size metrics for error cases #32

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,7 @@ func (p *pool) fetchWith(ctx context.Context, c cid.Cid, with string) (blk block
}

for i := 0; i < len(nodes); i++ {
blk, err = p.doFetch(ctx, nodes[i], c)
if err != nil {
goLogger.Debugw("fetch failed", "from", nodes[i], "of", c, "attempt", i, "error", err)
}
blk, err = p.doFetch(ctx, nodes[i], c, i)

var idx int
var nm *Member
Expand Down Expand Up @@ -345,21 +342,25 @@ func (p *pool) updateWeightUnlocked(node string, failure bool) (index int, membe
var saturnReqTmpl = "https://%s/ipfs/%s?format=raw"

// doFetch attempts to fetch a block from a given Saturn endpoint. It sends the retrieval logs to the logging endpoint upon a successful or failed attempt.
func (p *pool) doFetch(ctx context.Context, from string, c cid.Cid) (b blocks.Block, e error) {
func (p *pool) doFetch(ctx context.Context, from string, c cid.Cid, attempt int) (b blocks.Block, e error) {
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())
ttfbMs := fb.Sub(start).Milliseconds()
durationSecs := time.Since(start).Seconds()
goLogger.Debugw("fetch result", "from", from, "of", c, "status", code, "size", received, "ttfb", int(ttfbMs), "duration", durationSecs, "attempt", attempt, "error", e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ replaced two debugs logs per request with one (success will have error equal null here)

fetchResponseMetric.WithLabelValues(fmt.Sprintf("%d", code)).Add(1)
if e == nil {
fetchLatencyMetric.Observe(float64(fb.Sub(start).Milliseconds()))
fetchSpeedMetric.Observe(float64(received) / time.Since(start).Seconds())
if fb.After(start) {
fetchLatencyMetric.Observe(float64(ttfbMs))
}
if received > 0 {
fetchSpeedMetric.Observe(float64(received) / durationSecs)
fetchSizeMetric.Observe(float64(received))
}
p.logger.queue <- log{
Expand All @@ -368,11 +369,11 @@ func (p *pool) doFetch(ctx context.Context, from string, c cid.Cid) (b blocks.Bl
LocalTime: start,
// TODO: does this include header sizes?
NumBytesSent: received,
RequestDuration: time.Since(start).Seconds(),
RequestDuration: durationSecs,
RequestID: requestId,
HTTPStatusCode: code,
HTTPProtocol: proto,
TTFBMS: int(fb.Sub(start).Milliseconds()),
TTFBMS: int(ttfbMs),
// my address
ClientAddress: "",
Range: "",
Expand Down