-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEV-369 #46
Conversation
WalkthroughThe changes in this pull request primarily involve modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
src/sc_keeper/parameters.py (2)
67-75
: LGTM! Consider adding a default value for consistency.The changes to
vcpus_max
look good. Changing the type fromOptional[int]
toint
ensures that a valid integer value is always provided for the maximum number of virtual CPUs. This aligns with the PR objectives of refining the server filtering capabilities.For consistency with other parameters and to improve usability, consider adding a default value to
vcpus_max
. This could be the maximum allowed value (256) or another sensible default. For example:vcpus_max = Annotated[ int, Query( title="Maximum vCPUs", description="Maximum number of virtual CPUs.", ge=1, le=256, default=256, # Add this line json_schema_extra={ "category_id": FilterCategories.PROCESSOR, "unit": "vCPUs" }, ), ]This change would make the parameter optional in API calls while still ensuring it always has a valid integer value.
Line range hint
1-400
: Summary of changes and suggestions for next steps
The change to
vcpus_max
parameter improves type safety by ensuring it's always a valid integer. This change is approved with a minor suggestion to add a default value for consistency.There's a discrepancy between the PR objectives and the actual changes. The PR description mentions adding new filters, but these filters already exist in the file and haven't been modified in this change.
To address this discrepancy and align the PR with its objectives, consider the following steps:
- Review the PR objectives and update them to accurately reflect the changes made, focusing on the
vcpus_max
parameter modification.- If new filters are still required, implement them in this file following the existing pattern for consistency.
- If the existing filters need modifications (e.g., updating enum values, changing descriptions), make those changes explicitly.
- Update the PR description to clearly state which existing filters were modified, if any.
- If the intention was to expose these existing filters in a new way (e.g., in a different part of the API or UI), ensure those changes are included in the PR and mentioned in the description.
By taking these steps, you'll ensure that the PR accurately represents the changes made and meets the intended objectives.
src/sc_keeper/api.py (2)
Line range hint
232-286
: Implement missing filters mentioned in PR objectives.The PR objectives mention adding new filters for GPU manufacturer, GPU family, GPU model, CPU manufacturer, and CPU family. However, these filters are not implemented in the current changes. Consider adding these filters to fully meet the PR objectives.
To implement the missing filters, you can add new parameters to the
search_servers
function and corresponding conditions to theconditions
set. Here's an example of how you might implement these filters:def search_servers( response: Response, partial_name_or_id: options.partial_name_or_id = None, vcpus_min: options.vcpus_min = 1, vcpus_max: options.vcpus_max = 256, architecture: options.architecture = None, + cpu_manufacturer: options.cpu_manufacturer = None, + cpu_family: options.cpu_family = None, benchmark_score_stressng_cpu_min: options.benchmark_score_stressng_cpu_min = None, memory_min: options.memory_min = None, only_active: options.only_active = True, vendor: options.vendor = None, compliance_framework: options.compliance_framework = None, storage_size: options.storage_size = None, storage_type: options.storage_type = None, gpu_min: options.gpu_min = None, gpu_memory_min: options.gpu_memory_min = None, gpu_memory_total: options.gpu_memory_total = None, + gpu_manufacturer: options.gpu_manufacturer = None, + gpu_family: options.gpu_family = None, + gpu_model: options.gpu_model = None, limit: options.limit = 25, page: options.page = None, order_by: options.order_by = "vcpus", order_dir: options.order_dir = OrderDir.ASC, add_total_count_header: options.add_total_count_header = False, db: Session = Depends(get_db), ) -> List[ServerPKs]: # ... (existing code) if vcpus_max and vcpus_max < 256: conditions.add(Server.vcpus <= vcpus_max) if architecture: conditions.add(Server.cpu_architecture.in_(architecture)) + if cpu_manufacturer: + conditions.add(Server.cpu_manufacturer.in_(cpu_manufacturer)) + if cpu_family: + conditions.add(Server.cpu_family.in_(cpu_family)) if benchmark_score_stressng_cpu_min: conditions.add(max_scores.c.score > benchmark_score_stressng_cpu_min) # ... (existing code) if gpu_memory_total: conditions.add(Server.gpu_memory_total >= gpu_memory_total * 1024) + if gpu_manufacturer: + conditions.add(Server.gpu_manufacturer.in_(gpu_manufacturer)) + if gpu_family: + conditions.add(Server.gpu_family.in_(gpu_family)) + if gpu_model: + conditions.add(Server.gpu_model.in_(gpu_model)) if only_active: conditions.add(Server.status == Status.ACTIVE) # ... (rest of the function)Make sure to update the
options.py
file to include the new option types for these filters.
Line range hint
232-286
: Consider refactoring for improved maintainability.The
search_servers
function is quite long and complex, which may make it harder to maintain and test. Consider refactoring it to improve readability and maintainability.Here are some suggestions for refactoring:
- Extract the filter condition logic into a separate function:
def add_filter_conditions(conditions, server, max_scores, **filters): if filters.get('vcpus_max') and filters['vcpus_max'] < 256: conditions.add(server.vcpus <= filters['vcpus_max']) if filters.get('architecture'): conditions.add(server.cpu_architecture.in_(filters['architecture'])) # ... (add other conditions) # In the search_servers function: add_filter_conditions(conditions, Server, max_scores, **locals())
- Use a dictionary to map filter names to their corresponding condition functions:
filter_conditions = { 'vcpus_max': lambda s, v: s.vcpus <= v if v < 256 else None, 'architecture': lambda s, v: s.cpu_architecture.in_(v), # ... (add other filters) } def add_filter_conditions(conditions, server, **filters): for filter_name, filter_value in filters.items(): if filter_value and filter_name in filter_conditions: condition = filter_conditions[filter_name](server, filter_value) if condition: conditions.add(condition) # In the search_servers function: add_filter_conditions(conditions, Server, **locals())These refactoring suggestions can help make the code more modular and easier to maintain, especially when adding new filters or modifying existing ones.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- src/sc_keeper/api.py (2 hunks)
- src/sc_keeper/parameters.py (1 hunks)
🔇 Additional comments not posted (3)
src/sc_keeper/api.py (3)
232-232
: LGTM: Default value forvcpus_max
parameter.The change to set a default value of 256 for
vcpus_max
is a good improvement. It provides a sensible upper limit for the number of virtual CPUs, which can help optimize query performance by avoiding unnecessary filtering for very large values.
285-286
: LGTM: Improved condition forvcpus_max
filtering.The updated condition
if vcpus_max and vcpus_max < 256:
is a good optimization. It ensures that the filter is only applied when necessary, avoiding redundant filtering when the max value is set to the default of 256 or higher.
Line range hint
232-286
: Summary of review findings
- The changes to the
vcpus_max
parameter and its usage are good improvements that optimize query performance.- The PR objectives for adding new GPU and CPU filters have not been fully implemented. These filters should be added to meet the stated goals of the pull request.
- The
search_servers
function could benefit from refactoring to improve maintainability and readability.Recommendation: Address the missing filter implementations and consider refactoring the function before merging this pull request. The current changes are good but incomplete based on the PR objectives.
To ensure that all necessary changes have been made, please run the following script:
… added optional 'null_value' to set an extreme value that should be sent as 'null/None' to the API
Summary by CodeRabbit
New Features
Bug Fixes
vcpus_max
parameter to ensure it is always a valid integer.