Skip to content

fix(mixin): filter empty-image cgroup series out of the CPU scaling rule - #16320

Merged
narqo merged 1 commit into
grafana:mainfrom
jmichalek132:jmichalek132/mixin-cpu-usage-filter-pause-cgroups
Aug 11, 2026
Merged

fix(mixin): filter empty-image cgroup series out of the CPU scaling rule#16320
narqo merged 1 commit into
grafana:mainfrom
jmichalek132:jmichalek132/mixin-cpu-usage-filter-pause-cgroups

Conversation

@jmichalek132

Copy link
Copy Markdown
Contributor

What this PR does

cluster_namespace_deployment:container_cpu_usage_seconds_total:sum_rate sums
container_cpu_usage_seconds_total with no selector, while the sibling memory_usage rule
already reads container_memory_usage_bytes{image!=""}. Both come from the same cAdvisor job,
so the two are inconsistent: where the scrape keeps the sandbox and parent cgroup series next
to the per-container ones, the CPU rule counts the same CPU time twice.

This is not just a cosmetic wrong number, because cpu_required_replicas_count divides the
recorded CPU usage by CPU requests. A 2x inflated numerator makes the Scaling dashboard
recommend roughly double the replicas a deployment actually needs.

Measured on an affected cAdvisor scrape: 368.9 cores unfiltered versus 183.5 with image!="".

This PR adds image!="" to the CPU selector so it matches memory_usage. Installations that
already drop those series at scrape time are unaffected. The compiled mixin and the helm
golden records are regenerated accordingly.

Which issue(s) this PR fixes or relates to

Fixes #9005

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]. If changelog entry is not needed, please add the changelog-not-needed label to the PR.
  • about-versioning.md updated with experimental features.

@jmichalek132
jmichalek132 requested a review from a team as a code owner August 6, 2026 18:57

@narqo narqo 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.

The changes look good to me. It seems that GitHub actions had issues right around the time when the PR was opened. Could you rebase the changes to re-trigger the CI. Thank you

@narqo
narqo enabled auto-merge (squash) August 10, 2026 12:20
cluster_namespace_deployment:container_cpu_usage_seconds_total:sum_rate sums
container_cpu_usage_seconds_total without the image!="" selector that the
sibling memory_usage rule already applies. Both read the same cAdvisor job, so
where the scrape retains the sandbox and parent cgroup series next to the real
per-container ones, the CPU rule counts the same CPU time twice.

The recorded value feeds cpu_required_replicas_count, which divides CPU usage by
CPU requests, so the Scaling dashboard recommends roughly double the replicas a
deployment actually needs. Measured on one affected cAdvisor scrape: 368.9 cores
unfiltered versus 183.5 with image!="", a 2.0x overcount.

Fixes grafana#9005
auto-merge was automatically disabled August 10, 2026 13:02

Head branch was pushed to by a user without write access

@jmichalek132
jmichalek132 force-pushed the jmichalek132/mixin-cpu-usage-filter-pause-cgroups branch from 4a8d170 to 4bf3471 Compare August 10, 2026 13:02
@jmichalek132

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Rebased onto latest main. I also rebased #16323, which was in the same state.

The rebase alone doesn't seem to be enough though: the PR shows "33 workflows awaiting approval / This workflow requires approval from a maintainer", and on the new head every run comes back as action_required (ci, helm-ci, Changelog Check, compare-helm-with-jsonnet, CodeQL, TruffleHog, zizmor, Regenerate docs and helm tests, Build and Push mimir-build-image). Only the pull_request_target ones ran on their own. I left Grafana recently, so these now come in as outside-contributor PRs and each push needs a maintainer to hit "Approve and run workflows". Could you approve the runs on both PRs?

@narqo
narqo enabled auto-merge (squash) August 11, 2026 07:34
@narqo
narqo merged commit cf5bb16 into grafana:main Aug 11, 2026
142 of 203 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading recording rule for cluster_namespace_deployment:container_cpu_usage_seconds_total:sum_rate

2 participants