Skip to content

Improved workflows example program and added in statestore functionality.#1020

Merged
halspang merged 18 commits into
dapr:masterfrom
RyanLettieri:workflow-test-improvement
Feb 10, 2023
Merged

Improved workflows example program and added in statestore functionality.#1020
halspang merged 18 commits into
dapr:masterfrom
RyanLettieri:workflow-test-improvement

Conversation

@RyanLettieri
Copy link
Copy Markdown
Contributor

…ionality

Signed-off-by: Ryan Lettieri ryanLettieri@microsoft.com

Description

Please explain the changes you've made

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: #[issue number]

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

@RyanLettieri RyanLettieri changed the title Beefed up the workflows example program and added in statestore functionality. Improved workflows example program and added in statestore functionality. Feb 2, 2023
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 2, 2023

Codecov Report

Merging #1020 (1d118bb) into master (bc3ec80) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1020   +/-   ##
=======================================
  Coverage   69.45%   69.45%           
=======================================
  Files         162      162           
  Lines        5432     5432           
  Branches      585      585           
=======================================
  Hits         3773     3773           
  Misses       1519     1519           
  Partials      140      140           
Flag Coverage Δ
net6 69.38% <ø> (ø)
net7 69.38% <ø> (ø)
netcoreapp3.1 69.42% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Copy Markdown
Contributor

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

Nice work on this! Here's my feedback. Mostly nit-picky stuff.

using WorkflowWebApp.Workflows;
using WorkflowWebApp.Models;
using JsonOptions = Microsoft.AspNetCore.Http.Json.JsonOptions;
using Dapr.Client;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Let's sort the using statements alphabetically.

string orderId = Guid.NewGuid().ToString()[..8];
// All the necessary inputs (with workflow options being optional)
string workflowComponent = "dapr";
string workflowName = "OrderProcessingWorkflow";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's do nameof(OrderProcessingWorkflow) instead of hardcoding the name. That way the program won't break if someone renames the workflow class.

// All the necessary inputs (with workflow options being optional)
string workflowComponent = "dapr";
string workflowName = "OrderProcessingWorkflow";
object input = orderInfo;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove this and pass orderInfo as the input directly.

string workflowComponent = "dapr";
string workflowName = "OrderProcessingWorkflow";
object input = orderInfo;
Dictionary<string, string> workflowOptions = new Dictionary<string, string>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is workflowOptions required or can we just pass null below since we don't add any options?

string workflowName = "OrderProcessingWorkflow";
object input = orderInfo;
Dictionary<string, string> workflowOptions = new Dictionary<string, string>();
CancellationToken cts = new CancellationToken();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's remove this and use CancellationToken.None below.

this.logger.LogInformation($"There are now: {original.Quantity} {original.Name} left in stock");

this.logger.LogInformation(
"OrderID '{requestId}' processed successfully",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd remove this log statement. This activity is only concerned with managing inventory and shouldn't make any assumptions about the status of the order.

{
readonly ILogger logger;
readonly DaprClient client;
private static readonly string storeName = "statestore";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this is defined in two places. Let's put it somewhere more global to reduce the duplication.

if (original == null)
{
// Not enough paperclips.
return new InventoryResult(false, original, originalETag);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of original and originalETag here, just do null, null. The intent is otherwise confusing to the reader.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"original" is still needed since it is the response from the statestore. If there are no items, we need to check for it. Furthermore, we use 'original' to see the quantity of items as well as logging. I think we should just rename 'original' to 'orderResponse' or something along those lines

Comment thread examples/Workflow/README.md Outdated

The application will listen for HTTP requests at `http://localhost:10080`.

This workflow example utilizes a redis statestore. In order to retrieve items from this statestore, an HTTP command must first be sent down to restock the inventory:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you meant, "In order to populate items into the state store..."

Comment thread examples/Workflow/README.md Outdated
On Windows (PowerShell):

```powershell
curl -i -X POST http://localhost:10080/reset `
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This command actually isn't correct for PowerShell. The trailing ` means you're entering a multi-line command, which is not the case.

In any case, the command is exactly the same for both bash and powershell, so no need to distinguish them here.

@RyanLettieri RyanLettieri marked this pull request as ready for review February 6, 2023 15:34
@RyanLettieri RyanLettieri requested review from a team as code owners February 6, 2023 15:34
}

this.logger.LogInformation(
"There are: {requestId}, {name} available for purchase",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question/nit: is the requestId the remaining items in stock? I wasn't sure, but the sentence sounds more correct to me without punctuation.

Suggested change
"There are: {requestId}, {name} available for purchase",
"There are {requestId} {name} available for purchase",

Comment thread examples/Workflow/README.md Outdated
Comment on lines 46 to 50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather prefer to have the shell scripts commands ready to run (for lazy users whose will copy/paste before going through the text, like me [sometimes]).

I can see two options:

  1. Generate a random ID and print after the command get executed
randomId=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 50 | head -n 1)
curl -i -X POST http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/$randomId/start \
  -H "Content-Type: application/json" \
  -d '{ "input" : {"Name": "Paperclips", "TotalCost": 99.95, "Quantity": 1}}'

This command works on Linix OSs

Then ask the user to copy out the instance_id from the curl output.

  1. Auto-generated workflow ids?

Given the circumstances (time-wise), I guess this option is not feasible cause it might require new APIs, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could also, assign the randomId to a variable to be reusable later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I updated the example to use a hardcoded ID. That seemed like an overall simpler solution. :)

And yes, we need to support auto-generated IDs. I'm planning to open a bug for v1.11 to support this.

Comment thread examples/Workflow/README.md Outdated
Comment on lines 55 to 57
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sry, my powershell knowledge isn't sufficient to suggest any specific solution for random string than googling it: https://devblogs.microsoft.com/scripting/generate-random-letters-with-powershell/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I switched to using harcoded IDs. It's what I use for my manual testing anyways, and the IDs can be reused after the workflow completes.

Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it's not returning any Location header, what I'm missing?
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other think is that my traceparent is not working as well (returning a bunch of zero) is that correct?

I guess you have zipkin configured while I don't. So you might have to disable since it was not mentioned?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’m planning to open a bug to track the missing Location header from the StartWorkflow API. Previously, we were returning it from the custom web API. For now, we should remove this from the directions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I removed the Location header from the response example and removed mention of it from the text. I also went ahead and removed the Traceparent headers to avoid distracting the user from the primary objective of this example.

cgillum
cgillum previously approved these changes Feb 6, 2023
Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: the other properties uses _ and this one is using a capital letter, but since this payloads comes from runtime I guess there's no alternative than creating a issue to change this later (v1.11).

this will be seen as a breaking change but since wf is in alpha we are fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can change "WFInfo" in v1.11 since it requires a change to the components-contrib code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tracking here: dapr/dapr#5911

Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we fulfill the custom_status field with something meaningful ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can consider this for a future update.

Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it valuable to supply the documentation link for individuals without a configured Zipkin?

https://docs.dapr.io/operations/monitoring/tracing/zipkin/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove blank line

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to return something <object>? Can we just return a Task ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The base class currently requires a Task<T>, but we can look into providing a Task option in a future update.

Comment on lines 57 to 59
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is 1 second always sufficient?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's just for vanity purposes, but so far it's been sufficient each time I tried.

Comment on lines 61 to 62
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need to mention this here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I figured that folks probably should rely on this pattern moving forward, and that it serves as a heads-up.

mcandeia
mcandeia previously approved these changes Feb 7, 2023
Comment thread examples/Workflow/README.md Outdated
Comment thread examples/Workflow/README.md Outdated
Comment thread examples/Workflow/README.md Outdated
Comment thread examples/Workflow/README.md Outdated
Comment thread examples/Workflow/README.md Outdated
Comment thread examples/Workflow/WorkflowConsoleApp/Program.cs Outdated
Comment thread examples/Workflow/WorkflowConsoleApp/Program.cs Outdated
Comment thread examples/Workflow/WorkflowConsoleApp/Program.cs Outdated
Comment thread examples/Workflow/WorkflowConsoleApp/Program.cs Outdated
Comment thread examples/Workflow/WorkflowConsoleApp/Program.cs Outdated
@msfussell
Copy link
Copy Markdown
Member

I would also update

@RyanLettieri RyanLettieri dismissed stale reviews from mcandeia and cgillum via d422920 February 8, 2023 23:44
Comment thread README.md Outdated
cgillum
cgillum previously approved these changes Feb 9, 2023
Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tracking here: dapr/dapr#5911

Comment thread examples/Workflow/README.md Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can consider this for a future update.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The base class currently requires a Task<T>, but we can look into providing a Task option in a future update.

Comment on lines 57 to 59
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's just for vanity purposes, but so far it's been sufficient each time I tried.

Comment on lines 61 to 62
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I figured that folks probably should rely on this pattern moving forward, and that it serves as a heads-up.

RyanLettieri and others added 14 commits February 9, 2023 11:45
Initial work for workflows DotNET SDK

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
…ionality

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
* Update DurableTask SDK dependency to get ARM64 compatibility

Signed-off-by: Chris Gillum <cgillum@microsoft.com>

* Fix issue with gRPC address override behavior

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
- Replaced DaprClient with WorkflowEngineClient
- Removed unused etag logic
- Fixed incorrect usage of certain model types
- Cleaned up logs and console output
- Simplified program loop
- Cleaned up console output and added some coloring
- Added error handling in the console interactions
- Various other tweaks/simplifications/enhancements

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
* add workflows to client page

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Copy link
Copy Markdown
Contributor

@halspang halspang left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks. Primarily around the placement of using statements. You had it in a few files where I didn't comment but generally all usings should be outside of the namespace.

Comment on lines 6 to 7
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: using should be above the namespace.

Comment on lines 3 to 7
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment here.

Comment thread examples/Workflow/WorkflowConsoleApp/Activities/UpdateInventoryActivity.cs Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The <NoWarn>612,618</NoWarn> disables the "obsolete" warnings that we get when using the DaprClient methods. I'm actually not sure that these are needed, though, now that we've reverted to using WorkflowEngineClient in this initial release of the sample.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These are to supress the warnings that come from the fact that we are using functions that are still in alpha.

@halspang halspang merged commit 9dcae7b into dapr:master Feb 10, 2023
yash-nisar pushed a commit to yash-nisar/dotnet-sdk that referenced this pull request Feb 27, 2023
…ity. (dapr#1020)

* Workflow Management - Initial Methods (dapr#1003)

Initial work for workflows DotNET SDK

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Beefed up the workflows example program and added in statestore functionality

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Addressing a bunch of review comments

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Updates to readme and demo for workflows

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Changed webapp to console app

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Update DurableTask SDK dependency to get ARM64 compatibility (dapr#1024)

* Update DurableTask SDK dependency to get ARM64 compatibility

Signed-off-by: Chris Gillum <cgillum@microsoft.com>

* Fix issue with gRPC address override behavior

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Remove Web APIs and web dependencies

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Renaming WorkflowWebApp to WorkflowConsoleApp

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Various updates to the sample app

- Replaced DaprClient with WorkflowEngineClient
- Removed unused etag logic
- Fixed incorrect usage of certain model types
- Cleaned up logs and console output
- Simplified program loop
- Cleaned up console output and added some coloring
- Added error handling in the console interactions
- Various other tweaks/simplifications/enhancements

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Updates to README and demo http commands

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Make README copy/paste-able and some other minor tweaks

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Adding in Paul's devcontainer work

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* More README touch-ups

Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* [docs] Add workflows to .NET client doc (dapr#1019)

* add workflows to client page

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Updating workflows readme and example

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* Fixing README for letting users know which .NET is needed

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

* moving using statements above the namespace

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>

---------

Signed-off-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Signed-off-by: Chris Gillum <cgillum@microsoft.com>
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
Co-authored-by: Ryan Lettieri <ryanLettieri@microsoft.com>
Co-authored-by: Chris Gillum <cgillum@microsoft.com>
Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
@halspang halspang added this to the v1.11 milestone Jun 1, 2023
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.

6 participants