In contrast to the original HandleError and HandleCrash, the new HandleErrorWithContext and HandleCrashWithContext functions properly do contextual logging, so if a problem occurs while e.g. dealing with a certain request and WithValues was used for that request, then the error log entry will also contain information about it. The output changes from unstructured to structured, which might be a breaking change for users who grep for panics. Care was taken to format panics as similar as possible to the original output. For errors, a message string gets added. There was none before, which made it impossible to find all error output coming from HandleError. Keeping HandleError and HandleCrash around without deprecating while changing the signature of callbacks is a compromise between not breaking existing code and not adding too many special cases that need to be supported. There is some code which uses PanicHandlers or ErrorHandlers, but less than code that uses the Handle* calls. In Kubernetes, we want to replace the calls. logcheck warns about them in code which is supposed to be contextual. The steps towards that are: - add TODO remarks as reminder (this commit) - locally remove " TODO(pohly): " to enable the check with `//logcheck:context`, merge fixes for linter warnings - once there are none, remove the TODO to enable the check permanently
43 lines
1.9 KiB
Plaintext
43 lines
1.9 KiB
Plaintext
# hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>,
|
|
# for example k8s.io/cmd/kube-scheduler/app/config/config.go.
|
|
#
|
|
# By default, structured logging call parameters are checked, but usage of
|
|
# those calls is not required. That is changed on a per-file basis.
|
|
#
|
|
# Remember to clean the golangci-lint cache when changing the configuration and
|
|
# running the verify-golangci-lint.sh script multiple times, otherwise
|
|
# golangci-lint will report stale results:
|
|
# _output/local/bin/golangci-lint cache clean
|
|
|
|
# At this point we don't enforce the usage structured logging calls except in
|
|
# those packages that were migrated. This disables the check for other files.
|
|
-structured .*
|
|
|
|
# Now enable it again for migrated packages.
|
|
structured k8s.io/kubernetes/cmd/kubelet/.*
|
|
structured k8s.io/kubernetes/pkg/kubelet/.*
|
|
structured k8s.io/kubernetes/pkg/proxy/.*
|
|
structured k8s.io/kms/.*
|
|
structured k8s.io/apiserver/pkg/storage/value/.*
|
|
structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.*
|
|
|
|
# The following packages have been migrated to contextual logging.
|
|
# Packages matched here do not have to be listed above because
|
|
# "contextual" implies "structured".
|
|
contextual k8s.io/apimachinery/pkg/util/runtime/.*
|
|
contextual k8s.io/client-go/metadata/.*
|
|
contextual k8s.io/client-go/tools/events/.*
|
|
contextual k8s.io/client-go/tools/record/.*
|
|
contextual k8s.io/dynamic-resource-allocation/.*
|
|
contextual k8s.io/kubernetes/cmd/kube-proxy/.*
|
|
contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
|
|
contextual k8s.io/kubernetes/pkg/controller/.*
|
|
contextual k8s.io/kubernetes/pkg/scheduler/.*
|
|
contextual k8s.io/kubernetes/test/e2e/dra/.*
|
|
|
|
# As long as contextual logging is alpha or beta, all WithName, WithValues,
|
|
# NewContext calls have to go through klog. Once it is GA, we can lift
|
|
# this restriction. Whether we then do a global search/replace remains
|
|
# to be decided.
|
|
with-helpers .*
|