Skip to content

Conversation

@yoursanonymous
Copy link

@yoursanonymous yoursanonymous commented Feb 4, 2026

What type of PR is this?

This PR optimizes the algorithm configuration parsing in TestCaseController by consolidating redundant loops and introducing specific error types. This ensures that users receive clear, actionable feedback when their benchmarking configurations are incorrect.

/kind feature

What this PR does / why we need it:
The current implementation of algorithm parsing is difficult to debug and maintain:

  • Opaque Failures: Catching generic exceptions makes it hard for users to know if a failure was due to a missing file, a YAML syntax error, or an internal algorithm initialization issue.
  • Redundant Logic: The multiple loops and manual deepcopy operations contribute to higher resource usage and lower readability.
  • Implicit Dependencies: Lack of pre-parsing checks for mandatory keys like url can lead to confusing attribute errors later in the execution.

Which issue(s) this PR fixes:

Fixes #319

… handling

Signed-off-by: vinayak sharma <vinayaks0111@gmail.com>
@kubeedge-bot kubeedge-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 4, 2026
@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yoursanonymous
To complete the pull request process, please assign jaypume after the PR has been reviewed.
You can assign the PR to them by writing /assign @jaypume in a comment when ready.

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

@gemini-code-assist
Copy link

Summary of Changes

Hello @yoursanonymous, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the algorithm configuration parsing within the TestCaseController to enhance robustness and user experience. It streamlines the logic by consolidating algorithm expansion into a single pass, eliminating redundant loops and deepcopy operations. Crucially, it introduces more specific and informative error types, providing clearer feedback to users regarding issues like missing configuration files, parsing errors, or invalid algorithm initialization.

Highlights

  • Improved Error Handling: Enhanced error handling within the _parse_algorithms_config method to provide more specific and actionable feedback for issues such as missing 'url' fields, non-existent configuration files, and YAML parsing errors.
  • Refactored Algorithm Parsing Logic: The algorithm configuration parsing and expansion logic has been streamlined into a single loop, eliminating redundant iterations and deepcopy operations, leading to cleaner and more efficient code.
  • Specific Exception Types: Replaced generic RuntimeError with more precise exception types like ValueError and FileNotFoundError to better categorize and communicate the nature of configuration issues.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • core/testcasecontroller/testcasecontroller.py
    • Refactored _parse_algorithms_config to combine algorithm parsing and expansion into a single loop, removing an intermediate list and a second iteration.
    • Added an explicit check for a missing 'url' key in algorithm configurations, raising a ValueError if not found.
    • Changed the exception type from RuntimeError to FileNotFoundError when an algorithm configuration file is not found locally.
    • Implemented a try-except block around utils.yaml2dict to catch parsing errors and raise a ValueError with the underlying error message.
    • Improved the error message for Algorithm initialization failures, making it more descriptive.
    • Introduced logic to directly append algorithms without a modules_list (i.e., no permutations) to avoid unnecessary deep copies and simplify the flow.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubeedge-bot kubeedge-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 4, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly refactors the _parse_algorithms_config method in TestCaseController, leading to improved error handling, better readability, and reduced redundancy. The changes introduce more specific exception types for clearer diagnostics, separate error handling for YAML parsing and algorithm initialization, and consolidate the algorithm expansion logic into a single, more efficient loop. These improvements enhance the maintainability and user experience by providing more actionable feedback for configuration issues.

Comment on lines +76 to +81
try:
raw_config = utils.yaml2dict(config_file)
except Exception as err:
raise ValueError(
f"Failed to parse algorithm config file({config_file}): {err}"
) from err

Choose a reason for hiding this comment

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

high

Separating the YAML parsing into its own try-except block with a ValueError provides much clearer diagnostics. Users will immediately know if their YAML file is malformed, rather than guessing if it's a file issue or an algorithm initialization problem. This significantly improves the debugging experience.

Comment on lines 83 to +88
try:
config = utils.yaml2dict(config_file)
algorithm = Algorithm(name, config)
algorithms.append(algorithm)
algorithm = Algorithm(name, raw_config)
except Exception as err:
raise RuntimeError(f"algorithm config file({config_file} is not supported, "
f"error: {err}") from err
raise RuntimeError(
f"Failed to initialize Algorithm '{name}' from {config_file}: {err}"
) from err

Choose a reason for hiding this comment

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

high

This dedicated try-except block for Algorithm initialization, distinct from YAML parsing, further improves error clarity. It helps pinpoint whether the issue is with the configuration content itself or how the Algorithm class processes that content, making it easier to identify the root cause of failures.

Comment on lines +70 to +71
if not config_file:
raise ValueError(f"Algorithm 'url' is missing for algorithm: {name}")

Choose a reason for hiding this comment

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

medium

This explicit check for a missing 'url' is a great improvement. It provides immediate and clear feedback to the user, preventing later, more obscure errors that might arise from attempting to use a None value as a file path.

Comment on lines 73 to +74
if not utils.is_local_file(config_file):
raise RuntimeError(f"not found algorithm config file({config_file}) in local")
raise FileNotFoundError(f"Algorithm config file not found: {config_file}")

Choose a reason for hiding this comment

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

medium

Using FileNotFoundError instead of a generic RuntimeError is more semantically correct and allows for more specific error handling by callers. This makes the error message more precise and helpful.

Comment on lines +90 to +98
# If no modules_list (e.g. no permutations), add the base algorithm
if not algorithm.modules_list:
all_expanded_algorithms.append(algorithm)
continue

new_algorithms = []
for algorithm in algorithms:
for modules in algorithm.modules_list:
new_algorithm = copy.deepcopy(algorithm)
new_algorithm.modules = modules
new_algorithms.append(new_algorithm)
all_expanded_algorithms.append(new_algorithm)

Choose a reason for hiding this comment

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

medium

Consolidating the algorithm expansion logic into a single loop, and directly appending the base algorithm when modules_list is empty, streamlines the code. This reduces redundancy and improves readability compared to the previous two-loop approach, making the logic easier to follow and maintain.

Signed-off-by: vinayak sharma <vinayaks0111@gmail.com>
@yoursanonymous
Copy link
Author

@hsj576 @Poorunga
Can you please review this pull request

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

Labels

kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Algorithm Parsing in TestCaseController for Better Error Handling and Maintainability

2 participants