Skip to content

More cloud logging options #927

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

Merged
merged 5 commits into from
May 23, 2025
Merged

More cloud logging options #927

merged 5 commits into from
May 23, 2025

Conversation

EronWright
Copy link
Contributor

Proposed changes

This PR tweaks the operator's logging code to write to stdout rather than to stderr, and to support structured json output.

See "Best practices":

Severities: By default, logs written to the standard output are on the INFO level and logs written to the standard error are on the ERROR level. Structured logs can include a severity field, which defines the log's severity.

The Helm chart now supports the following logging options:

controller:
  # -- Log Level ('debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity)
  logLevel: info
  # -- Log format (one of 'json' or 'console')
  logFormat: console

When running the operator in your IDE, the "development mode" is enabled (i.e. debug-level, console format).

Examples

Console Format

2025-05-23T20:11:09.067Z INFO    setup   Pulumi Kubernetes Operator Manager      {"version": "v2.0.0"}
2025-05-23T20:11:09.155Z INFO    setup   starting file server for program resource       {"address": ":9090", "advertisedAddress": "pulumi-kubernetes-operator.pulumi-kubernetes-operator:80"}
2025-05-23T20:11:09.155Z INFO    setup   starting manager
2025-05-23T20:11:09.156Z INFO    controller-runtime.metrics      Starting metrics server
2025-05-23T20:11:09.156Z INFO    setup   disabling http/2
2025-05-23T20:11:09.156Z INFO    starting server {"name": "health probe", "addr": "[::]:8081"}
2025-05-23T20:11:09.257Z INFO    attempting to acquire leader lease pulumi-kubernetes-operator/operator.pulumi.com...
2025-05-23T20:11:11.353Z INFO    controller-runtime.metrics      Serving metrics server  {"bindAddress": ":8383", "secure"

JSON Format

{"level":"info","ts":"2025-05-23T20:08:41.331Z","logger":"setup","msg":"Pulumi Kubernetes Operator Manager","version":"v2.0.0"}
{"level":"info","ts":"2025-05-23T20:08:41.408Z","logger":"setup","msg":"starting file server for program resource","address":":9090","advertisedAddress":"pulumi-kubernetes-operator.pulumi-kubernetes-operator:80"}
{"level":"info","ts":"2025-05-23T20:08:41.408Z","logger":"setup","msg":"starting manager"}
{"level":"info","ts":"2025-05-23T20:08:41.408Z","logger":"controller-runtime.metrics","msg":"Starting metrics server"}
{"level":"info","ts":"2025-05-23T20:08:41.408Z","logger":"setup","msg":"disabling http/2"}
{"level":"info","ts":"2025-05-23T20:08:41.409Z","msg":"starting server","name":"health probe","addr":"[::]:8081"}
{"level":"info","ts":"2025-05-23T20:08:41.512Z","msg":"attempting to acquire leader lease pulumi-kubernetes-operator/operator.pulumi.com..."}
{"level":"info","ts":"2025-05-23T20:08:41.516Z","msg":"successfully acquired lease pulumi-kubernetes-operator/operator.pulumi.com"}

Related issues (optional)

Closes #912

@EronWright EronWright requested review from blampe and a team May 23, 2025 20:36
Copy link

codecov bot commented May 23, 2025

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 53.00%. Comparing base (f42d305) to head (cd6c0da).
Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
operator/cmd/main.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #927      +/-   ##
==========================================
+ Coverage   52.17%   53.00%   +0.82%     
==========================================
  Files          33       33              
  Lines        4556     4632      +76     
==========================================
+ Hits         2377     2455      +78     
+ Misses       1986     1981       -5     
- Partials      193      196       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

opts := zap.Options{
Development: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This Development flag is equivalent to debug-level + console format. I think it simplest to simply remove this line in favor of being explciit in Helm, quickstart, and launch.json.

Comment on lines +104 to +105
klog.SetLogger(logger)
ctrllog.SetLogger(logger)
Copy link
Contributor Author

@EronWright EronWright May 23, 2025

Choose a reason for hiding this comment

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

By configuring the klog backend to use Zap, one avoids having plain log output intermixed with json output. We see the good effects with these two lines:

{"level":"info","ts":"2025-05-23T20:08:41.512Z","msg":"attempting to acquire leader lease pulumi-kubernetes-operator/operator.pulumi.com..."}
{"level":"info","ts":"2025-05-23T20:08:41.516Z","msg":"successfully acquired lease pulumi-kubernetes-operator/operator.pulumi.com"}

@EronWright EronWright merged commit b945c80 into master May 23, 2025
9 checks passed
@EronWright EronWright deleted the issue-912 branch May 23, 2025 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More cloud logging options
2 participants