-
Notifications
You must be signed in to change notification settings - Fork 511
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
Fix and normalize the Javascript HTTP and SDK styles of State Management #687
Fix and normalize the Javascript HTTP and SDK styles of State Management #687
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.
LGTM. Really nice contribution and improvement, @mattmazzola Thank you!. I'd love to make a little style guide with things like use Await instead of and not including .then, etc, removing last ; etc.
I would love @XavierGeerinck (js maintainer) and @amulyavarote (author) to review too. |
Added my review on it, thanks for flagging me in it! :) really nice PR |
Review looks good to me! |
|
||
// Save state into the state store | ||
client.state.save(STATE_STORE_NAME, [ | ||
const host = `${DAPR_PROTOCOL}://${DAPR_HOST}` |
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.
You don't need to use the host here as we will automatically do this for you (https://github.com/dapr/js-sdk/blob/master/src/implementation/Client/HTTPClient/HTTPClient.ts#L47) so you can drop the url creation here and just pass localhost
.
As for which protocol to use, maybe you can just use:
import { DaprClient, CommunicationProtocol } from "@dapr/dapr";
const protocol = (DAPR_PROTOCOL === "http") ? CommunicationProtocol.HTTP : CommunicationProtocol.GRPC;
const client = new DaprClient(host, PORT, protocol);
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, I updated to use something similar to your suggestion
- Use
CommunicationProtocolEnum
instead of 'http' string - Remove protocol from url construction and instead pass protocol to DaprClient constructor
- use lowercase version of variables (port, host, etc) since they were not constants
- Remove
orderId
to avoid confusion about why it wasn't used
Given DAPR_PROTOCOL is non standard and is NOT set automatically by the Dapr CLI like the other env vars we have to assume it will not be set and in that case default both to "http"
Ideas for Dapr / CLI improvement
Given this determining of which port / env var to use based on protocol is going to be common across all Dapr apps. I think there should be first-class support for this in the Dapr SDK and the Dapr CLI should make DAPR_PROTOCOL standard and set it just like DAPR_GRPC_PORT and DAPR_HTTP_PORT
option | var |
---|---|
--app-protocol http | ? (why is nothing set for this?) |
--dapr-http-port 3500 | DAPR_HTTP_PORT |
--dapr-grpc-port 6001 | DAPR_GRPC_PORT |
@mattmazzola Hi! Thanks for this contribution. Can you please take the latest changes, rebase and push the changes? We actually pushed few changes recently to fix the build issues. Pulling and rebasing the latest changes should fix your PR's build issues. Thanks! |
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.
Other changes look good to me!
Hi! Can you please fix state management workflows and also DCO? |
No, I don't know what those terms mean. I thought this would be a simple PR, but this ridiculous. I give up |
@mattmazzola - @amulyavarote will work with you to resolve the above. This PR is too good to drop. We really welcome your contribution here and apologize if this is unclear. We will work to make the testing need to be simpler. |
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
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.
LGTM
Description
Both the HTTP and SDK tutorials demonstrating State Management using JavaScript had many mistakes and inconsistencies making them poor quality.
As mentioned in those issues there were numerous problems:
sleep
start
that didn't actually start anythingYou can see both tutorials now function with the same output:
Normalization of HTTP and SDK
The purpose of having the HTTP and SDK folders was to show them doing the same thing and how a developer may choose to use the SDK or may user HTTP directly.
The inconsistencies between the two code samples meant that there were many other changes besides merely using the SDK or not which distracts the user from recognizing this.
By removing all the inconsistencies, or normalizing the code it can be seen much more clearly that the ONLY change is the swapping of SDK calls for HTTP requests.
Issue reference
We strive to have all PRs 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:
Closes #2495
Closes #2494
Closes #693
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: