-
Notifications
You must be signed in to change notification settings - Fork 798
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
Change to use grpc-dotnet instead of Grpc.Core in C# SDK #3397
Merged
markmandel
merged 15 commits into
googleforgames:main
from
yoshd:change_csharp_grpc_lib
Sep 28, 2023
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7680635
Add conformance test implementation for C# SDK
yoshd a074e0e
add successful log
yoshd ff7e37e
Fix SetLabel/SetAnnotation tests
yoshd 685a5df
Remove garbage
yoshd 513cf29
Rename sdk test file
yoshd efb936f
Fix SetLabel test
yoshd 870976b
Merge branch 'main' into add_csharp_conformance_test
yoshd e484d1c
Change to use grpc-dotnet instead of Grpc.Core
yoshd 564d1ef
Remove Grpc.Core.Testing
yoshd f2d74f8
Merge branch 'main' into change_csharp_grpc_lib
yoshd d1660e0
Move proto file output
yoshd c287767
Fix proto file output destination for C#
yoshd 3e57dc9
Merge branch 'main' into change_csharp_grpc_lib
yoshd 2f2204b
Merge branch 'main' into change_csharp_grpc_lib
yoshd 6ab40e6
Merge branch 'main' into change_csharp_grpc_lib
markmandel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,12 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
using Agones.Dev.Sdk; | ||
using Grpc.Core; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The namespace |
||
using Grpc.Net.Client; | ||
|
||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Agones.Test")] | ||
namespace Agones | ||
|
@@ -33,8 +34,8 @@ public sealed class AgonesSDK : IAgonesSDK | |
|
||
internal SDK.SDKClient client; | ||
internal readonly Alpha alpha; | ||
internal readonly Channel channel; | ||
internal AsyncClientStreamingCall<Empty, Empty> healthStream; | ||
internal readonly GrpcChannel channel; | ||
internal AsyncClientStreamingCall<Empty,Empty> healthStream; | ||
internal readonly CancellationTokenSource cts; | ||
internal readonly bool ownsCts; | ||
internal CancellationToken ctoken; | ||
|
@@ -74,7 +75,10 @@ public AgonesSDK( | |
} | ||
|
||
ctoken = cts.Token; | ||
channel = new Channel(Host, Port, ChannelCredentials.Insecure); | ||
channel = GrpcChannel.ForAddress( | ||
$"http://{Host}:{Port}" | ||
); | ||
|
||
client = sdkClient ?? new SDK.SDKClient(channel); | ||
alpha = new Alpha(channel, requestTimeoutSec, cancellationTokenSource, logger); | ||
} | ||
|
@@ -91,16 +95,11 @@ public IAgonesAlphaSDK Alpha() | |
/// <summary> | ||
/// Connect the underlying gRPC channel. | ||
/// </summary> | ||
/// <returns>True if successful</returns> | ||
/// <returns>Always return true</returns> | ||
[Obsolete("No need to call ConnectAsync anymore")] | ||
public async Task<bool> ConnectAsync() | ||
{ | ||
await channel.ConnectAsync(DateTime.UtcNow.AddSeconds(RequestTimeoutSec)); | ||
if (channel.State == ChannelState.Ready) | ||
{ | ||
return true; | ||
} | ||
LogError($"Could not connect to the sidecar at {Host}:{Port}. Exited with connection state: {channel.State}."); | ||
return false; | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -387,6 +386,8 @@ public void Dispose() | |
cts.Dispose(); | ||
} | ||
|
||
channel.Dispose(); | ||
|
||
// Since we don't provide any facility to unregister a WatchGameServer callback, set the event to null to | ||
// clear its underlying invocation list, so we don't keep holding references to objects that would prevent | ||
// them to be GC'd in case we don't go out of scope. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Curious - does it have to be in
sdk/proto
? Also wondering if we should update the .gitignore so it doesn't ignore./proto
folder anymore, since the csharp code is now generated at build time.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.
It doesn't necessarily need to be in
sdk/proto
, but since only the C# SDK uses this specially rewritten.proto
files, I decided to output it there.Currently it doesn't seem to be ignored by .gitignore, but is there likely to be a problem?
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.
Sorry, I wasn't clear, lemme explain this another way:
Shall we put the proto files in
/go/src/agones.dev/agones/sdks/csharp/proto
(thesdk
seems redundant), which is the same as how we do the same thing with rust https://github.com/googleforgames/agones/tree/main/sdks/rust/protoThere 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.
I see, I understand!
I did it that way at first, but the actual C# SDK implementation was in
sdks/csharp/sdk
.For this reason, although it is redundant, I thought it would be better to put them in the same hierarchy.
WDYT?
https://github.com/googleforgames/agones/tree/main/sdks/csharp/sdk
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.
oooooh! So it is!
I guess what's the usual convention for csharp? Are the protos usually kept with the source code (i.e.
sdk
) or kept separately (i.e. one level up)?We should probably just do whatever the regular convention is - I don't actually mind either way.
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.
Normally, the proto file is often shared between the server and client, so I think it should be placed in a separate folder from the source code.
(However, this time it seems to be different in that a proto file exclusively for the C# SDK is generated.)
That said, I agree that it would be better to have a structure similar to most projects.
Now let's modify it to output to
sdks/csharp
.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.
Sorry, wasn't sure I 100% understood.
I think we're saying to leave it at
/go/src/agones.dev/agones/sdks/csharp/sdk/proto
yes? or no?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.
Sorry, that's no.
I modify it to
csharp/sdk
.And I just committed it.
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.
Got it! That works for me!