Skip to content

add podCount metric queries in resource_optimization_local_monitoring_norecordingrules.yaml - #2017

Open
mbvreddy wants to merge 1 commit into
kruize:mvp_demofrom
mbvreddy:issue_2016
Open

add podCount metric queries in resource_optimization_local_monitoring_norecordingrules.yaml#2017
mbvreddy wants to merge 1 commit into
kruize:mvp_demofrom
mbvreddy:issue_2016

Conversation

@mbvreddy

@mbvreddy mbvreddy commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR address issue #2016. As part of this, podCount metric queries are added to resource_optimization_local_monitoring_norecordingrules.yaml file which was missed in earlier PR #1932

Fixes # (issue)

Type of change

  • Bug fix
  • New feature
  • Docs update
  • Breaking change (What changes might users need to make in their application due to this PR?)
  • Requires DB changes

How has this been tested?

Please describe the tests that were run to verify your changes and steps to reproduce. Please specify any test configuration required.

  • New Test X
  • Functional testsuite

Test Configuration

  • Kubernetes clusters tested on:

Checklist 🎯

  • Followed coding guidelines
  • Comments added
  • Dependent changes merged
  • Documentation updated
  • Tests added or updated

Additional information

Include any additional information such as links, test results, screenshots here

Summary by Sourcery

Add pod readiness-based podCount metric to the resource optimization local monitoring performance profile.

New Features:

  • Introduce podCount metric leveraging Prometheus kube_pod_container_status_ready for current and time-windowed pod readiness statistics.

Enhancements:

  • Extend resource_optimization_local_monitoring_norecordingrules profile with additional aggregation functions for pod readiness (sum, avg, max, min) metrics.

…_norecordingrules.yaml

Signed-off-by: Bhaktavatsal Reddy <bhamaram@in.ibm.com>
@mbvreddy mbvreddy added this to the Kruize 0.12.0 Release milestone Jul 3, 2026
@mbvreddy mbvreddy added the bug Something isn't working label Jul 3, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a new podCount metric to the resource_optimization_local_monitoring_norecordingrules performance profile, using Prometheus queries based on ready containers to capture current, average, max, and min ready pod counts over a measurement window.

File-Level Changes

Change Details Files
Introduce podCount metric definitions based on READY containers in the resource optimization local monitoring profile.
  • Add podCount metric block using Prometheus as the datasource and container as the kubernetes_object
  • Define a sum query for current ready pods via kube_pod_container_status_ready filtered by namespace and container
  • Add avg_over_time aggregation over the summed ready pod count for the measurement duration window
  • Add max_over_time aggregation over the summed ready pod count for the measurement duration window
  • Add min_over_time aggregation over the summed ready pod count for the measurement duration window
manifests/autotune/performance-profiles/resource_optimization_local_monitoring_norecordingrules.yaml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="manifests/autotune/performance-profiles/resource_optimization_local_monitoring_norecordingrules.yaml" line_range="458" />
<code_context>
       - function: sum
         query: 'sum by(container, namespace, runtime, vendor, version)(jvm_info_total{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})'
+
+  # Pod Count (based on READY containers, not total pods)
+  - name: podCount
+    datasource: prometheus
</code_context>
<issue_to_address>
**issue:** Queries currently count ready containers, not pods, which conflicts with the "Pod Count" metric description.

`kube_pod_container_status_ready` is container-scoped, so this query returns ready containers, not ready pods. Either change the query to aggregate at the pod level (e.g., using `kube_pod_status_phase` / `kube_pod_status_ready` or grouping by pod) or update the metric name/description to clearly indicate it’s counting containers, not pods, to avoid misleading consumers.
</issue_to_address>

### Comment 2
<location path="manifests/autotune/performance-profiles/resource_optimization_local_monitoring_norecordingrules.yaml" line_range="465" />
<code_context>
+    kubernetes_object: "container"
+
+    aggregation_functions:
+      # Current ready pods
+      - function: sum
+        query: 'sum(kube_pod_container_status_ready{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})'
</code_context>
<issue_to_address>
**issue (bug_risk):** Missing filter on `condition="true"` for `kube_pod_container_status_ready` may overcount non-ready states.

`kube_pod_container_status_ready` exposes one series per `condition` value (e.g. `true`/`false`). Without `condition="true"`, the sum counts all conditions and won’t represent only ready containers. Please add `condition="true"` to the selector to match the intended "ready" semantics.
</issue_to_address>

### Comment 3
<location path="manifests/autotune/performance-profiles/resource_optimization_local_monitoring_norecordingrules.yaml" line_range="469" />
<code_context>
+      - function: sum
+        query: 'sum(kube_pod_container_status_ready{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})'
+
+      # Avg ready pods over time
+      - function: avg
+        query: 'avg_over_time(sum(kube_pod_container_status_ready{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})[$MEASUREMENT_DURATION_IN_MIN$m:])'
</code_context>
<issue_to_address>
**issue (bug_risk):** Use of subquery syntax inside `avg_over_time` with `[$MEASUREMENT_DURATION_IN_MIN$m:]` is likely invalid and/or semantically off.

This uses `avg_over_time(sum(metric){...}[$MEASUREMENT_DURATION_IN_MIN$m:])`, which creates a subquery (`[...] :`) and passes its result to a range function. `avg_over_time` expects a plain range vector, and the trailing colon without a step is invalid PromQL. To express "average ready containers over the last N minutes", use a simple range selector, e.g.:

- `avg_over_time(kube_pod_container_status_ready{...}[$MEASUREMENT_DURATION_IN_MIN$m])`, or
- `avg_over_time(sum(kube_pod_container_status_ready{...})[$MEASUREMENT_DURATION_IN_MIN$m])` if you want the average of the aggregated series.

`max_over_time` and `min_over_time` below should be updated similarly (remove the colon and use a plain `[...]` range).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

- function: sum
query: 'sum by(container, namespace, runtime, vendor, version)(jvm_info_total{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})'

# Pod Count (based on READY containers, not total pods)

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.

issue: Queries currently count ready containers, not pods, which conflicts with the "Pod Count" metric description.

kube_pod_container_status_ready is container-scoped, so this query returns ready containers, not ready pods. Either change the query to aggregate at the pod level (e.g., using kube_pod_status_phase / kube_pod_status_ready or grouping by pod) or update the metric name/description to clearly indicate it’s counting containers, not pods, to avoid misleading consumers.

kubernetes_object: "container"

aggregation_functions:
# Current ready pods

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.

issue (bug_risk): Missing filter on condition="true" for kube_pod_container_status_ready may overcount non-ready states.

kube_pod_container_status_ready exposes one series per condition value (e.g. true/false). Without condition="true", the sum counts all conditions and won’t represent only ready containers. Please add condition="true" to the selector to match the intended "ready" semantics.

- function: sum
query: 'sum(kube_pod_container_status_ready{namespace="$NAMESPACE$", container="$CONTAINER_NAME$"})'

# Avg ready pods over time

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.

issue (bug_risk): Use of subquery syntax inside avg_over_time with [$MEASUREMENT_DURATION_IN_MIN$m:] is likely invalid and/or semantically off.

This uses avg_over_time(sum(metric){...}[$MEASUREMENT_DURATION_IN_MIN$m:]), which creates a subquery ([...] :) and passes its result to a range function. avg_over_time expects a plain range vector, and the trailing colon without a step is invalid PromQL. To express "average ready containers over the last N minutes", use a simple range selector, e.g.:

  • avg_over_time(kube_pod_container_status_ready{...}[$MEASUREMENT_DURATION_IN_MIN$m]), or
  • avg_over_time(sum(kube_pod_container_status_ready{...})[$MEASUREMENT_DURATION_IN_MIN$m]) if you want the average of the aggregated series.

max_over_time and min_over_time below should be updated similarly (remove the colon and use a plain [...] range).

@mbvreddy
mbvreddy requested review from dinogun and khansaad July 6, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kruize-operator

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant