-
Notifications
You must be signed in to change notification settings - Fork 2
feat: expose service statuses in cli #134
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| -r requirements.txt | ||
|
|
||
| torch==2.8.0 | ||
| black>=23.10.0 | ||
| black==26.3.1 | ||
| pylint>=3.0.1 | ||
| pytest>=7.4.0 | ||
| pytest-env>=1.1.3 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| from centml.cli.cluster import _get_service_status, _get_status_error_messages | ||
| from centml.sdk import RolloutStatus, ServiceStatus | ||
|
|
||
|
|
||
| def test_service_status_uses_legacy_service_status_when_present(): | ||
| status_response = SimpleNamespace(service_status=ServiceStatus.HEALTHY) | ||
|
|
||
| assert _get_service_status(status_response, revision_number=None) == ServiceStatus.HEALTHY | ||
|
|
||
|
|
||
| def test_service_status_maps_v3_healthy_rollout_status(): | ||
| status_response = SimpleNamespace(rollout_status=RolloutStatus.HEALTHY) | ||
|
|
||
| assert _get_service_status(status_response, revision_number=None) == ServiceStatus.HEALTHY | ||
|
|
||
|
|
||
| def test_service_status_uses_current_v3_revision_status(): | ||
| status_response = SimpleNamespace( | ||
| rollout_status=RolloutStatus.PROGRESSING, | ||
| revision_pod_details_list=[ | ||
| SimpleNamespace(revision_number=1, revision_status=ServiceStatus.HEALTHY), | ||
| SimpleNamespace(revision_number=2, revision_status=ServiceStatus.SCALINGUP), | ||
| ], | ||
| ) | ||
|
|
||
| assert _get_service_status(status_response, revision_number=2) == ServiceStatus.SCALINGUP | ||
|
|
||
|
|
||
| def test_service_status_uses_v3_revision_without_revision_number_as_fallback(): | ||
| status_response = SimpleNamespace( | ||
| rollout_status=RolloutStatus.DEGRADED, | ||
| revision_pod_details_list=[ | ||
| SimpleNamespace(revision_number=None, revision_status=ServiceStatus.IMAGEPULLBACKOFF) | ||
| ], | ||
| ) | ||
|
|
||
| assert _get_service_status(status_response, revision_number=2) == ServiceStatus.IMAGEPULLBACKOFF | ||
|
|
||
|
|
||
| def test_status_error_messages_include_revision_and_pod_messages(): | ||
| status_response = SimpleNamespace( | ||
| revision_pod_details_list=[ | ||
| SimpleNamespace( | ||
| revision_number=3, | ||
| error_message="revision failed", | ||
| pod_details_list=[ | ||
| SimpleNamespace(name="pod-a", error_message="image pull failed"), | ||
| SimpleNamespace(name="pod-b", error_message=None), | ||
| ], | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| messages = _get_status_error_messages(status_response) | ||
|
|
||
| assert messages == ["revision 3: revision failed", "revision 3 / pod-a: image pull failed"] | ||
|
|
||
|
|
||
| def test_status_error_messages_do_not_repeat_duplicate_messages(): | ||
| duplicate_message = "one or more objects failed to apply" | ||
| status_response = SimpleNamespace( | ||
| revision_pod_details_list=[ | ||
| SimpleNamespace( | ||
| revision_number=None, | ||
| error_message=duplicate_message, | ||
| pod_details_list=[SimpleNamespace(name=None, error_message=duplicate_message)], | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| assert _get_status_error_messages(status_response) == [f"revision: {duplicate_message}"] | ||
|
|
||
|
|
||
| def test_status_error_messages_include_legacy_status_message(): | ||
| status_response = SimpleNamespace(error_message="legacy service failure") | ||
|
|
||
| assert _get_status_error_messages(status_response) == ["legacy service failure"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from centml.sdk import ApiException | ||
| from centml.sdk.api import CentMLClient | ||
|
|
||
|
|
||
| def test_get_status_uses_v3_endpoint(): | ||
| api = MagicMock() | ||
| expected_status = SimpleNamespace() | ||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.return_value = expected_status | ||
|
|
||
| assert CentMLClient(api).get_status(123) is expected_status | ||
|
|
||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.assert_called_once_with(123) | ||
| api.get_deployment_status_deployments_status_deployment_id_get.assert_not_called() | ||
|
|
||
|
|
||
| def test_get_status_falls_back_to_legacy_endpoint_when_v3_is_not_found(): | ||
| api = MagicMock() | ||
| expected_status = SimpleNamespace() | ||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.side_effect = ApiException(status=404) | ||
| api.get_deployment_status_deployments_status_deployment_id_get.return_value = expected_status | ||
|
|
||
| assert CentMLClient(api).get_status(123) is expected_status | ||
|
|
||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.assert_called_once_with(123) | ||
| api.get_deployment_status_deployments_status_deployment_id_get.assert_called_once_with(123) | ||
|
|
||
|
|
||
| def test_get_status_raises_v3_error_when_both_status_endpoints_fail(): | ||
| api = MagicMock() | ||
| v3_error = ApiException(status=404) | ||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.side_effect = v3_error | ||
| api.get_deployment_status_deployments_status_deployment_id_get.side_effect = ApiException(status=404) | ||
|
|
||
| try: | ||
| CentMLClient(api).get_status(123) | ||
| except ApiException as e: | ||
| assert e is v3_error | ||
| else: | ||
| raise AssertionError("Expected ApiException") | ||
|
|
||
| api.get_deployment_status_v3_deployments_status_v3_deployment_id_get.assert_called_once_with(123) | ||
| api.get_deployment_status_deployments_status_deployment_id_get.assert_called_once_with(123) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.