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

Prevent Int64 Overflow #3605

Merged
merged 9 commits into from
Jan 24, 2024
Merged

Prevent Int64 Overflow #3605

merged 9 commits into from
Jan 24, 2024

Conversation

Kalaiselvi84
Copy link
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:

Which issue(s) this PR fixes:

Closes #3604

Special notes for your reviewer:

@github-actions github-actions bot added kind/bug These are bugs. size/S labels Jan 23, 2024
@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: b886e664-8de1-4115-bf7c-de28307cdbc5

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

@Kalaiselvi84 Kalaiselvi84 marked this pull request as draft January 23, 2024 00:59
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: ecdf5262-fa85-4f70-86a0-f56d37ff858c

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/3605/head:pr_3605 && git checkout pr_3605
  • 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.38.0-dev-8996c33-amd64

Copy link
Collaborator

@igooch igooch left a comment

Choose a reason for hiding this comment

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

Could you also add in unit tests for the functionality? They can go in TestControllerUpdateFleetCounterStatus for the fleet controller and TestComputeStatus for the gameserverset controller.

@@ -721,6 +722,14 @@ func (c *Controller) filterGameServerSetByActive(fleet *agonesv1.Fleet, list []*
return active, rest
}

// SafeAdd prevents overflow by limiting the sum to math.MaxInt64.
func SafeAdd(x, y int64) int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function should probably go in pkg/apis/agones/v1/common.go

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 2877393a-b061-4dc9-8f0d-ab82a8ec57d9

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

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a354c8fb-a61e-42d0-841b-928831cb43f8

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/3605/head:pr_3605 && git checkout pr_3605
  • 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.38.0-dev-cf2a0fb-amd64

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 9528b86c-8336-4724-8768-a1a9d4a3fef9

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/3605/head:pr_3605 && git checkout pr_3605
  • 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.38.0-dev-0c6a587-amd64

Copy link
Collaborator

@igooch igooch left a comment

Choose a reason for hiding this comment

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

For testing some edge cases you can change

	gsSet1.Status.Counters = map[string]agonesv1.AggregatedCounterStatus{
		"fullCounter": {
			AllocatedCount:    1000,
			AllocatedCapacity: 1000,
			Capacity:          1000,
			Count:             1000,
		},

To have maxInt64:

	gsSet1.Status.Counters = map[string]agonesv1.AggregatedCounterStatus{
		"fullCounter": {
			AllocatedCount:    9223372036854775807,
			AllocatedCapacity: 9223372036854775807,
			Capacity:          9223372036854775807,
			Count:             9223372036854775807,
		},

assert.Equal(t, int64(30), fleet.Status.Counters["thirdCounter"].AllocatedCapacity)
assert.Equal(t, int64(400), fleet.Status.Counters["thirdCounter"].Capacity)
assert.Equal(t, int64(21), fleet.Status.Counters["thirdCounter"].Count)
assert.Equal(t, agonesv1.SafeAdd(1000, 100), fleet.Status.Counters["fullCounter"].AllocatedCount)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we want to leave assert.Equal(t, int64(21), fleet.Status.Counters["thirdCounter"].Count). The err := c.updateFleetStatus(ctx, fleet) will call the SafeAdd as part of the method, so that's part of what we're testing.

AllocatedCapacity: 10,
Count: 50,
Capacity: 85,
AllocatedCount: agonesv1.SafeAdd(5, 0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

For these we'll want to leave as plain int64.

You can add another Counter under multiple game servers similar to:

		gs1.Status.Counters = map[string]agonesv1.CounterStatus{
			"firstCounter":  {Count: 5, Capacity: 10},
			"secondCounter": {Count: 100, Capacity: 1000},
			"fullCounter":   {Count: 9223372036854775807, Capacity: 9223372036854775807},
		}

And under expected add:

				"fullCounter": {
					AllocatedCount:    9223372036854775807,
					AllocatedCapacity: 9223372036854775807,
					Count:             9223372036854775807,
					Capacity:          9223372036854775807,
				},

@igooch
Copy link
Collaborator

igooch commented Jan 24, 2024

A general comment is that we noted there's an issue with jsonpatch here https://github.com/googleforgames/agones/blob/eb4035e1f78e7a8e0c147a013a5405f904ab9899/pkg/gameservers/controller.go#L260C21-L273 that's preventing the game server from taking an actual max(int64) value. There's a fix in a different json package evanphx/json-patch#194, but we need to incorporate that into our code.

All that is to say this code mostly looks good, but the game server won't currently take max(int64) due to a separate bug. I don't think this PR needs to wait on that code, we can solve that issue separately.

@markmandel
Copy link
Member

All that is to say this code mostly looks good, but the game server won't currently take max(int64) due to a separate bug. I don't think this PR needs to wait on that code, we can solve that issue separately.

+1 on this.

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.

LGTM me too. Can come out of draft.

@Kalaiselvi84 Kalaiselvi84 marked this pull request as ready for review January 24, 2024 18:26
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 278dca47-49ac-466d-b094-008344c3b93a

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/3605/head:pr_3605 && git checkout pr_3605
  • 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.38.0-dev-5750a60-amd64

@markmandel markmandel merged commit 702141c into googleforgames:main Jan 24, 2024
4 checks passed
@Kalaiselvi84 Kalaiselvi84 deleted the pr-3604 branch March 15, 2024 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug These are bugs. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregate Counter Status Errors When Capacity Is Greater Than int64
4 participants