Skip to content
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

feat: Support for the DAPR_HTTP_ENDPOINT and DAPR_GRPC_ENDPOINT environment variables. Adds support for DAPR_API_TOKEN to gRPC client #519

Merged
merged 23 commits into from
Sep 27, 2023

Conversation

elena-kolevska
Copy link
Contributor

@elena-kolevska elena-kolevska commented Sep 12, 2023

Description

  • Adds support for DAPR_API_TOKEN to gRPC client
  • Adds support for the DAPR_GRPC_ENDPOINT environment variable
  • Adds support for the DAPR_HTTP_ENDPOINT environment variable

Issue reference

Issue this PR will close: #502 and #520

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@elena-kolevska elena-kolevska changed the title Support for the DAPR_HTTP_ENDPOINT environment variable feat: Support for the DAPR_HTTP_ENDPOINT environment variable Sep 12, 2023
@elena-kolevska elena-kolevska marked this pull request as ready for review September 13, 2023 09:52
@elena-kolevska elena-kolevska requested review from a team as code owners September 13, 2023 09:52
@elena-kolevska elena-kolevska marked this pull request as draft September 18, 2023 15:15
@elena-kolevska elena-kolevska changed the title feat: Support for the DAPR_HTTP_ENDPOINT environment variable feat: Support for the DAPR_HTTP_ENDPOINT and DAPR_GRPC_ENDPOINT environment variable Sep 18, 2023
@elena-kolevska elena-kolevska changed the title feat: Support for the DAPR_HTTP_ENDPOINT and DAPR_GRPC_ENDPOINT environment variable feat: Support for the DAPR_HTTP_ENDPOINT and DAPR_GRPC_ENDPOINT environment variables. Adds support for DAPR_API_TOKEN to gRPC client Sep 18, 2023
@elena-kolevska elena-kolevska marked this pull request as ready for review September 18, 2023 16:03
Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Attention: 31 lines in your changes are missing coverage. Please review.

Comparison is base (553affa) 35.23% compared to head (3b27c23) 35.34%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
+ Coverage   35.23%   35.34%   +0.11%     
==========================================
  Files          90       90              
  Lines       10143    10187      +44     
  Branches      415      429      +14     
==========================================
+ Hits         3574     3601      +27     
- Misses       6503     6516      +13     
- Partials       66       70       +4     
Files Coverage Δ
src/utils/Settings.util.ts 70.58% <100.00%> (+17.25%) ⬆️
...mplementation/Client/GRPCClient/GRPCClientProxy.ts 15.00% <0.00%> (-0.79%) ⬇️
src/implementation/Client/GRPCClient/GRPCClient.ts 76.78% <80.00%> (+0.04%) ⬆️
src/utils/Client.util.ts 43.26% <26.47%> (-2.89%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/utils/Client.util.ts Outdated Show resolved Hide resolved
src/utils/Client.util.ts Outdated Show resolved Hide resolved
src/utils/Client.util.ts Outdated Show resolved Hide resolved
src/utils/Client.util.ts Show resolved Hide resolved
src/utils/Client.util.ts Outdated Show resolved Hide resolved
test/unit/grpc/GRPCClient.test.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated
@@ -12,7 +12,7 @@
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

@elena-kolevska elena-kolevska Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubham1172 I enabled this so I could debug the code. I'm not a typescript person though, so if you think it's better not to have it in a release, that's totally ok for me, I'll just enable it for my local development.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use the same tsconfig for dev and prod, the production build size will also increase. We could add support to conditionally generate sourceMap for development only, but for now we should turn this off.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been resolved meanwhile?

elena-kolevska and others added 4 commits September 20, 2023 11:43
Co-authored-by: Shubham Sharma <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
Co-authored-by: Shubham Sharma <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
Copy link
Member

@shubham1172 shubham1172 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elena-kolevska LGTM overall! I wish this was two PRs instead of one but it's ok for now since we are very close to release and both of them are affecting the DaprClient.

Great work with adding the test to check for Dapr API token and fixing the proxy to include interceptors from gRPC client!

src/implementation/Client/GRPCClient/GRPCClient.ts Outdated Show resolved Hide resolved
src/utils/Client.util.ts Show resolved Hide resolved
src/utils/Settings.util.ts Outdated Show resolved Hide resolved
src/utils/Settings.util.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated
@@ -12,7 +12,7 @@
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
"sourceMap": true /* Generates corresponding '.map' file. */,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been resolved meanwhile?

Signed-off-by: Elena Kolevska <[email protected]>
@elena-kolevska
Copy link
Contributor Author

@XavierGeerinck and @shubham1172 Thank you both for the review! I updated the PR and commented on some of your questions.

Comment on lines 87 to 91
// Using HTTP, when DAPR_HTTP_ENDPOINT is set
const client = new DaprClient({ daprHost, daprPort });

// Using gRPC, when DAPR_GRPC_ENDPOINT is set
const client = new DaprClient({ communicationProtocol: CommunicationProtocol.GRPC });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we showing here that this is the equivalent of setting the environment variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how we can instantiate the client when we have DAPR_GRPC_ENDPOINT set. I noticed I had a copy/paste error for the HTTP example above though, so I fixed that. Basically, we don't need to pass constructor arguments for host and port when we have the env variables set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if DAPR_GRPC_ENDPOINT is set, should we also by-default use communication protocol GRPC. Also while instantiating the DaprClient, should we clearly log if we used env var to figure out host/port/protocol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I can add a log.
Regarding the automatic setting of the protocol, I think we can't do it, because, as per the proposal we can have both DAPR_GRPC_ENDPOINT and DAPR_HTTP_ENDPOINT set at the same time.

DAPR_GRPC_ENDPOINT and DAPR_HTTP_ENDPOINT can be set at the same time since some SDKs (Java, as of now) supports both protocols at the same time and app can pick which one to use.

Copy link
Member

@shubham1172 shubham1172 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right (and maybe this can be added to the proposal to unify SDK implementations), so if

  1. DAPR_GRPC_ENDPOINT is set, set protocol to gRPC
  2. DAPR_HTTP_ENDPOINT is set, set protocol to HTTP
  3. Both are set, use HTTP
  4. Finally, if function param is specified, that overrides everything
  5. No function param or env var also means HTTP

PS, we can track this separately as well.

shubham1172
shubham1172 previously approved these changes Sep 27, 2023
Copy link
Member

@shubham1172 shubham1172 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for updating the parseEndpoint implementation, much better to delegate the parsing!

Signed-off-by: Elena Kolevska <[email protected]>
@XavierGeerinck
Copy link
Contributor

Thank you so much! Running the tests now and if they pass we can merge :) thanks again for sticking with us and fixing the URL lib usage

@XavierGeerinck XavierGeerinck added this pull request to the merge queue Sep 27, 2023
Merged via the queue into dapr:main with commit 7464735 Sep 27, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support DAPR_HTTP_ENDPOINT and/or DAPR_GRPC_ENDPOINT
3 participants