Skip to content

fix(agent): emit blob download RPS metric even on failure#599

Merged
Anton-Kalpakchiev merged 2 commits into
masterfrom
emit-agent-download-blob-qps-attempt-2
Apr 16, 2026
Merged

fix(agent): emit blob download RPS metric even on failure#599
Anton-Kalpakchiev merged 2 commits into
masterfrom
emit-agent-download-blob-qps-attempt-2

Conversation

@Anton-Kalpakchiev
Copy link
Copy Markdown
Collaborator

The current QPS metric for agent downloads is in the ro_transferer's Download method, which does not always get called on blob downloads. This PR moves it into the P2P scheduler's Download method, which is always called when a blob is downloaded, unless there's a cache hit.

Reasoning

Container runtimes (e.g. containerd) usually call the HEAD API on an image layer, before calling GET, for various reasons. However, agent has implemented its API, such that even the HEAD API triggers a P2P image download. This means that the HEAD API is blocked by agent downloading the full blob (might be 10+GB). If that blob download errors out or times out, containerd doesn't reach the GET API step, meaning that the QPS metric in the ro_transferer's Download method is never called, while kraken-agent started a blob download.

Emitting QPS in the scheduler instead of the transferer has 1 downside, which is that cache hits against the agent's disk cache do not emit the metric. I am making this trade-off consciously, as

  1. I expect there to be fewer cache hits than downloads that timeout/fail, and thus never reach the transferer's Download API. My reasoning is that images get cached in containerd's cache after being served by agent, so subsequent image downloads on the host will hit that cache, before hitting agent's

I explored other approaches, where we emit the data in Stat, but containerd and dockerd are inconsistent with when they call HEAD and when they skip it, so such a metric would be unreliable and very bug-prone, so I opted for the simpler, error-free approach.

Comment thread lib/torrent/scheduler/scheduler.go Outdated
@Anton-Kalpakchiev Anton-Kalpakchiev merged commit 8fa8051 into master Apr 16, 2026
10 checks passed
@Anton-Kalpakchiev Anton-Kalpakchiev deleted the emit-agent-download-blob-qps-attempt-2 branch April 16, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants