Skip to content

Workflow Authoring #559

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

Merged
merged 42 commits into from
May 23, 2023
Merged

Workflow Authoring #559

merged 42 commits into from
May 23, 2023

Conversation

DeepanshuA
Copy link
Contributor

@DeepanshuA DeepanshuA commented Apr 25, 2023

Description

This PR implements Workflow Authoring part.

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 is related to: #542

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

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@DeepanshuA DeepanshuA requested review from a team as code owners April 25, 2023 10:41
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@DeepanshuA DeepanshuA changed the title Workflow Authoring [DRAFT] Workflow Authoring Apr 25, 2023
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #559 (a9be483) into master (5219da0) will increase coverage by 0.01%.
The diff coverage is 89.91%.

@@            Coverage Diff             @@
##           master     #559      +/-   ##
==========================================
+ Coverage   89.59%   89.60%   +0.01%     
==========================================
  Files          62       72      +10     
  Lines        2978     3310     +332     
==========================================
+ Hits         2668     2966     +298     
- Misses        310      344      +34     
Impacted Files Coverage Δ
...ext-workflow/dapr/ext/workflow/workflow_runtime.py 76.92% <76.92%> (ø)
...orkflow/dapr/ext/workflow/dapr_workflow_context.py 77.77% <77.77%> (ø)
...ext-workflow/dapr/ext/workflow/workflow_context.py 79.48% <79.48%> (ø)
...r-ext-workflow/dapr/ext/workflow/workflow_state.py 83.87% <83.87%> (ø)
...t/dapr-ext-workflow/tests/test_workflow_runtime.py 92.85% <92.85%> (ø)
...r-ext-workflow/tests/test_dapr_workflow_context.py 94.11% <94.11%> (ø)
...low/dapr/ext/workflow/workflow_activity_context.py 94.73% <94.73%> (ø)
...workflow/dapr/ext/workflow/dapr_workflow_client.py 97.43% <97.43%> (ø)
...xt/dapr-ext-workflow/tests/test_workflow_client.py 98.27% <98.27%> (ø)
...xt/dapr-ext-workflow/dapr/ext/workflow/__init__.py 100.00% <100.00%> (ø)
... and 1 more

@DeepanshuA
Copy link
Contributor Author

Removing DRAFT label from PR, but I still need to check-in test cases for it, add remaining client APIs and also see how I can remove get-pip.py.

@DeepanshuA DeepanshuA changed the title [DRAFT] Workflow Authoring Workflow Authoring Apr 25, 2023
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@@ -0,0 +1 @@
dapr-ext-workflow==1.5.0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dapr-ext-workflow==1.5.0
dapr-ext-workflow-dev==0.0.1-rc.1

Where did you come up with this version? :D That will not be the version number we are using.

What version would you like to launch the SDK with? I would assume 0.1.0?

In the master branch we always import our development packages -- so use the -dev one. In the release branches we then remove the -dev suffix to refer to the stable packages. The -dev one is the builds from master that we constantly update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you are correct. I don't know how I wrote this number here :)
Will fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to 0.0.1rc1 as per version.py of dapr-ext-workflow

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
daprOptions.register_activity(hello_act)
daprOptions.run()

client = WorkflowClient("localhost","4001")
Copy link
Member

Choose a reason for hiding this comment

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

What is this port 4001? Where is this configured? Why this port?

Copy link
Contributor

Choose a reason for hiding this comment

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

@DeepanshuA let's remove the explicit port configuration from this example. The default value of DAPR_GRPC_PORT will be what most users want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use DAPR_GRPC_PORT. If that is not found, then "4001" is used.
Used "4001" due to https://github.com/microsoft/durabletask-python/blob/dcf205831124d82ca3886e5dba26d8c7a9ac8d73/durabletask/internal/shared.py#L18

DeepanshuA and others added 5 commits May 2, 2023 15:06
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
daprOptions.register_activity(hello_act)
daprOptions.run()

client = WorkflowClient("localhost","4001")
Copy link
Contributor

Choose a reason for hiding this comment

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

@DeepanshuA let's remove the explicit port configuration from this example. The default value of DAPR_GRPC_PORT will be what most users want.

@@ -0,0 +1,47 @@
from typing import Callable, TypeVar, Union
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the copyright header to all these files you're adding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

host = settings.DAPR_RUNTIME_HOST
if port is None:
port = settings.DAPR_GRPC_PORT
address = f"{host}:{port}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's raise an error if either host or port is still None even after running through this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to set "host" to localhost, if DAPR_RUNTIME_HOST is not found.
Updated to raise an error, if DAPR_GRPC_PORT is not found.

@@ -25,6 +25,7 @@ packages = find_namespace:
include_package_data = True
install_requires =
dapr-dev >= 1.9.0rc1.dev
durabletask >= 0.1.0a2
Copy link
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 update this again after your latest fix to make durabletask-python compatible with 3.7 or does this version already have that support?

Copy link
Member

Choose a reason for hiding this comment

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

Yes it seems you need to release 0.1.0a3 and then update this here. The version with 3.7 compatibility has not been released yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0.1.0a2 durabletask-python also has 3.7 support. But, had marked 0.1.0a3 in durabletask-python, as wanted to keep Pypi and source code on github in sync. As, 0.1.0a2 had Pypi support even when 3.7 compliant PR was not merged.
Need to automate the release process in durabletask-python, I think then this mis-match issue will not be there.

Copy link
Member

@berndverst berndverst left a comment

Choose a reason for hiding this comment

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

In general I'm very confused how WorkflowClient here overlaps with Ryan's PR for workflow management.

I assume in this PR it is more of a WorkflowHost or WorkflowServer which the Dapr sidecar calls into?
If this understanding is correct, can we please avoid calling the class WorkflowClient ?

OrchestratorClient or WorkflowEngineClient or WorkflowEngineCallbackClient or something like that makes more sense to me. I assume this is how the sidecar tells your workflow to execute certain operations like pause, start, resume etc



class WorkflowRuntimeOptions:

Copy link
Member

Choose a reason for hiding this comment

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

Please add a doc string. It's not apparent to me what this class is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to WorkflowRuntime and provided a doc string.

@berndverst
Copy link
Member

Hmm or instead of WorkflowClient it could be WorkflowHostClient WorkflowProviderClient or something like that.

Anything but WorkflowClient :)

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
tox.ini Outdated
Comment on lines 47 to 53
; ./validate.sh demo_actor
./validate.sh demo_workflow
./validate.sh invoke-binding
./validate.sh grpc_proxying
./validate.sh w3c-tracing
./validate.sh distributed_lock
./validate.sh configuration
; ./validate.sh configuration
Copy link
Contributor

@tmacam tmacam May 16, 2023

Choose a reason for hiding this comment

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

Any reason to leave these commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, these tests are failing with 1.10.x Dapr version. These should be fixed with 1.11.x version though, So, will remove these commented outs, once 1.11.x can be pinned and validation can run against them.

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@DeepanshuA
Copy link
Contributor Author

@cgillum @berndverst Please re-review this PR. I have tried to address comments and included validate example for workflow as well.
I have commented out demo_actor and configuration from validate example, as they were failing with current Dapr 1.10.7 version. Will include them, once we have 1.11.x pointed here.

Copy link
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.

Just a few additional comments from me. Note that I didn't spend much time on the test-related files since I don't really understand how the mocking works (and I'm assuming it's not something requiring critical review).

from dapr.ext.workflow.workflow_runtime import WorkflowRuntime
from dapr.ext.workflow.dapr_workflow_client import DaprWorkflowClient
from dapr.ext.workflow.dapr_workflow_context import DaprWorkflowContext
from dapr.ext.workflow.workflow_activity_context import WorkflowActivityContext
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need so many modules or could we reduce it down to just one or two? Note that we don't need to organize files the same way we do for .NET. Ideally we could just do something like:

from dapr.ext.workflow import DaprWorkflowClient, DaprWorkflowContext, WorkflowActivityContext, WorkflowRuntime

...or...

import dapr.ext.workflow as wf

And just refer to everything from the wf. prefix, like wf.DaprWorkflowContext, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could import those into dapr.ext.workflow's init.py exactly as the code about so they could be imported as you mentioned. Agree it would make the existing and future code simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please check now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In recent validate examples, somehow import in app.py is failing.
Everything seems working on my local though.
https://github.com/dapr/python-sdk/actions/runs/5020485194/jobs/9001991467#step:17:279

trying to understand that what can be the issue, is somehow dapr-ext-workflow build used in validate examples, not consisting of my init.py changes
@berndverst Any suggestions here?

if port is None:
port = settings.DAPR_GRPC_PORT
if port is None:
raise ValueError("Port cannot be empty, please set DAPR_GRPC_PORT environment variable")
Copy link
Contributor

Choose a reason for hiding this comment

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

If no port is specified, let's default to 50001. This is the documented default port for gRPC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, in global_settings.py, DAPR_GRPC_PORT is already defined to its default: https://github.com/dapr/python-sdk/blob/master/dapr/conf/global_settings.py#L24
So, it is just an extra check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, my bad. It might actually be better to remove the check to avoid confusion. Too much defense in depth can be misleading.

Comment on lines 22 to 26

dapr run --app-id orderapp --app-protocol grpc --dapr-grpc-port 4001 --components-path components --placement-host-address localhost:50005 -- python3 app.py
```

<!-- END_STEP -->
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this into a separate section, named "Running this example".

Suggested change
dapr run --app-id orderapp --app-protocol grpc --dapr-grpc-port 4001 --components-path components --placement-host-address localhost:50005 -- python3 app.py
```
<!-- END_STEP -->
<!-- END_STEP -->
## Running this example
To run this example, the following code can be utilized:
```bash
dapr run --app-id orderapp --app-protocol grpc --dapr-grpc-port 4001 --components-path components --placement-host-address localhost:50005 -- python3 app.py

Copy link
Contributor

Choose a reason for hiding this comment

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

And we need some validation on the execution of this workflow, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, app.py has got some required assertions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, added expected_stdout_lines in Readme itself.

DeepanshuA added 11 commits May 18, 2023 09:12
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
berndverst and others added 2 commits May 22, 2023 13:37
Signed-off-by: Bernd Verst <github@bernd.dev>
Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
@berndverst
Copy link
Member

berndverst commented May 22, 2023

Let's see if the ordering works 👀 - that should give placement service plenty of time to initialize

@DeepanshuA
Copy link
Contributor Author

Let's see if the ordering works 👀 - that should give placement service plenty of time to initialize

surprisingly, it still failed - don't know if placement goes in unstable state in-between due to raft election etc.

Signed-off-by: Deepanshu Agarwal <deepanshu.agarwal1984@gmail.com>
Copy link
Member

@berndverst berndverst left a comment

Choose a reason for hiding this comment

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

I verified this locally. I will merge this now - but if we find an issue, please be prepared to create a follow up PR.

@berndverst berndverst merged commit e27dac9 into dapr:master May 23, 2023
@berndverst berndverst added this to the v1.10 milestone Jun 5, 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.

5 participants