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

Migrate actors to use grpc #954

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

addjuarez
Copy link

Signed-off-by: addjuarez addiajuarez@gmail.com

Description

Migrate .net actor implementation to use grpc by default.

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: #486

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

@codecov
Copy link

codecov bot commented Sep 22, 2022

Codecov Report

Merging #954 (4cae4c2) into master (1605ecd) will decrease coverage by 3.06%.
The diff coverage is 1.44%.

@@            Coverage Diff             @@
##           master     #954      +/-   ##
==========================================
- Coverage   70.17%   67.11%   -3.06%     
==========================================
  Files         160      161       +1     
  Lines        5284     5526     +242     
  Branches      567      592      +25     
==========================================
+ Hits         3708     3709       +1     
- Misses       1442     1679     +237     
- Partials      134      138       +4     
Flag Coverage Δ
net6 67.02% <1.44%> (-3.06%) ⬇️
net7 67.02% <1.44%> (-3.06%) ⬇️
netcoreapp3.1 67.08% <1.44%> (-3.06%) ⬇️

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

Impacted Files Coverage Δ
src/Dapr.Actors/DaprGrpcInteractor.cs 0.00% <0.00%> (ø)
src/Dapr.Actors/DaprHttpInteractor.cs 44.79% <0.00%> (-7.04%) ⬇️
src/Dapr.Actors/Runtime/ActorRuntimeOptions.cs 72.34% <0.00%> (-4.94%) ⬇️
src/Dapr.Actors/Runtime/DaprStateProvider.cs 17.39% <0.00%> (+9.84%) ⬆️
src/Dapr.Actors/Client/ActorProxyFactory.cs 47.61% <10.00%> (-35.72%) ⬇️
src/Dapr.Actors/Runtime/ActorRuntime.cs 75.00% <10.00%> (-9.00%) ⬇️
src/Dapr.Actors/Client/ActorProxyOptions.cs 66.66% <33.33%> (-11.12%) ⬇️

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

@addjuarez addjuarez marked this pull request as ready for review September 22, 2022 21:04
@addjuarez addjuarez requested review from a team as code owners September 22, 2022 21:04
addjuarez and others added 7 commits September 26, 2022 17:47
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
* feat: add metadata api
Signed-off-by: saberwang <saberwang@hotmail.com>

* Using HTTP API to get and set dapr metadata
Signed-off-by: saberwang <saberwang@hotmail.com>

* style
Signed-off-by: saberwang <saberwang@hotmail.com>

* using grpc to add metadata api
Signed-off-by: saberwang <saberwang@hotmail.com>

* style
Signed-off-by: saberwang <saberwang@hotmail.com>

Co-authored-by: halspang <70976921+halspang@users.noreply.github.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Comment on lines 77 to 80
/// <summary>
/// Option to use GRPC or HTTP
/// </summary>
public bool useGrpc { get; set; } = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Missing whitespace at the top and public members are capitalized. useGrpc -> UseGrpc.

Comment on lines 72 to 75
.UseGrpcEndpoint(options.GrpcEndpoint)
.UseDaprApiToken(options.DaprApiToken)
.UseGrpcChannelOptions(options.GrpcChannelOptions)
.Build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: These should be indented.

Comment on lines 92 to 95
.UseGrpcEndpoint(options.GrpcEndpoint)
.UseDaprApiToken(options.DaprApiToken)
.UseGrpcChannelOptions(options.GrpcChannelOptions)
.Build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Comment on lines 81 to 84
public Task SaveStateTransactionallyAsync(string actorType, string actorId, string data, CancellationToken cancellationToken = default)
{
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we decide to do this and create a new method instead of just using the gRPC client here?

@@ -75,6 +76,11 @@ HttpRequestMessage RequestFunc()
return stringResponse;
}

public Task SaveStateTransactionallyAsyncGrpc(string actorType, string actorId, List<Autogenerated.TransactionalActorStateOperation> data, CancellationToken cancellationToken = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

As commented above, I don't think we need to distinguish this.

Comment on lines 55 to 59
daprInteractor = new DaprInteractorBuilder()
.UseGrpcEndpoint(options.GrpcEndpoint)
.UseDaprApiToken(options.DaprApiToken)
.UseGrpcChannelOptions(options.GrpcChannelOptions)
.Build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs an indent but I also feel it shouldn't use a builder.

If you do want to use a builder, I think it should take in the options.UseGrpc field and return the appropriate interactor. The benefit of that being an interface is that we don't need to know the actual implementation.

/// <summary>
/// Option to use GRPC or HTTP
/// </summary>
public bool useGrpc { get; set; } = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

useGrpc -> UseGrpc

Comment on lines 83 to 87
if (this.daprInteractor.GetType().Name.Equals("DaprGrpcInteractor")){
await this.DoStateChangesTransactionallyAsyncGrpc(actorType, actorId, stateChanges, cancellationToken);
} else {
await this.DoStateChangesTransactionallyAsyncHttp(actorType, actorId, stateChanges, cancellationToken);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The interface of the interactor makes this unnecessary. Whatever the underlying object is, we'll use its method. So no need to separate them like this.

@@ -24,7 +24,6 @@ namespace Dapr.Actors.Runtime
/// <summary>
/// Represents the details of the timer set on an Actor.
/// </summary>
[Obsolete("This class is an implementation detail of the framework and will be made internal in a future release.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we make this internal? I don't think we did. And if we did, that's a breaking change so we shouldn't just do it. Any reason why you removed this?

}
}

private async Task DoStateChangesTransactionallyAsyncGrpc(string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments, we can remove this.

Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Copy link
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.

How hard would it be to replicate any tests that the DaprHttpInteractor has for the DaprGrpcInteractor?
It would also be good to make a base e2e test for the actors to ensure this works correctly.

}

private async Task DoStateChangesTransactionallyAsync(string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
public async Task DoStateChangesTransactionallyAsyncGrpc(string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
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 still need the Grpc and Http methods here? I thought with the interactors we wouldn't need these anymore.

Copy link
Author

Choose a reason for hiding this comment

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

For this method we do. The interface wants a ActorStateChange objects but grpc requires a proto object here.

/// <summary>
/// Option to use GRPC or HTTP
/// </summary>
public bool UseGrpc { get; set; } = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should default to false otherwise we'll change everyone's actor functionality without them opting into it.

/// <summary>
/// Option to use GRPC or HTTP
/// </summary>
public bool UseGrpc { get; set; } = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, this should be false.

{
UseGrpc = false,
HttpEndpoint = this.HttpEndpoint,
GrpcEndpoint = this.GrpcEndpoint
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 both endpoints?

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
@addjuarez
Copy link
Author

How hard would it be to replicate any tests that the DaprHttpInteractor has for the DaprGrpcInteractor? It would also be good to make a base e2e test for the actors to ensure this works correctly.

I can make e2e tests for the grpcInteractor but the unit tests for grpc are a bit more complex.

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
@@ -75,7 +77,7 @@ HttpRequestMessage RequestFunc()
return stringResponse;
}

public Task SaveStateTransactionallyAsync(string actorType, string actorId, string data, CancellationToken cancellationToken = default)
public Task SaveStateTransactionallyAsync(string actorType, string actorId, string data, CancellationToken cancellationToken = default, List<Autogenerated.TransactionalActorStateOperation> grpcData = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is grpcData used?

Copy link
Author

Choose a reason for hiding this comment

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

Yes the grpcInteractor uses this for its data. It doesnt use the string argument

Comment on lines 98 to 100
public Task DoStateChangesTransactionallyAsync(DaprStateProvider provider, string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
{
return provider.DoStateChangesTransactionallyAsyncHttp(actorType, actorId, stateChanges, cancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we wouldn't need to split them up between http and gRPC anymore.

}

private async Task DoStateChangesTransactionallyAsync(string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
public async Task DoStateChangesTransactionallyAsyncGrpc(string actorType, string actorId, IReadOnlyCollection<ActorStateChange> stateChanges, CancellationToken cancellationToken = default)
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving this logic into the daprGrpcInteractor would remove the need to distinguish between http/grpc right?

addjuarez and others added 3 commits January 9, 2023 12:51
Signed-off-by: addjuarez <addiajuarez@gmail.com>
Signed-off-by: addjuarez <addiajuarez@gmail.com>
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.

Migrate calls to Dapr's sidecar Actor APIS to GRPC
3 participants