Skip to content

NO-ISSUE: improve error reporting in cpumetriccollector#31132

Open
simonpasquier wants to merge 1 commit intoopenshift:mainfrom
simonpasquier:improve-error-reporting
Open

NO-ISSUE: improve error reporting in cpumetriccollector#31132
simonpasquier wants to merge 1 commit intoopenshift:mainfrom
simonpasquier:improve-error-reporting

Conversation

@simonpasquier
Copy link
Copy Markdown
Contributor

@simonpasquier simonpasquier commented May 6, 2026

While investigating https://redhat.atlassian.net/browse/OCPBUGS-84492, it was hard to understand which PromQL query was failing.

Summary by CodeRabbit

  • Chores
    • Refined error handling in monitoring operations to provide clearer diagnostic messages for troubleshooting.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 6, 2026
@openshift-ci-robot
Copy link
Copy Markdown

@simonpasquier: This pull request explicitly references no jira issue.

Details

In response to this:

While investigating https://redhat.atlassian.net/browse/OCPBUGS-84492, it was hard to understand which PromQL query was failing.

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: simonpasquier
Once this PR has been reviewed and has the lgtm label, please assign xueqzhan for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot requested review from deads2k and p0lyn0mial May 6, 2026 09:15
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Walkthrough

Error handling in CPU metric collection is enhanced by wrapping errors with contextual messages using fmt.Errorf and %w at three sites: Prometheus client creation, Thanos querier connectivity check, and CPU usage query execution.

Changes

Error Handling Improvements

Layer / File(s) Summary
Error Message Enhancement
pkg/monitortests/testframework/cpumetriccollector/monitortest.go
Three error returns are wrapped with contextual messages: Prometheus client creation (line 99), Thanos querier connectivity check (line 104), and CPU usage query (line 126). Each uses fmt.Errorf with %w to preserve the original error chain.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 12
✅ Passed checks (12 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: improving error reporting in cpumetriccollector by wrapping errors with context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The PR contains only standard Go unit tests (testing.T), not Ginkgo tests. The custom check is specific to Ginkgo test names. All test names are static and descriptive with no dynamic content.
Test Structure And Quality ✅ Passed Check targets Ginkgo test code. PR modifies monitor test implementation and standard Go unit tests (testify), not Ginkgo. Not applicable.
Microshift Test Compatibility ✅ Passed PR adds a MonitorTest framework component, not Ginkgo e2e tests. The custom check applies only to new Ginkgo e2e tests (It(), Describe(), etc.). No such tests are present in this PR.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR does not add Ginkgo e2e tests. It only refines error handling in monitoring framework code with fmt.Errorf and %w wrapping. The SNO test compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed Test utility modification with error handling improvements only. No deployment manifests, operators, controllers, or scheduling constraints. Not subject to topology-aware scheduling check.
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes found. Changes use fmt.Errorf/Sprintf for error wrapping only, which don't write to stdout.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The custom check is not applicable. No new Ginkgo e2e tests (It(), Describe(), etc.) are added. The PR only adds monitor test framework infrastructure code and standard Go unit tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/monitortests/testframework/cpumetriccollector/monitortest.go (1)

124-127: ⚡ Quick win

Include the actual PromQL expression in the query failure error.

At Line 126, the message still doesn’t identify the exact query text, which is the core pain point from the PR description. Including cpuQuery makes logs immediately actionable.

Proposed patch
-	if err != nil {
-		return nil, fmt.Errorf("failed to query CPU usage per instance: %w", err)
-	}
+	if err != nil {
+		return nil, fmt.Errorf("failed to query CPU usage per instance (query=%q): %w", cpuQuery, err)
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/monitortests/testframework/cpumetriccollector/monitortest.go` around
lines 124 - 127, The error returned from prometheusClient.QueryRange in
monitortest.go does not include the actual PromQL string; update the error
handling in the block where cpuMetrics, warningsForQuery, err :=
prometheusClient.QueryRange(ctx, cpuQuery, timeRange) is checked so that the
fmt.Errorf includes the cpuQuery value (the PromQL expression) alongside the
wrapped err and context (e.g., "failed to query CPU usage per instance
(query=%q): %w"), ensuring logs show the exact query.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/monitortests/testframework/cpumetriccollector/monitortest.go`:
- Around line 124-127: The error returned from prometheusClient.QueryRange in
monitortest.go does not include the actual PromQL string; update the error
handling in the block where cpuMetrics, warningsForQuery, err :=
prometheusClient.QueryRange(ctx, cpuQuery, timeRange) is checked so that the
fmt.Errorf includes the cpuQuery value (the PromQL expression) alongside the
wrapped err and context (e.g., "failed to query CPU usage per instance
(query=%q): %w"), ensuring logs show the exact query.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 47b74056-1182-4d90-b508-189515f11a24

📥 Commits

Reviewing files that changed from the base of the PR and between 0de3cea and d62f037.

📒 Files selected for processing (1)
  • pkg/monitortests/testframework/cpumetriccollector/monitortest.go

@openshift-merge-bot openshift-merge-bot Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label May 6, 2026
@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@simonpasquier
Copy link
Copy Markdown
Contributor Author

/cc @rexagod

@openshift-ci openshift-ci Bot requested a review from rexagod May 6, 2026 10:00
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

@simonpasquier: all tests passed!

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@openshift-trt
Copy link
Copy Markdown

openshift-trt Bot commented May 6, 2026

Risk analysis has seen new tests most likely introduced by this PR.
Please ensure that new tests meet guidelines for naming and stability.

New Test Risks for sha: d62f037

Job Name New Test Risk
pull-ci-openshift-origin-main-e2e-metal-ipi-ovn-ipv6 High - "[Jira:Node Tuning Operator][sig-tuning-node] should [test_id:37415][OTP]Allow setting isolated_cores without touching the default_irq_affinity [Disruptive]" is a new test, was only seen in one job, and failed 1 time(s) against the current commit.
pull-ci-openshift-origin-main-e2e-metal-ipi-ovn-ipv6 Medium - "[Jira:Node Tuning Operator][sig-tuning-node] should support passing tests" is a new test, and was only seen in one job.
pull-ci-openshift-origin-main-e2e-metal-ipi-ovn-ipv6 Medium - "[Jira:Node Tuning Operator][sig-tuning-node] should support passing tests [Disruptive]" is a new test, and was only seen in one job.

New tests seen in this PR at sha: d62f037

  • "[Jira:Node Tuning Operator][sig-tuning-node] should [test_id:37415][OTP]Allow setting isolated_cores without touching the default_irq_affinity [Disruptive]" [Total: 1, Pass: 0, Fail: 1, Flake: 0]
  • "[Jira:Node Tuning Operator][sig-tuning-node] should support passing tests" [Total: 1, Pass: 1, Fail: 0, Flake: 0]
  • "[Jira:Node Tuning Operator][sig-tuning-node] should support passing tests [Disruptive]" [Total: 1, Pass: 1, Fail: 0, Flake: 0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants