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

SDKServer Player Tracking implementation #1507

Merged

Conversation

markmandel
Copy link
Member

What type of PR is this?

/kind breaking
/kind bug
/kind cleanup
/kind documentation

/kind feature

/kind hotfix

What this PR does / Why we need it:
Implementation of the SDK gRPC Server, with accompanying unit tests.

Which issue(s) this PR fixes:

Work on #1033

Special notes for your reviewer:

None.

@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 May 1, 2020
@markmandel markmandel requested review from aLekSer and pooneh-m and removed request for EricFortin May 1, 2020 17:12
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 059fb6fa-d728-4f14-b1c7-903a3dc95ada

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

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1507/head:pr_1507 && git checkout pr_1507
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.6.0-35c17f9

assert.False(t, ok.Bool, "no player connected yet")

// sdk value should always be correct, even if we send more than one update per second.
for i := 0; i < 3; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably it would be easier to understand why 3 (if I got it right):

Suggested change
for i := 0; i < 3; i++ {
for i := 0; i < capacity; i++ {

}
count, err = sc.GetPlayerCount(context.Background(), e)
assert.NoError(t, err)
assert.Equal(t, int64(3), count.Count)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above?

Suggested change
assert.Equal(t, int64(3), count.Count)
assert.Equal(t, capacity, count.Count)

// on an update, confirm that the update hits the K8s api, only once
select {
case value := <-updated:
assert.Equal(t, int64(3), value.Count)
Copy link
Collaborator

Choose a reason for hiding this comment

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

here also

Suggested change
assert.Equal(t, int64(3), value.Count)
assert.Equal(t, capacity, value.Count)


// sdk value should always be correct, even if we send more than one update per second.
// let's leave one player behind
for i := 0; i < 2; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for i := 0; i < 2; i++ {
for i := 0; i < capacity-1; i++ {

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I like that. Nice.

id := &alpha.PlayerID{PlayerID: token}
ok, err := sc.PlayerDisconnect(context.Background(), id)
assert.NoError(t, err)
assert.True(t, ok.Bool, "Player "+token+" should be disconnected")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be a bit easier to read

Suggested change
assert.True(t, ok.Bool, "Player "+token+" should be disconnected")
assert.True(t, ok.Bool, "Player %s should be disconnected", token)

@@ -547,35 +555,108 @@ func (s *SDKServer) stopReserveTimer() {
// [Stage:Alpha]
// [FeatureFlag:PlayerTracking]
func (s *SDKServer) PlayerConnect(ctx context.Context, id *alpha.PlayerID) (*alpha.Bool, error) {
panic("implement me")
if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return nil, errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be something like:

Suggested change
return nil, errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")
return nil, errors.New(fmt.Sprintf("feature gate '%s' is not enabled", runtime.FeaturePlayerTracking))

Copy link
Member Author

Choose a reason for hiding this comment

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

We've currently got this code all through localsdk.go as well. Should I change both?

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, this should errors.Errorf(...) - which is much better. I'll make the change here, and come back around to localsdk.go in a later PR.

}

if int64(len(s.gsConnectedPlayers)) >= s.gsPlayerCapacity {
return &alpha.Bool{}, errors.New("Players are already at capacity")
Copy link
Collaborator

Choose a reason for hiding this comment

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

lower case for errors
https://github.com/golang/go/wiki/CodeReviewComments#error-strings

Suggested change
return &alpha.Bool{}, errors.New("Players are already at capacity")
return &alpha.Bool{}, errors.New("players are already at capacity")

if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return nil, errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")
}
s.logger.WithField("PlayerId", id).Debug("Player Disconnected")
Copy link
Collaborator

@aLekSer aLekSer May 1, 2020

Choose a reason for hiding this comment

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

Not sure if previous version parse pointers in a correct way.

Suggested change
s.logger.WithField("PlayerId", id).Debug("Player Disconnected")
s.logger.WithField("PlayerId", id.PlayerID).Debug("Player Disconnected")

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, excellent point.

if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")
}
s.logger.WithField("playerIDs", s.gsConnectedPlayers).Debug("updating connected players")
Copy link
Collaborator

@aLekSer aLekSer May 1, 2020

Choose a reason for hiding this comment

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

Might go also after lock.

Suggested change
s.logger.WithField("playerIDs", s.gsConnectedPlayers).Debug("updating connected players")
s.gsUpdateMutex.RLock()
s.logger.WithField("playerIDs", s.gsConnectedPlayers).Debug("updating connected players")

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Collaborator

@aLekSer aLekSer left a comment

Choose a reason for hiding this comment

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

Overall is great. Left some points - potential issues.

@markmandel markmandel force-pushed the feature/sdk-server-tracking branch from 35c17f9 to 79dc130 Compare May 4, 2020 22:28
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: cbd43784-331a-42c9-8f63-96ab7698143b

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

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1507/head:pr_1507 && git checkout pr_1507
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.6.0-79dc130

if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return nil, errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking)
}
s.logger.WithField("PlayerId", id).Debug("Player Connected")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry Mark, one more

Suggested change
s.logger.WithField("PlayerId", id).Debug("Player Connected")
s.logger.WithField("PlayerId", id.PlayerID).Debug("Player Connected")

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Applying now!

Copy link
Collaborator

@aLekSer aLekSer left a comment

Choose a reason for hiding this comment

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

Thanks for applying all the comments. Please apply one more log improvement (nit).

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aLekSer, markmandel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Implementation of the SDK gRPC Server, with accompanying unit tests.

Work on googleforgames#1033
markmandel added a commit to markmandel/agones that referenced this pull request May 6, 2020
Cleanup the remainder
`errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")`
to be being
`errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking)`,
which is much nicer.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 6, 2020
Includes implementations and unit tests for PlayerConnect,
PlayerDisconnect, GetPlayerCount, IsPlayerConnected and
GetConnectedPlayers.

Conformance tests will come in the next PR.

Work on googleforgames#1507
markmandel added a commit that referenced this pull request May 6, 2020
Cleanup the remainder
`errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")`
to be being
`errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking)`,
which is much nicer.

Work on #1507
markmandel added a commit to markmandel/agones that referenced this pull request May 6, 2020
Includes implementations and unit tests for PlayerConnect,
PlayerDisconnect, GetPlayerCount, IsPlayerConnected and
GetConnectedPlayers.

Conformance tests will come in the next PR.

Work on googleforgames#1507
markmandel added a commit that referenced this pull request May 7, 2020
Includes implementations and unit tests for PlayerConnect,
PlayerDisconnect, GetPlayerCount, IsPlayerConnected and
GetConnectedPlayers.

Conformance tests will come in the next PR.

Work on #1507

Co-authored-by: Alexander Apalikov <alexander.apalikov@globant.com>
markmandel added a commit to markmandel/agones that referenced this pull request May 7, 2020
Conformance tests for the Go SDK.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 7, 2020
Conformance tests for the Go SDK.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 7, 2020
Conformance tests for the Go SDK.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 10, 2020
Conformance tests for the Go SDK.

Work on googleforgames#1507
roberthbailey pushed a commit that referenced this pull request May 10, 2020
Conformance tests for the Go SDK.

Work on #1507
markmandel added a commit to markmandel/agones that referenced this pull request May 11, 2020
Conformance tests for the REST API.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 12, 2020
Conformance tests for the REST API.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 12, 2020
Conformance tests for the REST API.

Work on googleforgames#1507
roberthbailey pushed a commit that referenced this pull request May 12, 2020
Conformance tests for the REST API.

Work on #1507
markmandel added a commit to markmandel/agones that referenced this pull request May 13, 2020
Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 13, 2020
Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

Work on googleforgames#1507
markmandel added a commit to markmandel/agones that referenced this pull request May 13, 2020
Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

Work on googleforgames#1507
markmandel added a commit that referenced this pull request May 14, 2020
* E2E Tests for GameServer Player Tracking

Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

Work on #1507
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Implementation of the SDK gRPC Server, with accompanying unit tests.

Work on googleforgames#1033
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Cleanup the remainder
`errors.New(string(runtime.FeaturePlayerTracking) + " not enabled")`
to be being
`errors.Errorf("%s not enabled", runtime.FeaturePlayerTracking)`,
which is much nicer.

Work on googleforgames#1507
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
)

Includes implementations and unit tests for PlayerConnect,
PlayerDisconnect, GetPlayerCount, IsPlayerConnected and
GetConnectedPlayers.

Conformance tests will come in the next PR.

Work on googleforgames#1507

Co-authored-by: Alexander Apalikov <alexander.apalikov@globant.com>
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
* E2E Tests for GameServer Player Tracking

Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

Work on googleforgames#1507
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
* E2E Tests for GameServer Player Tracking

Updated the udp-simple example to accept various player tracking
commands, and also implemented e2e tests to test it working on a
singular GameServer instance.

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

Successfully merging this pull request may close these issues.

None yet

4 participants