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

agones-{extensions,allocator}: Make servers context aware #3845

Merged
merged 6 commits into from
Jul 12, 2024

Conversation

zmerlynn
Copy link
Collaborator

@zmerlynn zmerlynn commented May 31, 2024

  • adds an httpserver utility package to handle the Run function that controller/extensions use. Make that context aware using the same method as https.Run:
    go func() {
    <-ctx.Done()
    s.tls.Close() // nolint: errcheck,gosec
    }()
  • also plumbs context-awareness through the allocator run{Mux,REST,GRPC} functions.
  • adds a gRPC health server to the allocator, calls .Shutdown() on it during graceful termination - this seems to push the client off correctly.

Along the way, basically re-wrote the TestAllocatorAfterDeleteReplica test:

  • moved the GetAllocatorClient up because it's fairly disruptive (new certs, etc.), so I wanted the pod stability checks to happen after
  • changed agones-allocator stability checks to just grab the Deployment and wait for Replicas != AvailableReplicas.
  • changed the test to actually disrupt the Pods in the middle of the test (vs before it just nukes the pods then starts the test.

Tested with e2e in a loop.

Towards #3853

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: f71cd44c-de3c-458c-9dd6-aa9f3dd9b3ee

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

@zmerlynn
Copy link
Collaborator Author

Hmm, upon further testing this still has a minor flake. Let me play with it a bit more, moving to draft.

@zmerlynn zmerlynn marked this pull request as draft May 31, 2024 16:25
@github-actions github-actions bot added the size/L label Jun 5, 2024
@zmerlynn zmerlynn marked this pull request as ready for review June 5, 2024 18:05
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 6355c010-ac46-4c04-92cf-5fee63fbdc1f

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

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: cb48cb0a-06e7-485a-87ca-f0a79097eb43

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/3845/head:pr_3845 && git checkout pr_3845
  • 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.42.0-dev-2d2e2e5-amd64

@@ -150,7 +150,7 @@ func main() {
agonesInformerFactory := externalversions.NewSharedInformerFactory(agonesClient, defaultResync)
kubeInformerFactory := informers.NewSharedInformerFactory(kubeClient, defaultResync)

server := &httpServer{}
server := &httpserver.Server{Logger: logger}
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
server := &httpserver.Server{Logger: logger}
server := &http.Server{Logger: logger}

That wouldn't be redundant 😃

cmd/allocator/main.go Outdated Show resolved Hide resolved

// Package httpserver implements an http server that conforms to the
// controller runner interface.
package httpserver
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
package httpserver
package http

I'd be tempted to make the package http since we also have a https - not sure the server part is required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I really didn't want to shadow a super commonly important base library. Calling this http would result in it getting imported as agoneshttp or something pretty often, since I would also probably not rename base http.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: ec4f214a-d587-406d-8ee0-20be8a5a2b15

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/3845/head:pr_3845 && git checkout pr_3845
  • 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.42.0-dev-acc03f2-amd64


go func() {
go func() {
<-ctx.Done()
grpcServer.Stop()
Copy link
Member

Choose a reason for hiding this comment

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

Should this be: https://pkg.go.dev/google.golang.org/grpc#Server.GracefulStop (or maybe used in lieu of a lot of this code?)

Which might help with your multi-context issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went back and forth on this, and I have a version in a branch where I did exactly that. It made things worse.

Let me just go back to the drawing board here, but I think it may involve rewriting a lot of the handling basically everywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But no, it doesn't solve the two-context issue. The problem is that here (and in httpserver/https), we use a context to signal shutdown, but the service handler still needs a forward context to get work done to shut down. Let me see if I can just rework the listen handlers more.

Copy link
Member

@markmandel markmandel Jun 14, 2024

Choose a reason for hiding this comment

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

Yeah I see your point. I think you are right that we'll want two contexts, but what we could do is something akin to:

<- listenerCtx.Done()
// graceful shutdown both the http and grpc listeners. 
grpcServer.GracefulStop()
server.Shutdown()
cancelInfrormer() // cancel the worker + Informer context, since now we know we aren't accepting any more connections.

This might require pulling the grpc + http listeners into a larger struct that has a Run(ctx) operation on it, and stops when the ctx is <- ctx.Done(), to provide a larger data structure to operate on (and then it could take a context, and manage it's own context for the workers and informers).

Did that make sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, we could do something similar to the runner slices and have shutdown slices, perhaps?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, we could do something similar to the runner slices and have shutdown slices, perhaps?

Seems like you are rebuilding Contexts 😄

cmd/allocator/main.go Outdated Show resolved Hide resolved
…ealth check

* adds an `httpserver` utility package to handle the `Run` function
that controller/extensions use. Make that context aware using the same
method as https.Run:
https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130

* also plumbs context-awareness through the allocator
run{Mux,REST,GRPC} functions.

* adds a gRPC health server to the allocator, calls .Shutdown() on it
during graceful termination - this seems to push the client off correctly.

Tested with e2e in a loop.

Towards googleforgames#3853
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 4e70c09c-b912-48d4-91fb-6af56029445b

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/3845/head:pr_3845 && git checkout pr_3845
  • 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.42.0-dev-9d246a3-amd64

// and a cascading graceful shutdown instead of multiple contexts and sleeps.
<-listenCtx.Done()
logger.Infof("Listen context cancelled")
time.Sleep(5 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this is because we don't actually know that the gRPC/HTTP servers have gracefully shut down yet, so we just wait for a bit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah .. fully knowing they're done takes a bit more plumbing.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 6e64e3f3-f0bb-4499-8566-4b744130ea83

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/3845/head:pr_3845 && git checkout pr_3845
  • 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.42.0-dev-2f06434-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.

Good enough 😁 thanks for all the new plumbing!

@markmandel markmandel enabled auto-merge (squash) July 11, 2024 23:40
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 841fae19-753d-41d2-a8c5-4b3b68f7ad80

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/3845/head:pr_3845 && git checkout pr_3845
  • 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.42.0-dev-1006b0b-amd64

@markmandel markmandel merged commit a74a86f into googleforgames:main Jul 12, 2024
4 checks passed
indexjoseph pushed a commit to indexjoseph/agones that referenced this pull request Jul 12, 2024
…ames#3845)

* agones-{extensions,allocator}: Make servers context aware, add gRPC health check

* adds an `httpserver` utility package to handle the `Run` function
that controller/extensions use. Make that context aware using the same
method as https.Run:
https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130

* also plumbs context-awareness through the allocator
run{Mux,REST,GRPC} functions.

* adds a gRPC health server to the allocator, calls .Shutdown() on it
during graceful termination - this seems to push the client off correctly.

Tested with e2e in a loop.

Towards googleforgames#3853

* Move from context.Background()

* Use Shutdown/GracefulStop

* Relax deadline slightly (original had none), also delete pod from GetAllocatorClient
indexjoseph pushed a commit to indexjoseph/agones that referenced this pull request Jul 12, 2024
… apis (googleforgames#3900)

* Adds a command to generate the zz_generated.deepcopy.go files for the apis
* Combines CRD client and deepcopy code generation into one script
* Updates boilerplate headers to 2024
* Generated code from gen-all-sdk-grpc
* Small update to template comment

agones-{extensions,allocator}: Make servers context aware (googleforgames#3845)

* agones-{extensions,allocator}: Make servers context aware, add gRPC health check

* adds an `httpserver` utility package to handle the `Run` function
that controller/extensions use. Make that context aware using the same
method as https.Run:
https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130

* also plumbs context-awareness through the allocator
run{Mux,REST,GRPC} functions.

* adds a gRPC health server to the allocator, calls .Shutdown() on it
during graceful termination - this seems to push the client off correctly.

Tested with e2e in a loop.

Towards googleforgames#3853

* Move from context.Background()

* Use Shutdown/GracefulStop

* Relax deadline slightly (original had none), also delete pod from GetAllocatorClient

Update Slack invite link (googleforgames#3896)

Looks like the Slack invite link expired somewhere along the way, so
this is a new, shiny updated one!
indexjoseph pushed a commit to indexjoseph/agones that referenced this pull request Jul 12, 2024
… apis (googleforgames#3900)

* Adds a command to generate the zz_generated.deepcopy.go files for the apis
* Combines CRD client and deepcopy code generation into one script
* Updates boilerplate headers to 2024
* Generated code from gen-all-sdk-grpc
* Small update to template comment

agones-{extensions,allocator}: Make servers context aware (googleforgames#3845)

* agones-{extensions,allocator}: Make servers context aware, add gRPC health check

* adds an `httpserver` utility package to handle the `Run` function
that controller/extensions use. Make that context aware using the same
method as https.Run:
https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130

* also plumbs context-awareness through the allocator
run{Mux,REST,GRPC} functions.

* adds a gRPC health server to the allocator, calls .Shutdown() on it
during graceful termination - this seems to push the client off correctly.

Tested with e2e in a loop.

Towards googleforgames#3853

* Move from context.Background()

* Use Shutdown/GracefulStop

* Relax deadline slightly (original had none), also delete pod from GetAllocatorClient

Update Slack invite link (googleforgames#3896)

Looks like the Slack invite link expired somewhere along the way, so
this is a new, shiny updated one!
indexjoseph pushed a commit to indexjoseph/agones that referenced this pull request Jul 12, 2024
… apis (googleforgames#3900)

* Adds a command to generate the zz_generated.deepcopy.go files for the apis
* Combines CRD client and deepcopy code generation into one script
* Updates boilerplate headers to 2024
* Generated code from gen-all-sdk-grpc
* Small update to template comment

agones-{extensions,allocator}: Make servers context aware (googleforgames#3845)

* agones-{extensions,allocator}: Make servers context aware, add gRPC health check

* adds an `httpserver` utility package to handle the `Run` function
that controller/extensions use. Make that context aware using the same
method as https.Run:
https://github.com/googleforgames/agones/blob/dfa414e5e4da37798833bbf8c33919acb5f3c2ea/pkg/util/https/server.go#L127-L130

* also plumbs context-awareness through the allocator
run{Mux,REST,GRPC} functions.

* adds a gRPC health server to the allocator, calls .Shutdown() on it
during graceful termination - this seems to push the client off correctly.

Tested with e2e in a loop.

Towards googleforgames#3853

* Move from context.Background()

* Use Shutdown/GracefulStop

* Relax deadline slightly (original had none), also delete pod from GetAllocatorClient

Update Slack invite link (googleforgames#3896)

Looks like the Slack invite link expired somewhere along the way, so
this is a new, shiny updated one!
@kamaljeeti kamaljeeti added kind/bug These are bugs. and removed kind/other labels Jul 15, 2024
spiceratops referenced this pull request in spiceratops/k8s-gitops Jul 23, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [agones](https://agones.dev)
([source](https://togithub.com/googleforgames/agones)) | minor |
`1.41.0` -> `1.42.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>googleforgames/agones (agones)</summary>

###
[`v1.42.0`](https://togithub.com/googleforgames/agones/blob/HEAD/CHANGELOG.md#v1420-2024-07-16)

[Compare
Source](https://togithub.com/googleforgames/agones/compare/v1.41.0...v1.42.0)

[Full
Changelog](https://togithub.com/googleforgames/agones/compare/v1.41.0...v1.42.0)

**Breaking changes:**

- Update csharp.md to indicate ConnectAsync is deprecated by
[@&#8203;aallbrig](https://togithub.com/aallbrig) in
[https://github.com/googleforgames/agones/pull/3866](https://togithub.com/googleforgames/agones/pull/3866)

**Implemented enhancements:**

- Add security context to Agones containers by
[@&#8203;peterzhongyi](https://togithub.com/peterzhongyi) in
[https://github.com/googleforgames/agones/pull/3856](https://togithub.com/googleforgames/agones/pull/3856)
- Add Security Context to game server sidecar by
[@&#8203;peterzhongyi](https://togithub.com/peterzhongyi) in
[https://github.com/googleforgames/agones/pull/3869](https://togithub.com/googleforgames/agones/pull/3869)
- Drop CountsAndLists Data from the Fleet and Game Server Set When the
Flag is False by [@&#8203;igooch](https://togithub.com/igooch) in
[https://github.com/googleforgames/agones/pull/3881](https://togithub.com/googleforgames/agones/pull/3881)
- Adds tests to confirm that Fleet, Fleet Autoscaler, and Fleet
Allocation apply defaults code is idempotent by
[@&#8203;igooch](https://togithub.com/igooch) in
[https://github.com/googleforgames/agones/pull/3888](https://togithub.com/googleforgames/agones/pull/3888)
- feat: Add CRD Changes and Feature Flag for chain policy by
[@&#8203;indexjoseph](https://togithub.com/indexjoseph) in
[https://github.com/googleforgames/agones/pull/3880](https://togithub.com/googleforgames/agones/pull/3880)

**Fixed bugs:**

- sdk-server expects SDK_LOG_LEVEL by
[@&#8203;KAllan357](https://togithub.com/KAllan357) in
[https://github.com/googleforgames/agones/pull/3858](https://togithub.com/googleforgames/agones/pull/3858)
- this will resolve From/layer extraction issue on ltsc2019 in examples
by [@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3873](https://togithub.com/googleforgames/agones/pull/3873)
- featuregate: adds validation if PortPolicyNone is not enabled by
[@&#8203;daniellee](https://togithub.com/daniellee) in
[https://github.com/googleforgames/agones/pull/3871](https://togithub.com/googleforgames/agones/pull/3871)
- added local as default for registry when registry is not specified by
[@&#8203;kamaljeeti](https://togithub.com/kamaljeeti) in
[https://github.com/googleforgames/agones/pull/3876](https://togithub.com/googleforgames/agones/pull/3876)
- Buffer Unity SDK ReceiveData when watching for configuration changes
by [@&#8203;ZeroParticle](https://togithub.com/ZeroParticle) in
[https://github.com/googleforgames/agones/pull/3872](https://togithub.com/googleforgames/agones/pull/3872)
- agones-{extensions,allocator}: Make servers context aware by
[@&#8203;zmerlynn](https://togithub.com/zmerlynn) in
[https://github.com/googleforgames/agones/pull/3845](https://togithub.com/googleforgames/agones/pull/3845)
- added condition for distributed logic by
[@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3877](https://togithub.com/googleforgames/agones/pull/3877)

**Security fixes:**

- Bump [@&#8203;grpc/grpc-js](https://togithub.com/grpc/grpc-js) from
1.10.7 to 1.10.9 in /sdks/nodejs by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/googleforgames/agones/pull/3863](https://togithub.com/googleforgames/agones/pull/3863)

**Other:**

- Preparation for Release v1.42.0 by
[@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3854](https://togithub.com/googleforgames/agones/pull/3854)
- Add helpful note to edit-first-gameserver-go by
[@&#8203;peterzhongyi](https://togithub.com/peterzhongyi) in
[https://github.com/googleforgames/agones/pull/3846](https://togithub.com/googleforgames/agones/pull/3846)
- Moved Passthrough feature description to the correct section in
Feature Stages by [@&#8203;vicentefb](https://togithub.com/vicentefb) in
[https://github.com/googleforgames/agones/pull/3861](https://togithub.com/googleforgames/agones/pull/3861)
- Updated Node.js Page to Reflect that Counters and Lists is Implemented
by [@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3865](https://togithub.com/googleforgames/agones/pull/3865)
- Change Slack channel description from #developers to #development by
[@&#8203;branhoff](https://togithub.com/branhoff) in
[https://github.com/googleforgames/agones/pull/3868](https://togithub.com/googleforgames/agones/pull/3868)
- updated UpdateList documentation for local sdk server and sdk server
by [@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3878](https://togithub.com/googleforgames/agones/pull/3878)
- Add zio-agones to the list of third party client SDKs by
[@&#8203;ghostdogpr](https://togithub.com/ghostdogpr) in
[https://github.com/googleforgames/agones/pull/3875](https://togithub.com/googleforgames/agones/pull/3875)
- refactor simple game server by
[@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3817](https://togithub.com/googleforgames/agones/pull/3817)
- Update Slack invite link by
[@&#8203;markmandel](https://togithub.com/markmandel) in
[https://github.com/googleforgames/agones/pull/3896](https://togithub.com/googleforgames/agones/pull/3896)
- Added cleanup for app-engine services in cloudbuild script by
[@&#8203;kamaljeeti](https://togithub.com/kamaljeeti) in
[https://github.com/googleforgames/agones/pull/3890](https://togithub.com/googleforgames/agones/pull/3890)
- Adds a command to generate the zz_generated.deepcopy.go files for the
apis by [@&#8203;igooch](https://togithub.com/igooch) in
[https://github.com/googleforgames/agones/pull/3900](https://togithub.com/googleforgames/agones/pull/3900)
- update go version to 1.21.12 by
[@&#8203;ashutosji](https://togithub.com/ashutosji) in
[https://github.com/googleforgames/agones/pull/3894](https://togithub.com/googleforgames/agones/pull/3894)

**New Contributors:**

- [@&#8203;KAllan357](https://togithub.com/KAllan357) made their first
contribution in
[https://github.com/googleforgames/agones/pull/3858](https://togithub.com/googleforgames/agones/pull/3858)
- [@&#8203;branhoff](https://togithub.com/branhoff) made their first
contribution in
[https://github.com/googleforgames/agones/pull/3868](https://togithub.com/googleforgames/agones/pull/3868)
- [@&#8203;aallbrig](https://togithub.com/aallbrig) made their first
contribution in
[https://github.com/googleforgames/agones/pull/3866](https://togithub.com/googleforgames/agones/pull/3866)
- [@&#8203;ZeroParticle](https://togithub.com/ZeroParticle) made their
first contribution in
[https://github.com/googleforgames/agones/pull/3872](https://togithub.com/googleforgames/agones/pull/3872)
- [@&#8203;ghostdogpr](https://togithub.com/ghostdogpr) made their first
contribution in
[https://github.com/googleforgames/agones/pull/3875](https://togithub.com/googleforgames/agones/pull/3875)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzIuMCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9oZWxtIiwidHlwZS9taW5vciJdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants