Skip to content

feat: track allocations per fleet - #4513

Merged
markmandel merged 11 commits into
agones-dev:mainfrom
nrwiersma:allocations
May 27, 2026
Merged

feat: track allocations per fleet#4513
markmandel merged 11 commits into
agones-dev:mainfrom
nrwiersma:allocations

Conversation

@nrwiersma

Copy link
Copy Markdown
Contributor

What type of PR is this?

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:

This PR adds allocations tracking on a Fleet level to provide real allocation metrics to the Fleet Autoscaler. This provides better metrics to base custom autoscaling off of while also providing a good metric to the system

Which issue(s) this PR fixes:

Closes #4452

Special notes for your reviewer:

Initially I thought to use a RWMutex and atomic.Int64, but the locking logic got really verbose and I dont think, even in active clusters, that the contention on a Mutex is likely to be a real issue, given how low the actual lock time will be. If this proves to no longer be true, it is simple to change it.

It also occurred to me that queuing the Fleet when an Allocation is observed is likely not needed, as this will always result in either a change in AllocatedReplicas, ReadyReplicas or Replicas on the GameServerSet which will itself queue the Fleet. I will run some manual tests to prove this.

@github-actions github-actions Bot added kind/feature New features for Agones size/M labels Apr 14, 2026
@nrwiersma
nrwiersma force-pushed the allocations branch 2 times, most recently from 5dea128 to 38ae676 Compare April 14, 2026 07:05
@nrwiersma
nrwiersma marked this pull request as ready for review April 14, 2026 09:44
@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Failed 😭

Build Id: 0200e9ed-b8cb-4f9c-82a3-22a40ca1032e

Status: FAILURE

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

@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 52edf034-8467-427b-90f9-765fd733d9c6

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/4513/head:pr_4513 && git checkout pr_4513
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.58.0-dev-30678d3

@markmandel markmandel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for doing this -- sorry it took a bit to get to it.

We'll need some docs at https://agones.dev/site/docs/guides/metrics/ -- but also will need to be feature shortcoded -- https://agones.dev/site/docs/contribute/documentation-editing-contribution/

Comment thread pkg/metrics/exporter_test.go Outdated
gs.Status.State = agonesv1.GameServerStateAllocated
ctrl.gsWatch.Modify(gs)

require.Eventually(t, func() bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you use https://pkg.go.dev/github.com/stretchr/testify@v1.11.1/require#EventuallyWithT you can check multiple assertions, and also get better error messages.

ReservedReplicas int32 `json:"reservedReplicas"`
// AllocatedReplicas are the number of Allocated GameServer replicas
AllocatedReplicas int32 `json:"allocatedReplicas"`
// Allocations is a counter of the number of allocations observed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread pkg/fleets/controller.go
Comment thread pkg/fleets/controller.go Outdated
defer cancel()

c.allocsMu.Lock()
defer c.allocsMu.Unlock()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice one on making sure it gets processed on shutdown.

Probably doesn't make a huge difference, but holding the whole mutex over the network calls may cause some interesting long term locking over shutdown. Might be worth taking a snapshot - or the very least, moving to a RWLock, to avoid some potential contention.

Comment thread pkg/fleets/controller.go Outdated
Comment thread pkg/fleets/controller.go Outdated
Comment on lines +814 to +819
count, ok := c.allocs[key]
if !ok {
c.allocs[key] = 1
return
}
c.allocs[key] = count + 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
count, ok := c.allocs[key]
if !ok {
c.allocs[key] = 1
return
}
c.allocs[key] = count + 1
c.allocs[key]++

maps will 0 value here, just as a suggestion

Comment thread pkg/fleets/controller.go Outdated
@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 6178bfd6-30e7-4060-ba43-0e3864f400b8

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/4513/head:pr_4513 && git checkout pr_4513
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.58.0-dev-a8be28c

@markmandel

Copy link
Copy Markdown
Member

/gcbrun

1 similar comment
@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: c09603eb-c5f9-4bac-84cf-41668d315953

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/4513/head:pr_4513 && git checkout pr_4513
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.58.0-dev-6a3b9cb

@markmandel markmandel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! Getting close!

Comment thread pkg/fleets/controller.go Outdated
Comment thread site/content/en/docs/Reference/fleetautoscaler.md Outdated
Comment thread pkg/metrics/controller_test.go Outdated
@nrwiersma
nrwiersma force-pushed the allocations branch 3 times, most recently from 2f06504 to 4be582d Compare May 4, 2026 06:01
@markmandel

Copy link
Copy Markdown
Member

/gcbrun

Sorry - I missed this one for a while!

@nrwiersma

Copy link
Copy Markdown
Contributor Author

No stress. When you happy to merge, ill update the versions again in the docs.

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: dc7a3c1b-932b-4995-ba4f-5f1ce0238653

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/4513/head:pr_4513 && git checkout pr_4513
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.59.0-dev-9cc174e

@markmandel markmandel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Just need to update the version numbers in the docs, and this is good to go!

Thanks!

Comment thread site/content/en/docs/Guides/metrics.md Outdated



{{% feature expiryVersion="1.58.0" %}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry to make you do this, but yeah - update the version to 1.59

nrwiersma added 3 commits May 25, 2026 08:10
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
nrwiersma added 7 commits May 25, 2026 08:10
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
Signed-off-by: Nicholas Wiersma <nick@wiersma.co.za>
@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Failed 😭

Build Id: 16cbd81b-7911-4663-ae87-344e937a82d5

Status: FAILURE

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

@markmandel

Copy link
Copy Markdown
Member

/gcbrun

@markmandel

Copy link
Copy Markdown
Member
	agones /go/src/agones.dev/agones/install/helm/agones/
Release "agones" does not exist. Installing it now.
I0527 01:37:06.607611      89 warnings.go:110] "Warning: autopilot-default-resources-mutator:Autopilot updated Deployment agones-system/agones-ping: defaulted unspecified 'cpu' resource for containers [agones-ping] (see http://g.co/gke/autopilot-defaults)."
I0527 01:37:06.640118      89 warnings.go:110] "Warning: autopilot-default-resources-mutator:Autopilot updated Deployment agones-system/agones-controller: defaulted unspecified 'cpu' resource for containers [agones-controller] (see http://g.co/gke/autopilot-defaults)."
I0527 01:37:06.661004      89 warnings.go:110] "Warning: autopilot-default-resources-mutator:Autopilot updated Deployment agones-system/agones-extensions: defaulted unspecified 'cpu' resource for containers [agones-extensions] (see http://g.co/gke/autopilot-defaults)."
I0527 01:37:06.679747      89 warnings.go:110] "Warning: autopilot-default-resources-mutator:Autopilot updated Deployment agones-system/agones-allocator: defaulted unspecified 'cpu' resource for containers [agones-allocator] (see http://g.co/gke/autopilot-defaults)."
I0527 01:37:06.949030      89 warnings.go:110] "Warning: AdmissionWebhookController: mutated namespaceselector of the webhooks to enforce GKE Autopilot policies."
I0527 01:37:06.951059      89 warnings.go:110] "Warning: AdmissionWebhookController: mutated namespaceselector of the webhooks to enforce GKE Autopilot policies."
I0527 01:47:12.232464      89 warnings.go:110] "Warning: autopilot-default-resources-mutator:Autopilot updated Job agones-system/agones-delete-agones-resources: defaulted unspecified 'cpu' resource for containers [pre-delete-delete-agones-resources] (see http://g.co/gke/autopilot-defaults)."
Error: release agones failed, and has been uninstalled due to atomic being set: context deadline exceeded
make: *** [Makefile:446: install] Error 1

@agones-bot

Copy link
Copy Markdown
Collaborator

Build Succeeded 🥳

Build Id: 752d1bc1-edf4-462a-832a-45cc64de06d5

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/4513/head:pr_4513 && git checkout pr_4513
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.59.0-dev-1acd11f

@markmandel markmandel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's gooooo!

@markmandel
markmandel merged commit 9f18ead into agones-dev:main May 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature New features for Agones size/L size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Proposal] - Total Allocations Tracking

3 participants