-
Notifications
You must be signed in to change notification settings - Fork 825
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
SDK WatchGameServer logs error on shutdown #3271
SDK WatchGameServer logs error on shutdown #3271
Conversation
Build Succeeded 👏 Build Id: e6fbbb4f-7855-4029-84b8-8908dffc15ec 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:
|
@clairesc for review |
sdks/go/sdk.go
Outdated
// This is to wait for the reconnection, and not peg the CPU at 100%. | ||
time.Sleep(time.Second) | ||
continue | ||
} | ||
|
||
if gs.ObjectMeta.DeletionTimestamp != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
So I would handle this a bit differently. There are two problems we are trying to resolve:
- Not output errors here when shutting down
- Have a pluggable log system.
So, I would actually make the second part, part of the first - because we still want to handle io.EOF
as above, but not output the log.
So I would have a pluggable log as per:
#3245 (comment)
But have a function that is called here where the log functions are, that checks if gs.ObjectMeta.DeletionTimestamp.isZero()
(I think that's the right function)` and if not, then runs the pluggable log function.
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've included the Logger function to log the error message when gs.ObjectMeta.DeletionTimestamp
is not zero and removed log when "err == io.EOF" and any other error occurs while watching the GameServer.
DeletionTimestamp
is of type int64, so I added the following condition:
if reflect.ValueOf(gs.ObjectMeta.DeletionTimestamp).IsZero()
to check if it is zero or not.
reference
Build Succeeded 👏 Build Id: 4569518d-cef7-4b6d-bee7-e5d769f3f415 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:
|
Build Succeeded 👏 Build Id: 03f175d6-130d-4014-abc9-91a637d5495a 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:
|
sdks/go/sdk.go
Outdated
@@ -132,17 +140,22 @@ func (s *SDK) WatchGameServer(f GameServerCallback) error { | |||
if err != nil { | |||
return errors.Wrap(err, "could not watch gameserver") | |||
} | |||
|
|||
log := func(gs *sdk.GameServer, msg string, err error) { | |||
if time.Unix(gs.ObjectMeta.DeletionTimestamp, 0).IsZero() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if time.Unix(gs.ObjectMeta.DeletionTimestamp, 0).IsZero() { | |
if gs.ObjectMeta.DeletionTimestamp.IsZero() { |
This should work 🤔 , here is an example - we do this a bunch of places.
agones/pkg/gameservers/controller.go
Line 428 in 80f74c4
if gs.ObjectMeta.DeletionTimestamp.IsZero() { |
More examples: https://github.com/search?q=repo%3Agoogleforgames%2Fagones%20IsZero&type=code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, big slice for humble 🥧 for me. I didn't realise this was the protobuf version, not the K8s API version 🤦🏻
So, we can simplify this to:
gs.ObjectMeta.DeletionTimestamp == 0
And that will make everything happy.
Sorry about that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries. You are the best, always!👍🏻
Build Succeeded 👏 Build Id: 8ba80b50-b2e2-46d1-8cde-b1040636ed2b 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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@clairesc can you take a quick look, make sure we didn't miss anything?
I wanted to say LGTM but I gave it a quick go and got this exception when the GameServer is shutdown (via Fleet autoscaling)
I guess |
|
||
// Logger is a pluggable function that outputs the error message to standard error. | ||
var Logger ErrorLog = func(msg string, err error) { | ||
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err) | |
if gs == nil { | |
return | |
} | |
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err) |
Since @clairesc 's comment is very good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can I add the gs == nil
check here? WDYT?
log := func(gs *sdk.GameServer, msg string, err error) {
if gs == nil || gs.ObjectMeta.DeletionTimestamp == 0 {
return
}
Logger(msg, err)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's way better.
Build Failed 😱 Build Id: 694a9184-fbd4-496b-ab13-9e0d1f4a84ef To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
I think I fixed this flake. Updating. |
Build Succeeded 👏 Build Id: 89a7745a-8c4a-47b8-aa7d-2c9e2985d319 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:
|
@clairesc look good now? |
Yes LGTM |
/lgtm |
Build Succeeded 👏 Build Id: 63e69115-e00c-4daf-9c02-1f99e580f86c 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:
|
@markmandel, It looks like the PR didn't get merged automatically after the successful build. Could you kindly perform the merge for this PR?🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I forgot to approve. Done!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Kalaiselvi84, 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 |
What type of PR is this?
/kind bug
What this PR does / Why we need it:
Replaced
fmt
statements withlog
statements and added a condition to prevent logging whengs.ObjectMeta.DeletionTimestamp
is not equal to zeroWhich issue(s) this PR fixes:
Closes #3245
Special notes for your reviewer: