aspire-samples icon indicating copy to clipboard operation
aspire-samples copied to clipboard

Dapr Actor Example?

Open pjmagee opened this issue 1 year ago • 18 comments

I can't get a simple actor setup working but looking through some of the Dapr configuration DaprClient is not setup the same way as the ActorProxy class. Wondering if it should be working and I'm just not sure how to set it up correctly with an asp.net core web project hosting the actor proxy implementation and getting a simple console app to use the Proxy and make calls to the actors. The connection doesnt seem to work for me, but there's no starter sample using actors so I'm not sure if its me or if it's been an oversight with Actors being different to Sidecar web services or something?

pjmagee avatar Jan 05 '24 19:01 pjmagee

cc @philliphoff

davidfowl avatar Jan 05 '24 19:01 davidfowl

I'm seeing an issue with Dapr actors and Aspire as well (on Preview 2). If running via Aspire, the Dapr sidecar doesn't appear to fetch the application's configuration (which contains, among other things, its registered actor types). However, my own requests to the application's /dapr/config endpoint return the expected registrations. If I take the same command line for the Dapr sidecar (as shown in the Aspire dashboard), the sidecar does appear to fetch the application's configuration and notice its registrations.

@karolz-ms Are there any implicit proxies between the Dapr sidecar and the application in the normal single-replica case?

philliphoff avatar Jan 06 '24 00:01 philliphoff

Yes, the sidecar and the replica are both currently modeled as services, so each gets its own proxy. Is the sidecar a singleton, regardless how many replicas it serves? If so, it would be a candidate to switch to "proxyless service" mode, which DCP does support since preview 2.

karolz-ms avatar Jan 06 '24 01:01 karolz-ms

The Dapr sidecar has a 1:1 relationship with the service. There should be a separate sidecar instance for each service replica, though the sidecars will share the same application ID; the sidecars will use their own scheme for distributing traffic across replicas. (I don't know if Aspire is creating multiple sidecars today; I haven't done any testing to date with replicas.)

philliphoff avatar Jan 08 '24 18:01 philliphoff

Tagging with area-app-model-offsite because I think this is a hard problem to solve in our current architecture. Standing up replicas is controlled by DCP, but by the time they start getting spun up it is too late to start adding in extra containers/executables.

mitchdenny avatar Jan 11 '24 04:01 mitchdenny

Did we fix this @karolz-ms ?

davidfowl avatar Jan 23 '24 04:01 davidfowl

@davidfowl Using the 8.0.0-preview.3.24072.3 daily build of Aspire, I'm no longer seeing this issue. The service actors are getting registered and I can invoke them from a client application.

@pjmagee You might try with a recent daily build or wait until the upcoming Preview 3 to see if your issue is, indeed, resolved.

philliphoff avatar Jan 23 '24 16:01 philliphoff

(I don't know if Aspire is creating multiple sidecars today; I haven't done any testing to date with replicas.)

@philliphoff I just tried this tonight and it doesn't create multiple sidecars ☹️

laurentkempe avatar Feb 08 '24 21:02 laurentkempe

preview3?

davidfowl avatar Feb 08 '24 21:02 davidfowl

I think it was preview 4

laurentkempe avatar Feb 09 '24 23:02 laurentkempe

@philliphoff can you add an actor example to the dapr playground project?

davidfowl avatar Feb 24 '24 07:02 davidfowl

@philliphoff is this something you plan to do? we moved out of GA anyway.

danmoseley avatar Apr 22 '24 19:04 danmoseley

This is happening for me still. We are using dapr actors in multiple production deployed projects and would love to integrate Aspire for local development. If I use VS Code to run the project (based on official documentation) the system works fine but if I run using Aspire, the Actor Proxy is not able to call any actor methods.

This the log from the dapr sidecar

2024-10-04T13:13:16.2720000 time="2024-10-04T09:13:16.2723811-04:00" level=debug msg="api error: code = Internal desc = error invoke actor method: did not find address for actor JobContextDataPollActor/qa1_19986" app_id=system-monitoring-service instance=5CG3290HV0 scope=dapr.runtime.http type=log ver=1.14.2 2024-10-04T13:13:16.7260000 time="2024-10-04T09:13:16.7266552-04:00" level=warning msg="Error processing operation DaprBuiltInActorNotFoundRetries. Retrying in 1s…" app_id=system-monitoring-service instance=5CG3290HV0 scope=dapr.runtime type=log ver=1.14.2 2024-10-04T13:13:16.7260000 time="2024-10-04T09:13:16.7266552-04:00" level=debug msg="Error for operation DaprBuiltInActorNotFoundRetries was: did not find address for actor JobStateActor/qa1_19934" app_id=system-monitoring-service instance=5CG3290HV0 scope=dapr.runtime type=log ver=1.14.2

It would be helpful to have a Dapr + Aspire sample that uses Actors

msislam3 avatar Oct 04 '24 13:10 msislam3

@msislam3 I have a quickly-thrown-together sample here: https://github.com/philliphoff/DaprAndAspireSample

philliphoff avatar Oct 25 '24 18:10 philliphoff

@philliphoff I think I have found the issue. The repo really helped. I was calling WebApplication.UseHttpsRedirection() extension method in the actor project. The actor calls started to work when I removed it. I don't need this call so it worked for me but I am not sure why this call would cause the issue and why it works in VS Code setup. Image

msislam3 avatar Oct 29 '24 18:10 msislam3

@philliphoff I have reproduce the issue with your repo by adding the same extension call Image Image I am not sure if I should create a new issue or it's normal

msislam3 avatar Oct 29 '24 19:10 msislam3

@msislam3 My guess is that the Dapr sidecar may not be following the redirect to the HTTPS endpoint when it's attempting to invoke/manage the actors in the service (as, by default, the Dapr sidecar uses HTTP). My interpretation of the ASP.NET guidelines is that web APIs (like an actors project) shouldn't redirect to HTTPS (as it risks clients still calling the HTTP endpoint with sensitive data--instead they should only expose an HTTPS endpoint). In that case, you could configure the Dapr sidecar explicitly use the HTTPS endpoint.

philliphoff avatar Oct 29 '24 23:10 philliphoff

@philliphoff no it makes sense. I agree that an web API should not expose http endpoints. In fact our project is not. I am not sure why we had that redirect call. I have removed it and it's working. Thanks for your help on this!

msislam3 avatar Oct 30 '24 02:10 msislam3