-
Notifications
You must be signed in to change notification settings - Fork 813
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
Define SDKServer LogLevel early #3631
Conversation
I've defined the sdkServer logLevel at the beginning of the sdk-server/main.go file. Please let me know if this is the correct approach and what are the other necessary changes required? |
Build Failed 😱 Build Id: 5f6842c0-3883-45d3-8b3f-8c9c3e4a7a85 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
To add the environment variable to the sidecar, you will need to edit this function to add an environment variable to the set that already exists: agones/pkg/gameservers/controller.go Line 641 in 5f58fce
|
Build Failed 😱 Build Id: cabb1ae6-ad2b-4e07-bbbf-3fd75e5007a0 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
I've added an environment variable to the |
Build Failed 😱 Build Id: dcd467b6-3e41-46bc-8c16-9cdb2c2bed38 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Succeeded 👏 Build Id: 044857f0-d3fe-4edc-b250-877ecf04dc9e 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:
|
pkg/gameservers/controller.go
Outdated
@@ -659,6 +659,10 @@ func (c *Controller) sidecar(gs *agonesv1.GameServer) corev1.Container { | |||
Name: "FEATURE_GATES", | |||
Value: runtime.EncodeFeatures(), | |||
}, | |||
{ | |||
Name: "LOG_LEVEL", | |||
Value: "info", |
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.
This shouldn't be hard coded, it should take the value from the logLevel
field on https://agones.dev/site/docs/reference/agones_crd_api_reference/#agones.dev/v1.SdkServer
Then the user can configure it themselves.
pkg/sdkserver/sdkserver.go
Outdated
// grab configuration details | ||
if gs.Spec.SdkServer.LogLevel != "" { | ||
logLevel = gs.Spec.SdkServer.LogLevel | ||
var logLevel string |
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 the one that really needs changing is here:
Lines 72 to 75 in 8b2c442
func main() { | |
ctlConf := parseEnvFlags() | |
logger.WithField("version", pkg.Version).WithField("featureGates", runtime.EncodeFeatures()). | |
WithField("ctlConf", ctlConf).Info("Starting sdk sidecar") |
Which is some of the Info level output that was happening when logging was set to Warning/Error only.
What I'm thinking we should do here, is take a logrus.Level
as part of NewSDKServer
(which will mean refactoring some unit tests, and some error handling code) and passing it in after parsing in main.go.
Then we can set the s.logger.Logger.SetLevel(level)
right under:
https://github.com/googleforgames/agones/pull/3631/files#diff-2b47120b02bc51219ccd6d97b8fe68f9d5043997eba480c0655babcafd771e4eR185 (line 185), so that is also covers all logging in this file.
Hopefully that all was clear!
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.
Following your guidance, I made below modifications:
- Removed the hardcoded log level in
controller.go
and replaced it withgs.Spec.SdkServer.LogLevel
. - Added log level as a parameter in the
NewSDKServer
function to accept the log level. - Added log level parsing in
main.go
and passed it toNewSDKServer
function. - Set
s.logger.Logger.SetLevel(logLevel)
right after its initialization in theNewSDKServer
function. - Modified the
controller_test.go
andsdkserver_test.go
files based on the lint suggestion.
Please let me know if anything missing
Build Failed 😱 Build Id: 1369b9d8-b25e-4b05-9a01-0e4c6b8420e1 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Succeeded 👏 Build Id: a6b36772-984b-46fe-ba64-8ad66374399a 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.
Couple of small things, but overall looks good.
Will need a manual test!
To test, take a single GameSever
such as: https://github.com/googleforgames/agones/blob/main/examples/simple-game-server/gameserver.yaml and set different log levels (Info, warn, error, debug). See how it changes the log output for the sidecar.
cmd/sdk-server/main.go
Outdated
@@ -70,6 +71,14 @@ var ( | |||
) | |||
|
|||
func main() { | |||
logLevelEnv := os.Getenv("LOG_LEVEL") |
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.
Rather than use os.Getenv
- please make this part of the parseEnvFlags()
function and object that it returns - then we have all argument and environment variable parsing in a single place.
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.
Quick question: I noticed that we're setting default values in our parseEnvFlags() function and binding an environment variable with the key. Do we need to follow the same pattern for the log level by using viper.SetDefault("logLevel", "info")?
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.
Please ignore the above question. I've tested the latest code changes with the Info
, Error
, Debug
, and Warn
log levels. Please review the logs at https://gist.github.com/Kalaiselvi84/74fe77e6cce7ebc55485efbeb1e0d79d and share your feedback.
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.
Could you please confirm if the manual testing looks fine? Is this how we should be testing it?
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.
Yep! Looks perfect! 👍🏻
pkg/sdkserver/sdkserver.go
Outdated
if gs.Spec.SdkServer.LogLevel != "" { | ||
logLevel = gs.Spec.SdkServer.LogLevel | ||
var logLevel string | ||
logLevelEnv := os.Getenv("LOG_LEVEL") |
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.
This section can be deleted since we set the log level in the constructor.
Build Failed 😱 Build Id: 70b31dca-e43f-45b7-b6a3-ce00b6f2dc14 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
|
Build Succeeded 👏 Build Id: 03e12482-1462-48d3-a138-3b52a193d4a9 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: e48caa8d-e3c2-40f8-bef9-97058efa8bac 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:
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" |
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.
@markmandel it looks like this is the same package that we use in our other controllers. Is there a reason we use this one over https://pkg.go.dev/log/slog?
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.
Slog didn't exist when we started this project 😄
Build Succeeded 👏 Build Id: 713b3e1e-1b3b-470f-9801-b58ebd74360e 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.
Looks great - a couple of lines to remove, and I think this is good to go 👍🏻
pkg/sdkserver/sdkserver.go
Outdated
currentLogLevel := s.logger.Logger.GetLevel() | ||
s.logger.WithField("logLevel", currentLogLevel).Debug("Setting LogLevel configuration") |
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.
currentLogLevel := s.logger.Logger.GetLevel() | |
s.logger.WithField("logLevel", currentLogLevel).Debug("Setting LogLevel configuration") |
Don't think we need these lines anymore.
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 taken out these two lines.
Build Succeeded 👏 Build Id: 62d29939-5812-45c9-81bf-220eb59399af 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:
|
Just a note - this is approved, you can take it out of draft 😄 |
Build Succeeded 👏 Build Id: 1f78b3c0-acb5-423f-bf73-670c082fc4fa 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:
|
What type of PR is this?
What this PR does / Why we need it:
Which issue(s) this PR fixes:
Closes #3629
Special notes for your reviewer: