Skip to content

Commit

Permalink
contextual logging: update plans and status
Browse files Browse the repository at this point in the history
We need to be more conservative than originally planned and continue to produce
the same informative log output as before when contextual logging is disabled.

To help reviewers understand the scope of the work, a new "Status and next
steps" summarizes where we are with the conversion.
  • Loading branch information
pohly committed Jan 24, 2024
1 parent 66b45aa commit b83cdb2
Showing 1 changed file with 120 additions and 4 deletions.
124 changes: 120 additions & 4 deletions keps/sig-instrumentation/3077-contextual-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- [Scalability](#scalability)
- [Troubleshooting](#troubleshooting)
- [Implementation History](#implementation-history)
- [Status and next steps](#status-and-next-steps)
- [Drawbacks](#drawbacks)
- [Alternatives](#alternatives)
- [Per-component logger](#per-component-logger)
Expand Down Expand Up @@ -520,9 +521,8 @@ logger.Info("Processing", "pod", klog.KObj(pod))
logger.Info("Done", "pod", klog.KObj(pod))
```

Starting with beta, the feature gate will be enabled and code can be written
without such duplication to avoid the need for further changes when reaching
GA:
Starting with GA, the feature will always be enabled and code can be written
without such duplication:

```
logger := logger.WithValues("pod", klog.KObj(pod))
Expand Down Expand Up @@ -1075,14 +1075,130 @@ None besides bugs that could cause a program to panic (null logger).

###### What steps should be taken if SLOs are not being met to determine the problem?

Revert commits that changed log calls.
A cluster operator can disable the feature via the feature gate.

Kubernetes developers can revert individual commits that changed log calls once
it has been determined that they introduce too much overhead.

## Implementation History

* Kubernetes 1.24: initial alpha
* Kubernetes 1.27: parts of kube-controller-manager converted
* Kubernetes 1.28: kube-controller-manager converted completely, relationship
with log/slog in Go 1.21 clarified
* Kubernetes 1.29: kube-scheduler converted completely

## Status and next steps

As of Kubernetes 1.29.1, kube-controller-manager and kube-scheduler have been
converted. The logcheck tool can be used to count remaining log calls that need
to be converted:

```
go install sigs.k8s.io/logtools/logcheck@latest
echo "Component | Non-Structured Logging | Non-Contextual Logging " && echo "------ | ------- | -------" && for i in $(find pkg/* cmd/* staging/src/k8s.io/* -maxdepth 0 -type d | sort); do echo "$i | $(cd $i; ${GOPATH}/bin/logcheck -check-structured -check-deprecations=false 2>&1 ./... | wc -l ) | $(cd $i; ${GOPATH}/bin/logcheck -check-structured -check-deprecations=false -check-contextual ./... 2>&1 | wc -l )"; done
```

Note that this also counts calls where it was decided to not convert them. The
actual check with golangci-lint ignores those because of a `//nolint:logcheck`
suppression comment.

Component | Non-Structured Logging | Non-Contextual Logging
------ | ------- | -------
cmd/clicheck | 0 | 0
cmd/cloud-controller-manager | 6 | 8
cmd/dependencycheck | 0 | 0
cmd/dependencyverifier | 0 | 0
cmd/fieldnamedocscheck | 1 | 1
cmd/gendocs | 0 | 0
cmd/genkubedocs | 0 | 0
cmd/genman | 0 | 0
cmd/genswaggertypedocs | 2 | 2
cmd/genutils | 0 | 0
cmd/genyaml | 0 | 0
cmd/gotemplate | 0 | 0
cmd/importverifier | 0 | 0
cmd/kubeadm | 264 | 463
cmd/kube-apiserver | 6 | 7
cmd/kube-controller-manager | 0 | 0
cmd/kubectl | 0 | 0
cmd/kubectl-convert | 0 | 0
cmd/kubelet | 0 | 52
cmd/kubemark | 1 | 1
cmd/kube-proxy | 0 | 42
cmd/kube-scheduler | 0 | 0
cmd/preferredimports | 0 | 0
cmd/prune-junit-xml | 0 | 0
cmd/yamlfmt | 0 | 0
pkg/api | 0 | 0
pkg/apis | 0 | 0
pkg/auth | 1 | 1
pkg/capabilities | 0 | 0
pkg/client | 0 | 0
pkg/cloudprovider | 0 | 0
pkg/cluster | 0 | 0
pkg/controller | 0 | 3
pkg/controlplane | 53 | 69
pkg/credentialprovider | 48 | 77
pkg/features | 0 | 0
pkg/fieldpath | 0 | 0
pkg/generated | 0 | 0
pkg/kubeapiserver | 4 | 4
pkg/kubectl | 1 | 2
pkg/kubelet | 2 | 1983
pkg/kubemark | 7 | 7
pkg/printers | 0 | 0
pkg/probe | 7 | 24
pkg/proxy | 0 | 360
pkg/quota | 0 | 0
pkg/registry | 46 | 99
pkg/routes | 2 | 2
pkg/scheduler | 0 | 0
pkg/security | 0 | 0
pkg/securitycontext | 0 | 0
pkg/serviceaccount | 25 | 44
pkg/util | 20 | 57
pkg/volume | 704 | 1110
pkg/windows | 1 | 1
staging/src/k8s.io/api | 0 | 0
staging/src/k8s.io/apiextensions-apiserver | 58 | 89
staging/src/k8s.io/apimachinery | 80 | 125
staging/src/k8s.io/apiserver | 285 | 655
staging/src/k8s.io/client-go | 163 | 283
staging/src/k8s.io/cli-runtime | 1 | 2
staging/src/k8s.io/cloud-provider | 122 | 162
staging/src/k8s.io/cluster-bootstrap | 2 | 4
staging/src/k8s.io/code-generator | 108 | 155
staging/src/k8s.io/component-base | 33 | 64
staging/src/k8s.io/component-helpers | 2 | 4
staging/src/k8s.io/controller-manager | 10 | 10
staging/src/k8s.io/cri-api | 0 | 0
staging/src/k8s.io/csi-translation-lib | 3 | 4
staging/src/k8s.io/dynamic-resource-allocation | 0 | 0
staging/src/k8s.io/endpointslice | 0 | 0
staging/src/k8s.io/kms | 0 | 0
staging/src/k8s.io/kube-aggregator | 45 | 62
staging/src/k8s.io/kube-controller-manager | 0 | 0
staging/src/k8s.io/kubectl | 96 | 160
staging/src/k8s.io/kubelet | 0 | 32
staging/src/k8s.io/kube-proxy | 0 | 0
staging/src/k8s.io/kube-scheduler | 0 | 0
staging/src/k8s.io/legacy-cloud-providers | 1281 | 2015
staging/src/k8s.io/metrics | 0 | 0
staging/src/k8s.io/mount-utils | 55 | 95
staging/src/k8s.io/pod-security-admission | 0 | 1
staging/src/k8s.io/sample-apiserver | 0 | 0
staging/src/k8s.io/sample-cli-plugin | 0 | 0
staging/src/k8s.io/sample-controller | 0 | 0

For Kubernetes 1.30, the focus is on client-go. APIs need to be extended
carefully without breaking existing code so that a context can be provided for
log calls. In some cases, this also makes a context available to code which
currently uses `context.TODO` as a stop-gap measure. Currently there are over
300 of those in `staging/src/k8s.io/client-go`. Whenever new APIs get
introduced, components which were already converted to contextual logging get
updated to use those.

## Drawbacks

Expand Down

0 comments on commit b83cdb2

Please sign in to comment.