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

refactor simple game server #3817

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ashutosji
Copy link
Contributor

What type of PR is this? This is a refactor of existing code of simple game server present in examples folder.

Uncomment only one /kind <> line, press enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind hotfix
/kind release

What this PR does / Why we need it:

Which issue(s) this PR fixes: #3813

Closes #3813

Special notes for your reviewer:

@github-actions github-actions bot added kind/cleanup Refactoring code, fixing up documentation, etc size/XL labels May 10, 2024
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 72700498-8b76-4a75-8bea-5879ed4cd3a9

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/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.41.0-dev-8b83ca3-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Approach looks good! Some nits, and some other ideas to try.

@@ -0,0 +1,331 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Apache licence header please.

examples/simple-game-server/response-handler.go Outdated Show resolved Hide resolved
examples/simple-game-server/response-handler.go Outdated Show resolved Hide resolved
Comment on lines 16 to 21
func ready(s *sdk.SDK) {
err := s.Ready()
if err != nil {
log.Fatalf("Could not send ready message")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

So I am noting that we have a pattern that looks like the above quite a bit - execute a function on the SDK, if it fails, log.Fatalf(...)

Not 100% sure how useful this would be - as it may only apply in a few places, but something like:

func runSDK(f func() err, failMsg string) {
   if err := f(); err != nil {
      log.Fatalf(failMsg + ": %v", err)
   }
}

Then this function could pretty much go away and you could do inline in handleReady

func handleReady(s *sdk.SDK, parts []string, _ ...context.CancelFunc) (response string, addACK bool, responseError error) {
   runSDK(func() err { return s.Ready() }, "Could not send ready message")
}

Since it's a closure, it could also handle anything taking in a series of arguments.

Where it goes fall over is if a SDK function returns several return values -- so it may not be worth it. But figured I'd show you my general idea, and see if it made sense -- save writing two functions for each command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I am noting that we have a pattern that looks like the above quite a bit - execute a function on the SDK, if it fails, log.Fatalf(...)

Not 100% sure how useful this would be - as it may only apply in a few places, but something like:

func runSDK(f func() err, failMsg string) {
   if err := f(); err != nil {
      log.Fatalf(failMsg + ": %v", err)
   }
}

Then this function could pretty much go away and you could do inline in handleReady

func handleReady(s *sdk.SDK, parts []string, _ ...context.CancelFunc) (response string, addACK bool, responseError error) {
   runSDK(func() err { return s.Ready() }, "Could not send ready message")
}

Since it's a closure, it could also handle anything taking in a series of arguments.

Where it goes fall over is if a SDK function returns several return values -- so it may not be worth it. But figured I'd show you my general idea, and see if it made sense -- save writing two functions for each command.

Ahan! I got it. I have added all the sdk functions inside the handlers.

@@ -0,0 +1,371 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

rename suggestion: handlers.go

@@ -0,0 +1,331 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Rename suggestions : sdk.go (don't love it) - but helpers.go is a bit ambiguous. sdk.go gives some idea that this is where the sdk gets called.

Either that or pull it all into handers.go and put the SDK command under each handler? (or if need be, make it inline?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rename suggestions : sdk.go (don't love it) - but helpers.go is a bit ambiguous. sdk.go gives some idea that this is where the sdk gets called.

Either that or pull it all into handers.go and put the SDK command under each handler? (or if need be, make it inline?)

I have pulled everything inside handlers.go. sdk.go isn't required.
Thank you so much for your guidance.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 8b83ca3 to 7a03c71 Compare May 14, 2024 11:00
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: c54e02bb-849e-45cd-83ba-9885bf4fa113

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/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.41.0-dev-7a03c71-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Looks good!

Will need an increment on the version number:

Will also need to update all the references to simple-game-server - but may want to test locally with some e2e tests before updating everything as we'll need to push a new version to prod.

@@ -0,0 +1,581 @@
// Copyright 2020 Google LLC All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2020 Google LLC All Rights Reserved.
// Copyright 2024 Google LLC All Rights Reserved.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 7a03c71 to 253638e Compare May 21, 2024 09:18
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@ashutosji
Copy link
Contributor Author

Looks good!

Will need an increment on the version number:

Will also need to update all the references to simple-game-server - but may want to test locally with some e2e tests before updating everything as we'll need to push a new version to prod.

I had tested few functionalities mentioned in this file: https://github.com/googleforgames/agones/blob/main/test/e2e/gameserver_test.go#L717.
Also, I had ran the command mentioned here: https://github.com/googleforgames/agones/blob/main/build/README.md#make-test-e2e and https://github.com/googleforgames/agones/blob/main/build/README.md#make-test-go.

Everything works perfectly to me. I was communicated with gameserver (https://agones.dev/site/docs/getting-started/create-gameserver/#3-connect-to-the-gameserver) the response was as expected.

Please, let me know what else i am missing for e2e test.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 2eb3c057-1ad5-4c69-9e20-40a830f1b884

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 253638e to 7c8810f Compare May 21, 2024 10:52
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: bdcd983b-76c0-4aba-be39-cbf32599be5f

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji
Copy link
Contributor Author

Hi @markmandel,

Step #1 - "e2e-feature-gates":     framework.go:346: 
Step #1 - "e2e-feature-gates":         	Error Trace:	/go/src/agones.dev/agones/test/e2e/framework/framework.go:346
Step #1 - "e2e-feature-gates":         	            				/go/src/agones.dev/agones/test/e2e/allocator_test.go:77
Step #1 - "e2e-feature-gates":         	Error:      	Received unexpected error:
Step #1 - "e2e-feature-gates":         	            	context deadline exceeded
Step #1 - "e2e-feature-gates":         	Test:       	TestAllocatorWithDeprecatedRequired
Step #1 - "e2e-feature-gates":         	Messages:   	error waiting for fleet condition on fleet: simple-fleet-1.052xsd
Step #1 - "e2e-feature-gates": --- FAIL: TestAllocatorWithDeprecatedRequired (302.54s)
Step #1 - "e2e-feature-gates": FAIL test/e2e.TestAllocatorWithDeprecatedRequired (302.54s)

Could you please guide why this is failing. There are other functions also failing in allocator_test.go file.
I am not getting why it is failing.

@igooch
Copy link
Collaborator

igooch commented May 21, 2024

Could you please guide why this is failing. There are other functions also failing in allocator_test.go file. I am not getting why it is failing.

It's possible it's failing because the simple game server image 0.33 is not in the Agones artifact registry yet. You can test if that's the issue locally by pushing the simple game server image to your dev project's artifact registry https://github.com/googleforgames/agones/blob/main/examples/simple-game-server/Makefile and temporarily changing the image to your repo image

viper.SetDefault(gsimageFlag, "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.32")
and running the tests on your cluster.

@markmandel
Copy link
Member

As part of this PR, try out the approach(es) in #3836 and see if they work for you 👍🏻

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 7c8810f to 636f807 Compare May 31, 2024 10:27
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: ded8d76c-7d0f-4290-bf8e-6b840b5f906b

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 636f807 to 3ee108f Compare May 31, 2024 10:45
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 93ea63f6-853d-4104-a5af-6fa11f8b1d70

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@@ -64,7 +64,7 @@ KIND_PROFILE ?= agones
KIND_CONTAINER_NAME=$(KIND_PROFILE)-control-plane

# Game Server image to use while doing end-to-end tests
GS_TEST_IMAGE ?= us-docker.pkg.dev/agones-images/examples/simple-game-server:0.32
GS_TEST_IMAGE ?= us-central1-docker.pkg.dev/agones-ashutoshnsingh/example/simple-game-server:0.33-dev-linux-amd64
Copy link
Member

Choose a reason for hiding this comment

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

I expect this won't work, since the agones-images project doesn't have access to your artifact registry.

You could make it public if yo u desired though 😄 at least temporarily.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 3ee108f to e2f17f4 Compare June 3, 2024 10:51
Copy link

github-actions bot commented Jun 3, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: cbe7023a-7c96-4571-870d-a23ed4285820

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Refactoring code, fixing up documentation, etc size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor simple-game-server
4 participants