-
Notifications
You must be signed in to change notification settings - Fork 183
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
H4HIP: Enhanced logging library for Helm CLI #372
Open
banjoh
wants to merge
5
commits into
helm:main
Choose a base branch
from
banjoh:em/enhance-helm-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
282e1da
H4HIP: Enhanced logging library for Helm CLI
banjoh abc7f7f
Add comment
banjoh a39b11b
chore: choose logr library instead of others
banjoh 82f2a55
chore: indicate slog and logr both have logger API interfaces
banjoh d19e11a
Prefer slog logging library
banjoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
hip: 9999 | ||
title: "Enhanced logging library for Helm CLI" | ||
authors: [ "Evans Mungai <[email protected]>" ] | ||
created: "2024-11-22" | ||
type: "feature" | ||
status: "draft" | ||
--- | ||
|
||
## Abstract | ||
|
||
This proposal introduces an improved logging library for Helm CLI and SDK to enhance logging capabilities for troubleshooting, development, and debugging. By using newer logging features such as log formatting and different log levels, developers and CLI users gain flexibility when deciding how much logging information they want to consume, and in what format. | ||
|
||
The HIP also introduces the ability for SDK users to use their own logging library with the SDK. Users will be able to provide a logger implementing `slog.Handler` interface, allowing them to consume instrumented logs in the SDK. | ||
|
||
## Motivation | ||
|
||
The current logging mechanism in Helm CLI and SDK lacks granularity and structure. Users and developers face difficulties when: | ||
|
||
- Troubleshooting Helm CLI commands due to inability to increase the details that can get logged. More logs come in handy when submitting bug reports for example. | ||
- Instrumenting Helm code with clear and consistent logging conventions for contributors, as well as consumers of CLI and SDK logs. | ||
- Inflexibility using a different logging library to what the SDK uses. There is no way, in code, to have client loggers consume logs produced by the SDK | ||
|
||
The proposed solution addresses these gaps by integrating a logging library that supports log levels and structured output, as well as a widely supported logger implementation interface for SDK users to consume. | ||
|
||
## Rationale | ||
|
||
The following libraries were evaluated: | ||
|
||
1. **`slog`:** | ||
- Provides log levels (`info`, `debug`, `error`, `warning`). More levels can be added | ||
- Offers structured logging. | ||
- Lightweight and straightforward to integrate. | ||
- Is part of Go standard library | ||
- Has `slog.Handler` interface that other logger implementations can implement to be `slog` compatible | ||
|
||
2. **`klog`:** | ||
- Provides log levels and also verbosity levels, enabling more granular control. Verbosity level controls the amount of detail in logs, enabling users to filter messages based on their importance or relevance. | ||
- Allows getting instrumented Kubernetes client library | ||
- Its an external library, hence introducing a dependency | ||
|
||
3. **`logr`** | ||
- Library defining interfaces for logger implementations and libraries expecting loggers that implement these APIs. `klog`, `slog`, `log` and many others are compatible with `logr`. | ||
- Provides log levels also verbosity levels | ||
- Its an external library, hence introducing a dependency | ||
- Has `logr.Handler` interface that other logger implementations can implement to be `logr` compatible | ||
|
||
While these libraries meet all the requirements we want, `slog` is the preferred choice here. It provides all functionality that the other choices have but stands out since it has a wider adoption given that its part of Go standard library. This will be benefitial to SDK users who have their existing logger implementations present. They would either implement `slog.Handler` interface or add a dependency of an existing adapter logger implementation. | ||
|
||
## Specification | ||
|
||
- Helm will instrument `debug`, `info`, `warning` and `error` log levels. These log levels will enable filtering of logs. | ||
- Logs will be written to `stderr` by the Helm CLI client. `stdout` will be left for output from operations. SDK users would choose where to write logs to through configuring the logger they pass to the SDK. | ||
- Ability to allow users to configure log levels and formatting through CLI flags or environment variables. | ||
- Helm SDK should not be instrumented with error logs. Instead, errors ought to be returned. Any logging of such errors should be left to clients to choose whether to log or not. | ||
- When invoking plugins and post-renderers, `HELM_LOG_LEVEL` and `HELM_LOG_FORMAT` environment variables would be set, allowing them to output the appropriate amount of logs and format to stderr. | ||
- There will be structured logging with two options. Raw text for humans to view, and JSON formatting that machines can consume. | ||
- Ability for SDK users to override the default logger implementation. The SDK will expect at logger that implements `slog.Handler` interface. | ||
|
||
### Example: | ||
|
||
TODO: To be added once specification is agreed | ||
|
||
## Backwards Compatibility | ||
|
||
The current logging system, Golang's `log` package will be replaced by `slog`. | ||
|
||
## Security Implications | ||
|
||
|
||
## How to Teach This | ||
|
||
1. **Documentation Updates:** | ||
- Provide examples of using the new logging features in the Helm documentation. | ||
- Include a section on how to configure log levels and formats. | ||
- Document conventions of how to instrument logs. Specifically, what information should be in what log level. Also document that the SDK does not log errors. | ||
- Example for SDK users of how to override the default logger with their own implementation. For loggers that do not implement `slog.Handler`, document an example of how this can be done. | ||
- Document how plugins and post-renderers can inherit log levels and formatting from helm CLI client. | ||
|
||
2. **CLI help text:** | ||
- Use Helm CLI help messages (`helm --help`) to inform users about the new logging options. | ||
|
||
## Reference Implementation | ||
|
||
|
||
## Rejected Ideas | ||
|
||
1. **Sticking with the current logging system:** | ||
- Rejected due to lack of flexibility and limited usefulness for debugging. | ||
|
||
## Open Issues | ||
|
||
|
||
## References | ||
|
||
- [Go’s slog Documentation](https://pkg.go.dev/log/slog) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In addition to klog there is logr, an interface that klog suffices. Can you add that in.