Skip to content

Conversation

@twz123
Copy link
Member

@twz123 twz123 commented Oct 14, 2025

Description

By default, grpc-go only logs errors. However, the Kubernetes API server installs a klog backend for GRPC logs. In k0s, this means that GRPC warnings will be printed to stderr. Install our own logrus backend instead. Set the default log level to "error," as vanilla grpc-go does. Support the same environment variables to change that behavior.

Note that to see GRPC info logs, one must set the GRPC log level to info and run k0s with either the --verbose or --debug flag.

See:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@twz123 twz123 added the chore label Oct 14, 2025
@twz123 twz123 added the backport/release-1.34 PR that needs to be backported/cherrypicked to the release-1.34 branch label Oct 14, 2025
@twz123 twz123 marked this pull request as ready for review October 14, 2025 22:20
@twz123 twz123 requested review from a team as code owners October 14, 2025 22:20
@twz123 twz123 requested review from jnummelin and ncopa October 14, 2025 22:20
func newGRPCLogger(log logrus.FieldLogger) grpclog.LoggerV2 {
// https://github.com/grpc/grpc-go/blob/v1.76.0/grpclog/loggerv2.go#L65-L79

levelValue := os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL")
Copy link
Contributor

Choose a reason for hiding this comment

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

We have --logging flag, shouldn't it be there as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, right now, the logging flag is only for embedded binaries, not for the logging of stuff happening in the k0s executable itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why we need a separate log level for it? Can we just use the k0s log level here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, but the warning would still be displayed because k0s logs warnings and errors by default. This cannot be turned off. You can only request info logs (--verbose) or debug logs (--debug). Logrus itself is not flexible enough to support different log levels for different components either.

Kimmo was trying to troubleshoot this and found the environment variable that usually controls it. That's why I thought it wouldn't be a bad idea for k0s to honor those settings. However, it currently doesn't because the API server overwrites grpc-go's defaults (which is error) in one of its package's init functions.

So yes, we can remove the separate log level, but that wouldn't silence the warning. I'm trying to figure out if this can be fixed upstream because either etcd is doing something unusual or GRPC is logging at the wrong log level. However, I'm not convinced that this will lead anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another option would be to shift the GRPC log levels by one: Error -> Warning, Warning -> Info, Info -> Debug. The GRPC logger doesn't have a Debug level, it has a V threshold instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hold on! Maybe there's really a chance to fix it upstream. In that case, it'd probably be best to just use k0s log levels.

Copy link
Member Author

Choose a reason for hiding this comment

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

@makhov I've removed all the custom handling and made this a simple adapter, just as we do it for cfssl. I'm trying my best to get rid of the warning upstream. However, if that won't work out, then we can still opt to add some means of changing the GRPC log level separately from the general k0s log level.

makhov
makhov previously approved these changes Oct 15, 2025
@twz123 twz123 marked this pull request as draft October 15, 2025 10:38
@twz123 twz123 changed the title Install a logrus logger for GRPC logs Bridge GRPC logs to logrus Oct 30, 2025
@twz123 twz123 marked this pull request as ready for review October 31, 2025 07:08
The Kubernetes API server installs a klog backend for GRPC logs. In k0s,
this means that GRPC warnings will be printed to stderr. Install our own
logrus adapter for GRPC instead.

See: https://github.com/kubernetes/kubernetes/blob/v1.34.1/staging/src/k8s.io/apiserver/pkg/storage/etcd3/logger.go#L27
Signed-off-by: Tom Wieczorek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/release-1.34 PR that needs to be backported/cherrypicked to the release-1.34 branch chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants