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

Define SDKServer LogLevel early #3631

Merged
merged 11 commits into from
Feb 20, 2024
Merged

Conversation

Kalaiselvi84
Copy link
Contributor

@Kalaiselvi84 Kalaiselvi84 commented Feb 2, 2024

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 #3629

Special notes for your reviewer:

@Kalaiselvi84
Copy link
Contributor Author

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?

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 5f6842c0-3883-45d3-8b3f-8c9c3e4a7a85

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

@markmandel
Copy link
Member

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?

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:

func (c *Controller) sidecar(gs *agonesv1.GameServer) corev1.Container {

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: cabb1ae6-ad2b-4e07-bbbf-3fd75e5007a0

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

@Kalaiselvi84
Copy link
Contributor Author

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:

I've added an environment variable to the sidecar method in the pkg/gameservers/controller.go file and updated the Run method to reflect this capture in the pkg/sdkserver/sdkserver.go file. Does this change seem correct to you? Please let me know if anything else needs to be modified.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: dcd467b6-3e41-46bc-8c16-9cdb2c2bed38

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

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-5fbabcc-amd64

@@ -659,6 +659,10 @@ func (c *Controller) sidecar(gs *agonesv1.GameServer) corev1.Container {
Name: "FEATURE_GATES",
Value: runtime.EncodeFeatures(),
},
{
Name: "LOG_LEVEL",
Value: "info",
Copy link
Member

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.

// grab configuration details
if gs.Spec.SdkServer.LogLevel != "" {
logLevel = gs.Spec.SdkServer.LogLevel
var logLevel string
Copy link
Member

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:

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!

Copy link
Contributor Author

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:

  1. Removed the hardcoded log level in controller.go and replaced it with gs.Spec.SdkServer.LogLevel.
  2. Added log level as a parameter in the NewSDKServer function to accept the log level.
  3. Added log level parsing in main.go and passed it to NewSDKServer function.
  4. Set s.logger.Logger.SetLevel(logLevel) right after its initialization in the NewSDKServer function.
  5. Modified the controller_test.go and sdkserver_test.go files based on the lint suggestion.

Please let me know if anything missing

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 1369b9d8-b25e-4b05-9a01-0e4c6b8420e1

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

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-e3ea7a8-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.

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.

@@ -70,6 +71,14 @@ var (
)

func main() {
logLevelEnv := os.Getenv("LOG_LEVEL")
Copy link
Member

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.

Copy link
Contributor Author

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")?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yep! Looks perfect! 👍🏻

if gs.Spec.SdkServer.LogLevel != "" {
logLevel = gs.Spec.SdkServer.LogLevel
var logLevel string
logLevelEnv := os.Getenv("LOG_LEVEL")
Copy link
Member

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.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 70b31dca-e43f-45b7-b6a3-ce00b6f2dc14

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

@gongmax
Copy link
Collaborator

gongmax commented Feb 13, 2024

#6 34.23 Err:1 http://deb.debian.org/debian bullseye/main amd64 wget amd64 1.21-1+deb11u1
#6 34.23   Could not connect to debian.map.fastlydns.net:80 (199.232.98.132), connection timed out Unable to connect to deb.debian.org:http:
#6 34.24 E: Failed to fetch http://deb.debian.org/debian/pool/main/w/wget/wget_1.21-1%2bdeb11u1_amd64.deb  Could not connect to debian.map.fastlydns.net:80 (199.232.98.132), connection timed out Unable to connect to deb.debian.org:http:
#6 34.24 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
#6 ERROR: executor failed running [/bin/sh -c apt-get --allow-releaseinfo-change update &&     apt-get install -y wget]: exit code: 100
------
 > [2/7] RUN apt-get --allow-releaseinfo-change update &&     apt-get install -y wget:

3.917 The following NEW packages will be installed:
3.918   wget
34.23 0 upgraded, 1 newly installed, 0 to remove and 22 not upgraded.
34.23 Need to get 964 kB of archives.
34.23 After this operation, 3559 kB of additional disk space will be used.
34.23 Err:1 http://deb.debian.org/debian bullseye/main amd64 wget amd64 1.21-1+deb11u1
34.23   Could not connect to debian.map.fastlydns.net:80 (199.232.98.132), connection timed out Unable to connect to deb.debian.org:http:
34.24 E: Failed to fetch http://deb.debian.org/debian/pool/main/w/wget/wget_1.21-1%2bdeb11u1_amd64.deb  Could not connect to debian.map.fastlydns.net:80 (199.232.98.132), connection timed out Unable to connect to deb.debian.org:http:
34.24 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
------
ERROR: failed to solve: executor failed running [/bin/sh -c apt-get --allow-releaseinfo-change update &&     apt-get install -y wget]: exit code: 100
make[5]: *** [includes/sdk.mk:109: build-build-sdk-image] Error 1
make[5]: Leaving directory '/workspace/build'
make[4]: Leaving directory '/workspace/build'
make[4]: *** [includes/build-image.mk:63: ensure-image] Error 2
make[3]: *** [includes/sdk.mk:126: ensure-build-sdk-image] Error 2
make[3]: Leaving directory '/workspace/build'
Unable to find image 'agones-build-sdk-csharp:dbf73e956b' locally
docker: Error response from daemon: pull access denied for agones-build-sdk-csharp, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.
make[2]: *** [includes/sdk.mk:91: run-sdk-command] Error 125
make[2]: Leaving directory '/workspace/build'
make[1]: *** [includes/sdk.mk:87: run-sdk-command-csharp] Error 2
make[1]: Leaving directory '/workspace/build'
make: *** [includes/sdk.mk:239: test-gen-all-sdk-grpc] Error 2

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-954cd1f-amd64

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-63b3640-amd64

gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Copy link
Collaborator

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?

Copy link
Member

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 😄

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-63b3640-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.

Looks great - a couple of lines to remove, and I think this is good to go 👍🏻

Comment on lines 250 to 251
currentLogLevel := s.logger.Logger.GetLevel()
s.logger.WithField("logLevel", currentLogLevel).Debug("Setting LogLevel configuration")
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
currentLogLevel := s.logger.Logger.GetLevel()
s.logger.WithField("logLevel", currentLogLevel).Debug("Setting LogLevel configuration")

Don't think we need these lines anymore.

Copy link
Contributor Author

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.

@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-87071a8-amd64

@markmandel
Copy link
Member

Just a note - this is approved, you can take it out of draft 😄

@Kalaiselvi84 Kalaiselvi84 marked this pull request as ready for review February 20, 2024 16:44
@agones-bot
Copy link
Collaborator

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3631/head:pr_3631 && git checkout pr_3631
  • 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.39.0-dev-9b35dbf-amd64

@markmandel markmandel merged commit 492cbb9 into googleforgames:main Feb 20, 2024
4 checks passed
@Kalaiselvi84 Kalaiselvi84 added kind/bug These are bugs. and removed kind/other labels Mar 8, 2024
@Kalaiselvi84 Kalaiselvi84 deleted the pr-3629 branch March 15, 2024 01:01
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.

Some info logs logged from sidecar when sdkServer.logLevel set to Error
5 participants