Skip to content

Commit 66b45aa

Browse files
committed
contextual logging: bump to beta
1 parent 42bb993 commit 66b45aa

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

keps/prod-readiness/sig-instrumentation/3077.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
kep-number: 3077
55
alpha:
66
approver: "@ehashman"
7+
beta:
8+
approver: "@logicalhan"

keps/sig-instrumentation/3077-contextual-logging/README.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- [Unit testing](#unit-testing)
3838
- [Injecting common value, logger passed through existing ctx parameter or new parameter](#injecting-common-value-logger-passed-through-existing-ctx-parameter-or-new-parameter)
3939
- [Resulting output](#resulting-output)
40+
- [Integration with log/slog](#integration-with-logslog)
4041
- [Test Plan](#test-plan)
4142
- [Graduation Criteria](#graduation-criteria)
4243
- [Alpha](#alpha)
@@ -58,6 +59,7 @@
5859
- [Propagating a logger to init code](#propagating-a-logger-to-init-code)
5960
- [Panic when FromContext is called before setting a logger](#panic-when-fromcontext-is-called-before-setting-a-logger)
6061
- [Clean separation of contextual logging and traditional klog logging](#clean-separation-of-contextual-logging-and-traditional-klog-logging)
62+
- [Use log/slog instead of klog+logr](#use-logslog-instead-of-kloglogr)
6163
<!-- /toc -->
6264

6365
## Release Signoff Checklist
@@ -507,6 +509,37 @@ The logcheck static code analysis tool will warn about code in Kubernetes which
507509
calls the underlying functions directly. Once the feature gate is no longer needed,
508510
a global search/replace can remove the usage of these wrapper functions again.
509511

512+
Because the feature gate is off during alpha, log calls have to repeat
513+
important key/value pairs even if those also got passed to `WithValues`:
514+
515+
```
516+
logger := logger.WithValues("pod", klog.KObj(pod))
517+
...
518+
logger.Info("Processing", "pod", klog.KObj(pod))
519+
...
520+
logger.Info("Done", "pod", klog.KObj(pod))
521+
```
522+
523+
Starting with beta, the feature gate will be enabled and code can be written
524+
without such duplication to avoid the need for further changes when reaching
525+
GA:
526+
527+
```
528+
logger := logger.WithValues("pod", klog.KObj(pod))
529+
...
530+
logger.Info("Processing")
531+
...
532+
logger.Info("Done")
533+
```
534+
535+
Documentation of APIs has to make it clear which values will always be included
536+
in log entries and thus don't need to be repeated. If in doubt, repeating them
537+
is okay: the text format will filter out duplicates if log call parameters
538+
overlap with `WithValues` parameters. For performance reasons it will not do
539+
that for duplicates between different `WithValues` calls. In JSON, repeating
540+
keys increases log volume size because there is no de-duplication, but the
541+
semantic is the same ("most recent wins").
542+
510543
### Text format
511544

512545
The formatting and verbosity code will be moved into `internal` packages where
@@ -839,6 +872,15 @@ I1026 16:21:00.461886 801139 scheduler.go:464] "Status after running PostFilter
839872
I1026 16:21:00.461918 801139 factory.go:209] "Unable to schedule pod; no fit; waiting" pod="default/my-csi-app-inline-volume" err="0/1 nodes are available: 1 node(s) did not have enough free storage."
840873
```
841874

875+
### Integration with log/slog
876+
877+
[`log/slog`](https://pkg.go.dev/log/slog) got added in Go
878+
1.21. Interoperability with slog is [provided by
879+
logr](https://github.com/go-logr/logr/pull/222). Applications which use slog
880+
can route log output from Kubernetes packages into their `slog.Handler` and
881+
vice versa, as demonstrated with [`component-base/logs`
882+
examples](https://github.com/kubernetes/kubernetes/pull/120696).
883+
842884
### Test Plan
843885

844886
The new code will be covered by unit tests that execute as part of
@@ -870,7 +912,7 @@ logging.
870912

871913
#### Beta
872914

873-
- All of kube-scheduler (in-tree) and CSI external-provisioner (out-of-tree) converted
915+
- [All of kube-controller-manager](https://github.com/kubernetes/kubernetes/pull/119250) and some [parts of kube-scheduler](https://github.com/kubernetes/kubernetes/pull/115588) converted (in-tree), conversion of out-of-tree components possible, whether they use pflag ([external-provisioner](https://github.com/kubernetes-csi/external-provisioner/pull/639)] or plain Go flags ([node-driver-registrar](https://github.com/kubernetes-csi/node-driver-registrar/pull/259))
874916
- Gathered feedback from developers and surveys
875917
- New APIs in `k8s.io/klog/v2` no longer marked as experimental
876918

@@ -1037,6 +1079,11 @@ Revert commits that changed log calls.
10371079

10381080
## Implementation History
10391081

1082+
* Kubernetes 1.24: initial alpha
1083+
* Kubernetes 1.27: parts of kube-controller-manager converted
1084+
* Kubernetes 1.28: kube-controller-manager converted completely, relationship
1085+
with log/slog in Go 1.21 clarified
1086+
10401087
## Drawbacks
10411088

10421089
Supporting contextual logging is a key design decision that has implications
@@ -1098,3 +1145,10 @@ would have removed all legacy code from Kubernetes. However, that transition
10981145
would have been complicated and forced all consumers of Kubernetes code to
10991146
adjust their code. Therefore the scope of the KEP was reduced from "remove
11001147
dependency on klog" to "remove dependency on global logger in klog".
1148+
1149+
### Use log/slog instead of klog+logr
1150+
1151+
This isn't viable because `slog` doesn't provide a mechanism to pass a logger
1152+
through a context. Therefore it would not be possible to support contextual
1153+
logging in packages like client-go where adding an explicit logger parameter
1154+
would be a major API break.

keps/sig-instrumentation/3077-contextual-logging/kep.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ stage: alpha
2424
# The most recent milestone for which work toward delivery of this KEP has been
2525
# done. This can be the current (upcoming) milestone, if it is being actively
2626
# worked on.
27-
latest-milestone: "v1.24"
27+
latest-milestone: "v1.30"
2828

2929
# The milestone at which this feature was, or is targeted to be, at each stage.
3030
milestone:
3131
alpha: "v1.24"
32-
beta: "v1.28"
33-
stable: "v1.30"
32+
beta: "v1.30"
3433

3534
feature-gates:
3635
- name: ContextualLogging

0 commit comments

Comments
 (0)