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

Implements SDK callback for GameServer updates #316

Merged
merged 1 commit into from
Aug 10, 2018

Conversation

markmandel
Copy link
Member

This implements the gRPC system to send messages up to a unidirectional
stream from the sdk-server to the SDK.

This has been implemented in the Go, C++ and REST SDK.

Closes #277

@markmandel markmandel added kind/feature New features for Agones area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc labels Aug 8, 2018
@markmandel markmandel added this to the 0.4.0 milestone Aug 8, 2018
sdks/go/sdk.go Outdated
s.watchCallbacks = append(s.watchCallbacks, f)
var err error

s.watchOnce.Do(func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

@enocom I've love to get your take on this approach. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using a sync.Once, it might be easier to have a RegisterCallback method to register a new callback. Then WatchGameServer can run forever invoking the callbacks.

Presently, there's a data race between the call to append above and reading the callbacks in the goroutine with range below. If you split out the two concerns, you can lock around the slice of callbacks, taking out the lock when appending or reading from the slice, and then releasing it afterwords.

Be careful about locking around the callback, though, as there is a chance the callback might never finish. You might consider passing a content.Context into the callback to provide a mechanism for cancelling the work and releasing the lock in failure cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reading all this, and your comments I think I've got too fancy with this.

I think I'll take an approach that is similar to what I did with the C++ (although non-blocking). Each call to WatchGameServer is it's own call to the gRPC service, with it's own singular function callback - that will make things far simpler to run and test, rather than managing sets of function callbacks and the potential issues therein.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -59,6 +59,18 @@ namespace agones {
return stub->GetGameServer(context, request, response);
}

grpc::Status SDK::WatchGameServer(const std::function<void(stable::agones::dev::sdk::GameServer)> callback) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@Kuqd @EricFortin My C++ is terrible - I hope I haven't done anything totally silly here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks good to me, may be @victor-prodan can confirm ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, looks fine to me as well.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: cd74a9a4-49c7-4773-bbee-2a8245e0ca5b

The following development artifacts have been built, and will exist for the next 30 days:

This implements the gRPC system to send messages up to a unidirectional
stream from the sdk-server to the SDK.

This has been implemented in the Go, C++ and REST SDK.

Closes googleforgames#277
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: d1fcc50e-e6db-4f74-8343-0d840928a255

The following development artifacts have been built, and will exist for the next 30 days:

(experimental) To install this version:

  • git fetch upstream pull/316/head:pr_316 && git checkout pr_316 - helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=0.4.0-6b7c090`

Copy link
Collaborator

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

I was wondering why there is multiple streams, then I saw your discussion, LTGM

@markmandel markmandel merged commit 3c7304d into googleforgames:master Aug 10, 2018
@markmandel markmandel deleted the feature/gs-callback branch August 10, 2018 16:15
return errors.Wrap(err, "could not watch gameserver")
}

go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@markmandel Should this goroutine ever exit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes - on EOF of the gRPC stream. Basically when the stream closes on the sdk sidecar server shutdown.

I could have written the if statement much cleaner looking at it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc kind/feature New features for Agones
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants