-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LOGGING.md provides basic information on logging and how to do it in Fleet's context. --------- Co-authored-by: Mario Manno <[email protected]>
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
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,71 @@ | ||
# Context: controller-runtime | ||
|
||
Since 0.10, Fleet uses [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) as its Kubernetes | ||
controller framework. It implements _structured logging_, which basically means logging _constant_ log messages with | ||
variable key-value pairs. | ||
|
||
For instance: | ||
``` | ||
// Unstructured | ||
myloglib.Log(fmt.Sprintf("Something happened: %v", err)) | ||
// Structured | ||
logger.V(1).Info( | ||
"Reconciling bundle, checking targets, calculating changes, building objects", | ||
"generation", | ||
bundle.Generation, | ||
"observedGeneration", | ||
bundle.Status.ObservedGeneration, | ||
) | ||
``` | ||
|
||
More info [here](https://github.com/kubernetes-sigs/controller-runtime/blob/main/TMP-LOGGING.md) on how | ||
`controller-runtime` approaches logging. | ||
|
||
Fleet has preexisting logging code using [logrus](https://github.com/sirupsen/logrus), which can be ported to | ||
[zap](https://pkg.go.dev/go.uber.org/zap), for which `controller-runtime` provides helpers. | ||
|
||
# Where to log | ||
|
||
Logs should be produced from: | ||
|
||
* high-level functions, which do something that the user should know about, such as reconciliation, an entity not being | ||
found where it was expected, etc. Implementation details, which live in helper functions (eg. resetting a SHA256 sum for | ||
a manifest), are less relevant for logging. | ||
|
||
* functions taking a context as a parameter: these functions can time out, and knowing where the timeout happened before | ||
the error bubbles up can help troubleshoot it. | ||
|
||
# What (not) to log | ||
|
||
At the risk of stating the obvious, no sensitive information should be logged (eg. secrets). | ||
|
||
# Levels | ||
|
||
Fleet logging makes use of the following levels: | ||
* `Info` for events about which users may care | ||
* `Error` for errors, although those could | ||
[arguably](https://web.archive.org/web/20240521184322/https://dave.cheney.net/2015/11/05/lets-talk-about-logging) be | ||
logged as `Info` as well. | ||
|
||
## Verbosity | ||
|
||
Log messages can have a numerical verbosity. The default verbosity is 0, we also use 1 for debug logs and 4 for logs | ||
that aid in tracing problems. | ||
If log messages should not be included in the output of a binary started with the `--debug` argument, their level should | ||
be higher than 5. | ||
|
||
# Formatting | ||
|
||
Fields used for structured logging must follow camelCase. | ||
|
||
# Consistency is key | ||
|
||
Check how code living in the same file, or package, or higher up the call stack, does logging. Ensure that constant | ||
log messages and field names are phrased and formatted in consistent ways. | ||
|
||
# Useful links | ||
|
||
* [Dave Cheney on | ||
logging](https://web.archive.org/web/20240521184322/https://dave.cheney.net/2015/11/05/lets-talk-about-logging) |
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