Skip to content

Conversation

lilyLuLiu
Copy link
Contributor

@lilyLuLiu lilyLuLiu commented Jul 14, 2025

Description

Add cpu consume track to e2e test case

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Proposed changes

Testing

Contribution Checklist

  • I Keep It Small and Simple: The smaller the PR is, the easier it is to review and have it merged
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Which platform have you tested the code changes on?
    • Linux
    • Windows
    • MacOS

Summary by CodeRabbit

  • New Features

    • Added memory-usage collection alongside CPU measurements in the Openshift health scenario; results are saved for later analysis and collection errors are logged without stopping tests.
  • Bug Fixes

    • Test-result writes now append to result files instead of overwriting, preserving previous data.

Copy link

coderabbitai bot commented Jul 14, 2025

Walkthrough

Added memory usage collection alongside existing CPU collection in the OpenShift end-to-end scenario; new unexported functions collect CPU and memory metrics and write them to result files. The file write utility was changed to append mode so metric outputs accumulate.

Changes

Cohort / File(s) Change Summary
Feature test update
test/e2e/features/story_openshift.feature
Added "get memory data" steps at the same three checkpoints where CPU data is collected.
Test suite enhancements
test/e2e/testsuite/testsuite.go
Imported cpu and mem packages; added step defs for CPU and memory; added unexported getCPUdata and getMemoryData functions; calls inserted into @story_health initialization (errors logged, non-fatal).
File operation utility
test/extended/util/fileops.go
Changed WriteToFile to open files with os.O_CREATE

Sequence Diagram(s)

sequenceDiagram
    participant Runner as E2E Runner
    participant Suite as testsuite.go
    participant Lib as gopsutil (cpu/mem)
    participant File as WriteToFile

    Runner->>Suite: execute @story_health scenario steps
    Suite->>Lib: get CPU data (getCPUdata)
    Lib-->>Suite: CPU metrics
    Suite->>File: append CPU metrics to ../test-results/cpu-consume.txt
    Suite->>Lib: get Memory data (getMemoryData)
    Lib-->>Suite: Memory metrics
    Suite->>File: append Memory metrics to ../test-results/memory-consume.txt
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested reviewers

  • albfan
  • adrianriobo

Poem

In my burrow I count every cycle and heap,
CPU whispers numbers while memory drifts to sleep.
I hop through the tests, append notes with a grin,
Logs grow like carrots — one line at a time within.
🐇📊


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb7ce6 and cc32788.

📒 Files selected for processing (2)
  • test/e2e/features/story_openshift.feature (2 hunks)
  • test/e2e/testsuite/testsuite.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/e2e/features/story_openshift.feature
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/e2e/testsuite/testsuite.go (1)
test/extended/util/fileops.go (1)
  • WriteToFile (93-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build-qe (linux, amd64)
  • GitHub Check: build-qe (windows, amd64)
  • GitHub Check: build-qe (darwin, amd64)
  • GitHub Check: build-qe (linux, arm64)
  • GitHub Check: build-qe (darwin, arm64)
  • GitHub Check: build-installer (windows-2022, 1.23)
  • GitHub Check: verify-devcontainer
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: Run OKD bundle with crc (1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build (ubuntu-22.04, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: Konflux kflux-prd-rh02 / crc-binary-on-pull-request
🔇 Additional comments (1)
test/e2e/testsuite/testsuite.go (1)

31-32: LGTM: gopsutil v4 imports are correct and scoped to tests

Imports for CPU and memory metrics look good and match the APIs being used.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot requested review from adrianriobo and albfan July 14, 2025 07:23
Copy link

openshift-ci bot commented Jul 14, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

Copy link

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 425c446 and 217db59.

📒 Files selected for processing (3)
  • test/e2e/features/story_openshift.feature (2 hunks)
  • test/e2e/testsuite/testsuite.go (4 hunks)
  • test/extended/util/fileops.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/e2e/testsuite/testsuite.go (1)
test/extended/util/fileops.go (1)
  • WriteToFile (93-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: build (ubuntu-22.04, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: Run OKD bundle with crc (1.23)
  • GitHub Check: build-qe (linux, arm64)
  • GitHub Check: build-qe (linux, amd64)
  • GitHub Check: build-qe (darwin, amd64)
  • GitHub Check: build-qe (darwin, arm64)
  • GitHub Check: build-qe (windows, amd64)
  • GitHub Check: build-installer (windows-2022, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: verify-devcontainer
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
🔇 Additional comments (5)
test/e2e/features/story_openshift.feature (1)

15-15: Well-placed CPU data collection points.

The CPU data collection steps are strategically positioned to capture metrics at key phases of the test scenario: after project creation, after deployment, and after cluster stop. This provides comprehensive coverage for performance monitoring.

Also applies to: 27-27, 32-32

test/extended/util/fileops.go (1)

94-94: Appropriate modification to support append mode.

The change from os.O_RDWR to os.O_CREATE|os.O_APPEND|os.O_WRONLY is well-suited for the CPU data collection use case, allowing data to be accumulated in the results file without overwriting existing content.

test/e2e/testsuite/testsuite.go (3)

32-32: Import addition looks good.

The import of the gopsutil CPU package is appropriate for the CPU monitoring functionality.


266-268: Good integration with scenario tags.

The conditional check for @story_health tag to trigger CPU data collection before scenario start is well-integrated with the existing tag-based setup logic.


576-577: Step definition registration is correct.

The step definition follows the proper godog pattern and matches the feature file usage.

@lilyLuLiu lilyLuLiu self-assigned this Jul 22, 2025
@lilyLuLiu lilyLuLiu moved this to Work In Progress in Project planning: crc Jul 22, 2025
@lilyLuLiu lilyLuLiu marked this pull request as draft July 23, 2025 09:11
@lilyLuLiu lilyLuLiu changed the title [QE] add cpu consume track to e2e test [QE] add cpu and memory consume track to e2e test Jul 30, 2025
@lilyLuLiu lilyLuLiu marked this pull request as ready for review July 30, 2025 08:09
Copy link

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
test/e2e/testsuite/testsuite.go (3)

267-274: Rename to getCPUData for consistency; keep logging non-fatal

Align with Go naming conventions and prior review. Update the call site to the corrected function name. Optionally switch to util.LogMessage for consistent test logging.

-            if err := getCPUdata("Before start"); err != nil {
+            if err := getCPUData("Before start"); err != nil {
                 fmt.Printf("Failed to collect CPU data: %v\n", err)
             }

582-586: Bind step to getCPUData (naming consistency with Go conventions)

Keep step text the same; just bind to the properly cased function name.

-s.Step(`^get cpu data "([^"]*)"`,
-    getCPUdata)
+s.Step(`^get cpu data "([^"]*)"`,
+    getCPUData)
 s.Step(`^get memory data "([^"]*)"`,
     getMemoryData)

1323-1335: Fix CPU data formatting and handle fs path errors (writes may be broken as-is)

  • data formatting uses a []float64 with "%.2f", producing invalid output like %!f([]float64=...). Use cpuData[0].
  • stop ignoring os.Getwd error; surface failure.
  • ensure the output directory exists to avoid write failures.
-func getCPUdata(content string) error {
-    cpuData, err := cpu.Percent(0, false)
+func getCPUData(content string) error {
+    cpuData, err := cpu.Percent(0, false)
     if err != nil {
         return fmt.Errorf("failed to get CPU data: %v", err)
     }
     if len(cpuData) == 0 {
         return fmt.Errorf("no CPU data available")
     }
-    data := fmt.Sprintf("%s: %.2f%%\n", content, cpuData)
-    wd, _ := os.Getwd()
-    file := filepath.Join(wd, "../test-results/cpu-consume.txt")
-    return util.WriteToFile(data, file)
+    data := fmt.Sprintf("%s: %.2f%%\n", content, cpuData[0])
+    wd, err := os.Getwd()
+    if err != nil {
+        return fmt.Errorf("failed to get working directory: %v", err)
+    }
+    file := filepath.Join(wd, "../test-results/cpu-consume.txt")
+    if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
+        return fmt.Errorf("failed to create results directory: %v", err)
+    }
+    return util.WriteToFile(data, file)
 }

Optional: for more stable readings, consider a small sampling window, for example cpu.Percent(500*time.Millisecond, false).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f413e6 and 2cb7ce6.

📒 Files selected for processing (3)
  • test/e2e/features/story_openshift.feature (2 hunks)
  • test/e2e/testsuite/testsuite.go (4 hunks)
  • test/extended/util/fileops.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/extended/util/fileops.go
  • test/e2e/features/story_openshift.feature
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/e2e/testsuite/testsuite.go (1)
test/extended/util/fileops.go (1)
  • WriteToFile (93-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: build-qe (linux, arm64)
  • GitHub Check: build-qe (darwin, arm64)
  • GitHub Check: build-qe (linux, amd64)
  • GitHub Check: build-qe (darwin, amd64)
  • GitHub Check: build-qe (windows, amd64)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build-installer (windows-2022, 1.23)
  • GitHub Check: build (macOS-14, 1.23)
  • GitHub Check: build (macOS-13, 1.23)
  • GitHub Check: build (ubuntu-22.04, 1.23)
  • GitHub Check: build (ubuntu-latest, 1.23)
  • GitHub Check: verify-devcontainer
  • GitHub Check: Run OKD bundle with crc (1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: build (windows-2022, 1.23)
  • GitHub Check: Konflux kflux-prd-rh02 / crc-binary-on-pull-request
🔇 Additional comments (1)
test/e2e/testsuite/testsuite.go (1)

31-32: LGTM: imports for host metrics are appropriate and in use

cpu and mem from gopsutil v4 are correctly imported and used below.

Comment on lines 1337 to 1353
func getMemoryData(content string) error {
v, _ := mem.VirtualMemory()
data := fmt.Sprintf("%s, UsedPercent: %f%%, Free: %v Mib\n", content, v.UsedPercent, v.Free/1024/1024)
wd, _ := os.Getwd()
file := filepath.Join(wd, "../test-results/memory-consume.txt")
return util.WriteToFile(data, file)
}
Copy link

@coderabbitai coderabbitai bot Aug 11, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle mem.VirtualMemory and os.Getwd errors; improve units/formatting

  • Don’t ignore mem.VirtualMemory error; check for nil.
  • Don’t ignore os.Getwd error.
  • Use two decimals for UsedPercent; print Free in MiB with %d and correct “MiB” spelling.
  • Ensure output directory exists.
-func getMemoryData(content string) error {
-    v, _ := mem.VirtualMemory()
-    data := fmt.Sprintf("%s, UsedPercent: %f%%, Free: %v Mib\n", content, v.UsedPercent, v.Free/1024/1024)
-    wd, _ := os.Getwd()
-    file := filepath.Join(wd, "../test-results/memory-consume.txt")
-    return util.WriteToFile(data, file)
-}
+func getMemoryData(content string) error {
+    v, err := mem.VirtualMemory()
+    if err != nil {
+        return fmt.Errorf("failed to get memory data: %v", err)
+    }
+    if v == nil {
+        return fmt.Errorf("no memory data available")
+    }
+    data := fmt.Sprintf("%s, UsedPercent: %.2f%%, Free: %d MiB\n", content, v.UsedPercent, v.Free/1024/1024)
+    wd, err := os.Getwd()
+    if err != nil {
+        return fmt.Errorf("failed to get working directory: %v", err)
+    }
+    file := filepath.Join(wd, "../test-results/memory-consume.txt")
+    if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
+        return fmt.Errorf("failed to create results directory: %v", err)
+    }
+    return util.WriteToFile(data, file)
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func getMemoryData(content string) error {
v, _ := mem.VirtualMemory()
data := fmt.Sprintf("%s, UsedPercent: %f%%, Free: %v Mib\n", content, v.UsedPercent, v.Free/1024/1024)
wd, _ := os.Getwd()
file := filepath.Join(wd, "../test-results/memory-consume.txt")
return util.WriteToFile(data, file)
}
func getMemoryData(content string) error {
v, err := mem.VirtualMemory()
if err != nil {
return fmt.Errorf("failed to get memory data: %v", err)
}
if v == nil {
return fmt.Errorf("no memory data available")
}
data := fmt.Sprintf("%s, UsedPercent: %.2f%%, Free: %d MiB\n", content, v.UsedPercent, v.Free/1024/1024)
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get working directory: %v", err)
}
file := filepath.Join(wd, "../test-results/memory-consume.txt")
if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
return fmt.Errorf("failed to create results directory: %v", err)
}
return util.WriteToFile(data, file)
}
🤖 Prompt for AI Agents
In test/e2e/testsuite/testsuite.go around lines 1337 to 1343, getMemoryData
currently ignores errors from mem.VirtualMemory and os.Getwd, prints UsedPercent
with default precision and Free with incorrect units/spelling, and may write to
a non-existent directory; update the function to check and handle the error
returned by mem.VirtualMemory (returning it on failure), check and handle
os.Getwd error, format UsedPercent with two decimals (e.g., %.2f), convert Free
to MiB as an integer and print with %d and "MiB", ensure the target directory
(../test-results) exists before writing (create it with appropriate permissions
if missing), and propagate any file-write errors returned by util.WriteToFile.

Copy link
Member

Choose a reason for hiding this comment

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

@lilyLuLiu ^^ looks like this is correct and we shouldn't ignore the errors, instead return those if any?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@praveenkumar, I have added error handling for getMemory and getwd. For mkdir, I think it's not needed, as the folder test-result has already been created.

Copy link

openshift-ci bot commented Aug 12, 2025

@lilyLuLiu: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/security cc32788 link false /test security
ci/prow/e2e-crc cc32788 link true /test e2e-crc

Full PR test history. Your PR dashboard.

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.

@lilyLuLiu lilyLuLiu moved this from Work In Progress to Ready for review in Project planning: crc Aug 20, 2025
@praveenkumar praveenkumar merged commit ecbf4d6 into crc-org:main Aug 25, 2025
31 of 38 checks passed
@github-project-automation github-project-automation bot moved this from Ready for review to Done in Project planning: crc Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants