Skip to content

cri: exclude cached layer bytes from image_pulling_throughput_mibps - #13245

Merged
mikebrow merged 2 commits into
containerd:mainfrom
ahmetb:fix-image-pulling-throughput-cached-layers
Jun 26, 2026
Merged

mikebrow merged 2 commits into
containerd:mainfrom
ahmetb:fix-image-pulling-throughput-cached-layers

Conversation

@ahmetb

@ahmetb ahmetb commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #13244.

image_pulling_throughput metric currently calculates full image size / wall-clock pull duration. This inflates the metric when there are cached layers in the content store, and produces near-infinite data points for noop pulls.

  • This change plumbs the bytes actually fetched (totalBytesRead from pullRequestReporter, which is already maintained for progress/timeout checks in both pull paths) out of pullImageWithLocalPull and pullImageWithTransferService, and uses that in place of image.Size(ctx). Fully-cached pulls (bytesPulled == 0) are skipped.

  • To prevent a breaking change in time-series buckets, we introduce a new image_pulling_throughput_mibps metric; and deprecate the image_pulling_throughput.

  • Also updates the metric's Help text to note that the denominator spans the whole pull including extraction, not just network transfer.

See #13244 for motivation and considered alternatives (zero-sample, cached label, ingester wrapper).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates CRI image pulling throughput metrics so image_pulling_throughput reflects only bytes actually fetched from the registry (excluding cached layer bytes), avoiding inflated/near-infinite samples when pulls hit cache.

Changes:

  • Plumbs bytesPulled (bytes actually fetched) from both local-pull and transfer-service pull paths back to PullImage.
  • Records throughput using fetched bytes over end-to-end pull duration, skipping fully-cached pulls (bytesPulled == 0).
  • Adds unit-test coverage for the new throughput recording helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/cri/server/images/metrics.go Adds recordImagePullThroughput helper and updates metric HELP text.
internal/cri/server/images/image_pull.go Returns bytesPulled from both pull implementations and uses it for throughput observation.
internal/cri/server/images/image_pull_test.go Adds tests validating observation behavior and computed MB/s values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cri/server/images/metrics.go Resolved
Comment thread internal/cri/server/images/metrics.go Resolved
@ahmetb ahmetb closed this Apr 17, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Pull Request Review Apr 17, 2026
@ahmetb ahmetb reopened this Apr 17, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs Triage in Pull Request Review Apr 17, 2026
@ahmetb
ahmetb marked this pull request as ready for review April 20, 2026 17:37
@dosubot dosubot Bot added the area/cri Container Runtime Interface (CRI) label Apr 20, 2026
Comment thread internal/cri/server/images/metrics.go Resolved
Comment thread internal/cri/server/images/metrics.go Outdated
prom "github.com/prometheus/client_golang/prometheus"
)

const mbToByte = 1024 * 1024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know we had the same thing above in another file, but I agree with the robot. I'd prefer if this was mib, and any comments list as such as well.

@dcantah

dcantah commented Apr 25, 2026

Copy link
Copy Markdown
Member

This makes sense to me, only comments are on the wording of the units being used.

@ahmetb

ahmetb commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

@dcantah would readjusting the prometheus histogram buckets be considered a breaking change here or not?

@dcantah

dcantah commented Apr 30, 2026

Copy link
Copy Markdown
Member

@ahmetb The existing one I would probably classify as breaking to change. We could add in a new one and "deprecate" the old I suppose:

+
        imagePullThroughput = prom.NewHistogram(
                prom.HistogramOpts{
                        Namespace: namespace,
                        Subsystem: subsystem,
                        Name:      "image_pulling_throughput",
-                       Help:      "image pull throughput",
+                       Help:      "Deprecated: use image_pulling_throughput_mibps instead",
                        Buckets:   prom.DefBuckets,
                },
        )
+
+       imagePullThroughputMiBps = prom.NewHistogram(
+               prom.HistogramOpts{
+                       Namespace: namespace,
+                       Subsystem: subsystem,
+                       Name:      "image_pulling_throughput_mibps",
+                       Help:      "image pull throughput in MiB/s (fetched bytes / pull duration; cached layers excluded)",
+                       Buckets:   []float64{0.1, 1, 10, 25, 75, 150, 300, 500, 1000, 2000},
+               },
+       )
+
        ns.Add(imagePullThroughput)
+       ns.Add(imagePullThroughputMiBps)
        metrics.Register(ns)
 }

@ahmetb ahmetb changed the title cri: exclude cached layer bytes from image_pulling_throughput cri: exclude cached layer bytes from image_pulling_throughput_mibps May 4, 2026
@ahmetb

ahmetb commented May 4, 2026 •

Copy link
Copy Markdown
Contributor Author

OK readjusted based on feedback.

  • New metric is introduced with _mibps suffix to be explicitly clear.
  • Old metric marked as deprecated (for simplicity, we change its behavior to exclude cached layers now)

I'm not sure how to coordinate the Release Notes/Deprecations process in this project, but probably both can coexist for a while.

@dcantah

dcantah commented May 4, 2026

Copy link
Copy Markdown
Member

cc @dmcgowan as we'd talked about the prom buckets idea

@omerXfaruq omerXfaruq left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM, tested this version and metrics looks correct. Cached images were excluded from the results.

4 cold pulls and 3 warm pulls were reflected in calculation.

Pull throughput speeds calculated from (image size/pod startup time) matched with metric results.

$ curl localhost:16767/v1/metrics | grep image_pulls_total

containerd_cri_sandboxed_image_pulls_total{status="success"} 7

$ curl localhost:16767/v1/metrics | grep containerd_cri_sandboxed_image_pulling_throughput_count

containerd_cri_sandboxed_image_pulling_throughput_count 4
Pods scheduled on host:

  22:57:21Z  cold-pull    
  23:00:48Z  warm-pull 
  23:04:44Z  warm        
  23:04:45Z  cold       
  23:04:45Z  cold    
  23:31:08Z  warm   
  23:33:11Z  cold      

@ahmetb

ahmetb commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@k8s-ci-robot

Copy link
Copy Markdown

@ahmetb: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ahmetb

ahmetb commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@dcantah do you mind doing a /retest on this one? reviews appreciated too

@dcantah

dcantah commented May 17, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@dcantah

dcantah commented May 17, 2026

Copy link
Copy Markdown
Member

/retest

@omerXfaruq

Copy link
Copy Markdown

@dcantah do you know why the tests are not running?

Copilot AI review requested due to automatic review settings June 3, 2026 17:03
@ahmetb
ahmetb force-pushed the fix-image-pulling-throughput-cached-layers branch from 743e8ee to f599ebb Compare June 3, 2026 17:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread internal/cri/server/images/metrics.go Resolved
@ahmetb

ahmetb commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

please take a look again, it would be good to get this in sometime

@mikebrow
mikebrow force-pushed the fix-image-pulling-throughput-cached-layers branch 2 times, most recently from b60b759 to df9a1b1 Compare June 18, 2026 23:16
Copilot AI review requested due to automatic review settings June 18, 2026 23:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Not ready to approve

The transfer-service pull path can deadlock and/or fail to track bytes when image_pull_progress_timeout is configured as 0, and the metric HELP text currently omits the “includes extraction/unpack” duration semantics described in the PR.

Copilot's findings
  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

Comment thread internal/cri/server/images/metrics.go Resolved
Comment thread internal/cri/server/images/metrics.go Resolved
Comment on lines 336 to 338
transferProgressReporter.start(rctx)
log.G(ctx).Debugf("Calling cri transfer service")
err = c.transferrer.Transfer(rctx, reg, is, transfer.WithProgress(transferProgressReporter.createProgressFunc(rctx)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ahmetb would you like to tackle this one? Seems a fair argument that this code had a potential config issue. https://github.com/containerd/containerd/blob/main/internal/cri/config/config.go#L544-L549 validation probably needs to be looked at. Some options: 1) report a warning, 2) error if duration is zero, 3) use default (5min) if set to 0, or some other minimum.

@mikebrow
mikebrow force-pushed the fix-image-pulling-throughput-cached-layers branch from df9a1b1 to f5d4b42 Compare June 24, 2026 19:35
ahmetb added 2 commits June 25, 2026 07:55
The image_pulling_throughput histogram divided the full image size (all
layers plus config) by wall-clock pull duration. Layers already present
in the content store were counted in the numerator, so the reported
MB/s came out way higher than what was actually fetched. Fully-cached
pulls were the worst case: they "pulled" in milliseconds but reported
the full image size, showing up as huge outliers in the histogram.

Both pull paths (local client.Pull and the transfer service) already
maintain a totalBytesRead counter in pullRequestReporter for progress
and timeout checks. Cached blobs never trigger a fetch, so the counter
naturally excludes them. Plumb that value out of both helpers and use
it in place of image.Size(ctx). Fully-cached pulls (bytesPulled == 0)
are not observed, so they don't produce near-infinite samples.

Also updates the metric's Help text to say the denominator is the
end-to-end pull duration including layer extraction and snapshotter
unpack, not just network transfer.

Addresses containerd#13244

Signed-off-by: Ahmet Alp Balkan <[email protected]>
…hroughput

Address review feedback on the previous commit:

- Use MiB/s (binary, 1024^2) consistently. The divisor was already
  1024*1024; the constant name (mbToByte) and the Help/comment text
  mislabeled the unit.
- Keep image_pulling_throughput for backwards compatibility but mark
  it Deprecated. Its prom.DefBuckets top out at 10 MiB/s, which
  saturates almost immediately on modern hardware.
- Add image_pulling_throughput_mibps with buckets covering 0.1 MiB/s
  through 4000 MiB/s (~31 Gbps), enough for 10G+ NICs. Above that,
  disk write throughput becomes the bottleneck rather than the
  network, so finer buckets aren't worth the cardinality.
- Both metrics observe the same value (fetched bytes / pull duration,
  cached layers excluded; fully-cached pulls skipped). Only the
  buckets and deprecation status differ.

Signed-off-by: Ahmet Alp Balkan <[email protected]>
Copilot AI review requested due to automatic review settings June 25, 2026 12:55
@mikebrow
mikebrow force-pushed the fix-image-pulling-throughput-cached-layers branch from f5d4b42 to 16ff70b Compare June 25, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread internal/cri/server/images/metrics.go Resolved
Comment thread internal/cri/server/images/metrics.go Resolved

@mikebrow mikebrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 25, 2026
@mikebrow
mikebrow added this pull request to the merge queue Jun 26, 2026
Merged via the queue into containerd:main with commit 7de5a29 Jun 26, 2026
51 of 52 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) ok-to-test size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants