-
Notifications
You must be signed in to change notification settings - Fork 633
Fix serve status ordering by READY and versionfix replica ordering #5188
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
base: master
Are you sure you want to change the base?
Fix serve status ordering by READY and versionfix replica ordering #5188
Conversation
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.
Thanks for adding this @mert-cemri ! It mostly looks good to me. However, there seems to contain some unnecessary refactoring. Could we keep as much original code as possible to keep the chance of breaking anything as low as possible?
service_names_to_query: Optional[List[str]] = list( | ||
service_names) if service_names else None |
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.
Why do we need to convert it to list here?
service_names_to_query: Optional[List[str]] = list( | ||
service_names) if service_names else None | ||
|
||
# Show a status message while fetching data |
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.
Those comments looks a little bit tedious. Could we remove them?
def _sort_replica_records( | ||
replica_records: List[Dict[str, Any]]) -> List[Dict[str, Any]]: | ||
"""Sort replica records based on version, status and replica_id.""" | ||
|
||
# Define the sorting key function internally | ||
def _sort_key(replica_record: Dict[str, Any]) -> Tuple[int, int, int]: | ||
# Sort by version descending (latest first) | ||
version = int(replica_record.get('version', 0)) | ||
# Sort by status, prioritizing READY | ||
if replica_record['status'] == serve_state.ReplicaStatus.READY: | ||
status_priority = 0 | ||
elif replica_record['status'] == serve_state.ReplicaStatus.PROVISIONING: | ||
status_priority = 1 | ||
else: | ||
status_priority = 2 | ||
# Sort by replica_id ascending as a tie-breaker | ||
replica_id = int(replica_record.get('id', 0)) | ||
return -version, status_priority, replica_id | ||
|
||
# Sort the records using the defined key | ||
sorted_records = sorted(replica_records, key=_sort_key) | ||
return sorted_records |
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.
This seems will mix replica records for different service together. Should we sort first based on its service name?
if not service_records: | ||
return 'No existing services.' | ||
return 'No services found.' |
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.
why change this?
# Add service name and replica id to replica info dict. | ||
for info in record['replica_info']: | ||
info['service_name'] = record['name'] | ||
info['replica_id'] = info['id'] |
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.
why do we need this?
Fixes #3052
Tested (run the relevant ones):
bash format.sh
/smoke-test
(CI) orpytest tests/test_smoke.py
(local)/smoke-test -k test_name
(CI) orpytest tests/test_smoke.py::test_name
(local)/quicktest-core
(CI) orpytest tests/smoke_tests/test_backward_compat.py
(local)