Add an HTTP client for service invocation and default to using it#182
Conversation
027d418 to
a70aa3b
Compare
Codecov Report
@@ Coverage Diff @@
## master #182 +/- ##
==========================================
+ Coverage 87.11% 88.65% +1.54%
==========================================
Files 47 50 +3
Lines 1862 1948 +86
==========================================
+ Hits 1622 1727 +105
+ Misses 240 221 -19
Continue to review full report at Codecov.
|
3714150 to
ba83fb7
Compare
| from dapr.clients.base import DaprActorClientBase | ||
| from dapr.clients.exceptions import DaprInternalError, ERROR_CODE_UNKNOWN | ||
| from dapr.clients.grpc.client import DaprClient | ||
| from dapr.clients.generic import DaprClient |
There was a problem hiding this comment.
generic is an overloaded term here. Can you name this package something else? Maybe main?
| http_querystring: Optional[MetadataTuple] = None) -> InvokeMethodResponse: | ||
|
|
||
| if self.invocation_client: | ||
| return self.invocation_client.invoke_method( |
There was a problem hiding this comment.
Why tests do not cover this if-else?
There was a problem hiding this comment.
The unit tests are hitting the DaprHttpInvocationClient class directly
| matched with the response data type | ||
| """ | ||
|
|
||
| if self.content_type == "application/x-protobuf": |
There was a problem hiding this comment.
handle lower case vs upper case and content type optional suffix (application/x-protobuf; gzip)
There was a problem hiding this comment.
The http library already correctly parses out the suffix for us, but I'll add a test to confirm this. Will also make case sensitive.
|
|
||
|
|
||
| class DaprClient: | ||
| class DaprGrpcClient: |
There was a problem hiding this comment.
Why renaming it if it is in another package?
There was a problem hiding this comment.
Because there is a new DaprClient which inherits from this class. Would be confusing if I named it the same, wouldn't it?
There was a problem hiding this comment.
You can name it differently when importing it. It is already in another package.
There was a problem hiding this comment.
Yeah, but we only named it so generically in the first place because we only had the gRPC client and nothing else. Now that we have both gRPC and HTTP, naming them more specifically makes sense.
| dict_obj = obj | ||
|
|
||
| # importing this from top scope creates a circular import | ||
| from dapr.actor.runtime.config import ActorRuntimeConfig |
There was a problem hiding this comment.
Wait. Why we did not have this before?
There was a problem hiding this comment.
We did, I just moved it out of the module scope.
There was a problem hiding this comment.
You mean we had a circular import before?
There was a problem hiding this comment.
Right, if I attempted include the json serializer without including all the actor classes first, it would try to pull in ActorRuntimeConfig which would pull in the rest of the actor classes, which would pull in the json serializer. This was the easiest way to break the loop.
| from unittest.mock import patch | ||
|
|
||
| from dapr.clients.grpc.client import DaprClient | ||
| from dapr.clients.grpc.client import DaprGrpcClient as DaprClient |
There was a problem hiding this comment.
This is odd because it was named correctly before.
There was a problem hiding this comment.
This is what I mean, you can just name it DaprGrpcClient when using it. So the class can keep the original name.
There was a problem hiding this comment.
Yeah, but I'd rather not have two classes which are both called DaprClient in the overall project, even if I can alias one of them away. Prefer to just call the DaprGrpcClient the same everywhere and use the generic name DaprClient only for the public facing class that does both Grpc and HTTP. I've updated this to not use an alias, rather just use the name DaprGrpcClient everywhere, so there is no ambiguity anywhere.
ba83fb7 to
ebbf94e
Compare
| if http_verb is not None: | ||
| verb = http_verb | ||
|
|
||
| headers = {} |
There was a problem hiding this comment.
We need DAPR_API_TOKEN and the traceparent header to be set here.
There was a problem hiding this comment.
Ended up putting this in dapr/clients/http/client.py:50 so it can be shared with the Actor API client.
|
Tracing and API token added. I've verified the sample. Everything looks right, though the grpc integration has an extra span in the stack. |
3de731f to
c159dd5
Compare
c159dd5 to
0ce0695
Compare
Description
Created an HTTP client to use for service invocation. Also added a configuration option allow GRPC to be used as well.
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #176
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: