-
Notifications
You must be signed in to change notification settings - Fork 27
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
♻️ refactor dv-2 dy-sidecar's API client #3121
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3121 +/- ##
========================================
+ Coverage 79.7% 81.1% +1.3%
========================================
Files 706 710 +4
Lines 30496 30615 +119
Branches 3950 3948 -2
========================================
+ Hits 24321 24834 +513
+ Misses 5352 4941 -411
- Partials 823 840 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
|
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base_client.py
Outdated
Show resolved
Hide resolved
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_thin_client.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Show resolved
Hide resolved
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_base_client.py
Outdated
Show resolved
Hide resolved
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py
Outdated
Show resolved
Hide resolved
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py
Show resolved
Hide resolved
services/director-v2/tests/unit/test_modules_dynamic_sidecar_client_api_public.py
Outdated
Show resolved
Hide resolved
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.
it's a nice addition. I would like to see a test where you catch the httpx error. I do not get why this one still goes through when all the others are encapsulated.
Also if you could maybe asses the fact that the dynamic sidecar already retries every 5 seconds, what is the point of bringing 4 more retries in every request call?
...ces/director-v2/src/simcore_service_director_v2/models/schemas/dynamic_services/scheduler.py
Show resolved
Hide resolved
"ClientTransportError", | ||
"close_api_client", | ||
"DynamicSidecarClient", | ||
"get_dynamic_sidecar_client", | ||
"setup_api_client", | ||
"UnexpectedStatusError", | ||
"update_dynamic_sidecar_health", |
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.
maybe simplify the name of the functions, we know they all are linked to the api_client.. suggestion:
setup, close, get
And what means: update_dynamic_sidecar_health? what is it supposed to do? It sounds a bit strange that as a client of the dynamic sidecar I would update its health.
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.
I agree for setup and close, not with the get_api_client.
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.
I went with a rename from update_dynamic_sidecar_health
to get_dynamic_sidecar_service_health
which should be more precise. Only issue is that it does not return anything but it stores it memory. That's why it was called update previously.
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Show resolved
Hide resolved
...es/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_public.py
Show resolved
Hide resolved
...es/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_public.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_thin.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_thin.py
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
for _, method in pubic_methods: | ||
signature = inspect.signature(method) | ||
if signature.return_annotation != Response: | ||
raise WrongReturnType(method, signature.return_annotation) |
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 check is in a constructor or a class, I do not think this check will run when imported.
What I mean is that a tool like mypy
will detect that in your decorators (e.g. expected_status
) you annotated that it wraps Callable[..., Awaitable[Response]]
. Therefore if it does not return a Reponse
it fails the static check!
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_base.py
Outdated
Show resolved
Hide resolved
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.
Please review my latest comments
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.
Very nice. Please check my 2-3 comments.
) | ||
return response.json() | ||
except UnexpectedStatusError: | ||
return {} |
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.
I do find a bit weird that most of the calls actually raise further but this one not. I am not sure that is consistent. maybe consider raising? or is there a rationale for not doing so?
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.
Tis one can still raise BaseClientHTTPError
. Which is actually trapped and handled at the point where it is used.
This happens in the two below calls you singled and in task.py
...es/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_public.py
Show resolved
Hide resolved
...es/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_public.py
Show resolved
Hide resolved
...ices/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/api_client/_thin.py
Show resolved
Hide resolved
|
||
|
||
@pytest.fixture | ||
def env_mocks(monkeypatch: MonkeyPatch, mock_env: None) -> 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.
def env_mocks(monkeypatch: MonkeyPatch, mock_env: None) -> None: | |
def mock_end(monkeypatch: MonkeyPatch, mock_env: None) -> None: |
Let's define this as good practice now. overwrite it, let's not have thousand different names
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.
OK, not bad, I like this one!
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.
actually mock_env not mock_end...
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.
So I can overwrite the same exiting mock with one of the same name even when inheriting from it!
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
What do these changes do?
Brings a "drop-in" replacement of the dynamic-sidecar
client_api
module inside director-v2.This new module adds:
The new module
api_client
is composed of 3 layers:_base.py
contains all the low level error handling and utils to create an interface for an API. The ideas is that this module can be moved elsewhere and shared with other clients. Functionality is exposed via decorators, like:expect_status
andretry_on_errors
_thin.py
contains a thin client wrapping around the HTTP interface of the dynamic-sidecar. In the future this could be autogenerated from the OAS file of a service._public.py
is the port of the previousclient_api
based on the thin_ client.Related issue/s
How to test
Checklist