mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #99090 from adisky/logcheck3
Add tool to check use of unstructured logs
This commit is contained in:
commit
f55a4ce84f
17
hack/.structured_logging
Normal file
17
hack/.structured_logging
Normal file
@ -0,0 +1,17 @@
|
||||
pkg/kubelet/dockershim/
|
||||
pkg/kubelet/dockershim/cm
|
||||
pkg/kubelet/dockershim/libdocker
|
||||
pkg/kubelet/dockershim/libdocker/testing
|
||||
pkg/kubelet/dockershim/metrics
|
||||
pkg/kubelet/dockershim/network
|
||||
pkg/kubelet/dockershim/network/cni
|
||||
pkg/kubelet/dockershim/network/cni/testing
|
||||
pkg/kubelet/dockershim/network/hairpin
|
||||
pkg/kubelet/dockershim/network/hostport
|
||||
pkg/kubelet/dockershim/network/kubenet
|
||||
pkg/kubelet/dockershim/network/metrics
|
||||
pkg/kubelet/dockershim/network/testing
|
||||
pkg/kubelet/dockershim/remote
|
||||
pkg/kubelet/server/metrics
|
||||
pkg/kubelet/server/stats
|
||||
pkg/kubelet/server/stats/testing
|
@ -20,6 +20,7 @@ DEP_PROGS=\
|
||||
$(GOBIN)/misspell\
|
||||
$(GOBIN)/prettybench\
|
||||
$(GOBIN)/staticcheck\
|
||||
$(GOBIN)/logcheck\
|
||||
|
||||
.PHONY: all
|
||||
all: clean build
|
||||
@ -47,3 +48,6 @@ $(GOBIN)/prettybench: deps
|
||||
|
||||
$(GOBIN)/staticcheck: deps
|
||||
go install honnef.co/go/tools/cmd/staticcheck
|
||||
|
||||
$(GOBIN)/logcheck: deps
|
||||
go install k8s.io/klog/hack/tools/logcheck
|
||||
|
@ -10,5 +10,6 @@ require (
|
||||
gotest.tools v2.2.0+incompatible
|
||||
gotest.tools/gotestsum v0.3.5
|
||||
honnef.co/go/tools v0.0.1-2020.1.6
|
||||
k8s.io/klog/hack/tools v0.0.0-20210303110520-14dec3377f55
|
||||
sigs.k8s.io/zeitgeist v0.2.0
|
||||
)
|
||||
|
@ -689,8 +689,9 @@ golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -781,8 +782,9 @@ golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394/go.mod h1:emZCQorbCU4vsT4f
|
||||
golang.org/x/tools v0.0.0-20201230224404-63754364767c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210102185154-773b96fafca2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210105210202-9ed45478a130 h1:8qSBr5nyKsEgkP918Pu5FFDZpTtLIjXSo6mrtdVOFfk=
|
||||
golang.org/x/tools v0.0.0-20210105210202-9ed45478a130/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -907,6 +909,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.6 h1:W18jzjh8mfPez+AwGLxmOImucz/IFjpNlrKVnaj2YVc=
|
||||
honnef.co/go/tools v0.0.1-2020.1.6/go.mod h1:pyyisuGw24ruLjrr1ddx39WE0y9OooInRzEYLhQB2YY=
|
||||
k8s.io/klog/hack/tools v0.0.0-20210303110520-14dec3377f55 h1:dLsq+jacIVLNk1Jmh5RFmlTiD5kIwjYN5hh8udCyeDc=
|
||||
k8s.io/klog/hack/tools v0.0.0-20210303110520-14dec3377f55/go.mod h1:peYvfmhJdUiWTjdEpxAPkauLKX+lwVMfcSIMynAWZ14=
|
||||
mvdan.cc/gofumpt v0.1.0 h1:hsVv+Y9UsZ/mFZTxJZuHVI6shSQCtzZ11h1JEFPAZLw=
|
||||
mvdan.cc/gofumpt v0.1.0/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
|
||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
|
||||
_ "github.com/google/go-flow-levee/cmd/levee"
|
||||
_ "honnef.co/go/tools/cmd/staticcheck"
|
||||
_ "k8s.io/klog/hack/tools/logcheck"
|
||||
|
||||
// benchmarking tools
|
||||
_ "github.com/cespare/prettybench"
|
||||
|
64
hack/verify-structured-logging.sh
Executable file
64
hack/verify-structured-logging.sh
Executable file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2021 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script is used to avoid regressions after a package is migrated
|
||||
# to structured logging. once a package is completely migrated add
|
||||
# it .structured_logging file to avoid any future regressions.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
source "${KUBE_ROOT}/hack/lib/util.sh"
|
||||
|
||||
kube::golang::verify_go_version
|
||||
|
||||
# Ensure that we find the binaries we build before anything else.
|
||||
export GOBIN="${KUBE_OUTPUT_BINPATH}"
|
||||
PATH="${GOBIN}:${PATH}"
|
||||
|
||||
# Install logcheck
|
||||
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
||||
GO111MODULE=on go install k8s.io/klog/hack/tools/logcheck
|
||||
popd >/dev/null
|
||||
|
||||
# We store packaged that are migrated in .structured_logging
|
||||
migrated_packages_file="${KUBE_ROOT}/hack/.structured_logging"
|
||||
|
||||
# Ensure that file is sorted.
|
||||
kube::util::check-file-in-alphabetical-order "${migrated_packages_file}"
|
||||
|
||||
migrated_packages=()
|
||||
while IFS='' read -r line; do
|
||||
migrated_packages+=("$line")
|
||||
done < <(cat "${migrated_packages_file}")
|
||||
|
||||
|
||||
# TODO: Improve concurrancy here
|
||||
ret=0
|
||||
for package in "${migrated_packages[@]}"; do
|
||||
logcheck "$KUBE_ROOT/$package" || ret=$?
|
||||
done
|
||||
|
||||
if [ $ret -eq 0 ]; then
|
||||
echo "Structured logging static check is passed :)."
|
||||
else
|
||||
echo "Please fix above failures. You can locally test via:"
|
||||
echo "hack/verify-structured-logging.sh"
|
||||
fi
|
||||
exit $ret
|
Loading…
Reference in New Issue
Block a user