Make generated-stable-metrics use git ls-files

This commit is contained in:
Tim Hockin 2023-01-04 15:47:44 -08:00
parent 6a49eae422
commit 7229364f0a
No known key found for this signature in database

View File

@ -29,37 +29,47 @@ stability_check_setup() {
kube::golang::setup_env kube::golang::setup_env
} }
find_files_to_check() { function find_files_to_check() {
find . -not \( \ # Similar to find but faster and easier to understand. We want to include
\( \ # modified and untracked files because this might be running against code
-wholename './output' \ # which is not tracked by git yet.
-o -wholename './_output' \ git ls-files -cmo --exclude-standard \
-o -wholename './_gopath' \ ':!:vendor/*' `# catches vendor/...` \
-o -wholename './release' \ ':!:*/vendor/*' `# catches any subdir/vendor/...` \
-o -wholename './target' \ ':!:third_party/*' `# catches third_party/...` \
-o -wholename '*/third_party/*' \ ':!:*/third_party/*' `# catches third_party/...` \
-o -wholename '*/vendor/*' \ ':!:hack/*' `# catches hack/...` \
-o -wholename '*/hack/*' \ ':!:*/hack/*' `# catches any subdir/hack/...` \
-o -wholename '*_test.go' \ ':!:*/*_test.go' \
-o -wholename './test/instrumentation/*.go' \ ':!:test/instrumentation' \
\) -prune \ ':(glob)**/*.go' \
\) \ "$@"
\( -wholename '**/*.go' \
\)
} }
find_test_files() { function find_test_files() {
find './test/instrumentation' -wholename '**/*.go' git ls-files -cmo --exclude-standard \
'./test/instrumentation' \
"$@"
} }
red=$(tput setaf 1) red=$(tput setaf 1)
green=$(tput setaf 2) green=$(tput setaf 2)
reset=$(tput sgr0) reset=$(tput sgr0)
kube::validate::stablemetrics() { function kube::validate::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doValidate=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | grep -v ".git" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doValidate=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if $doValidate; then if $doValidate; then
echo -e "${green}Diffing test/instrumentation/testdata/stable-metrics-list.yaml\n${reset}" echo -e "${green}Diffing test/instrumentation/testdata/stable-metrics-list.yaml\n${reset}"
@ -74,10 +84,20 @@ kube::validate::stablemetrics() {
exit 1 exit 1
} }
kube::validate::test::stablemetrics() { function kube::validate::test::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doValidate=$(find_test_files | grep -E ".*.go" | grep -v ".*_test.go" | grep -v ".git" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doValidate=$(find_test_files -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if $doValidate; then if $doValidate; then
echo -e "${green}Diffing test/instrumentation/testdata/test-stable-metrics-list.yaml\n${reset}" echo -e "${green}Diffing test/instrumentation/testdata/test-stable-metrics-list.yaml\n${reset}"
@ -92,10 +112,21 @@ kube::validate::test::stablemetrics() {
exit 1 exit 1
} }
kube::update::stablemetrics() { function kube::update::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}")
doCheckStability=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2
@ -105,10 +136,21 @@ kube::update::stablemetrics() {
echo "${green}Updated golden list of stable metrics.${reset}" echo "${green}Updated golden list of stable metrics.${reset}"
} }
kube::update::documentation::list() { function kube::update::documentation::list() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" --allstabilityclasses -- 1>"${temp_file}") doCheckStability=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
--allstabilityclasses \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2
@ -118,7 +160,7 @@ kube::update::documentation::list() {
echo "${green}Updated list of metrics for documentation ${reset}" echo "${green}Updated list of metrics for documentation ${reset}"
} }
kube::update::documentation() { function kube::update::documentation() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
arg1=$1 arg1=$1
@ -132,10 +174,20 @@ kube::update::documentation() {
echo "${green}Updated documentation of metrics.${reset}" echo "${green}Updated documentation of metrics.${reset}"
} }
kube::update::test::stablemetrics() { function kube::update::test::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_test_files | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doCheckStability=$(find_test_files -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of test metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of test metrics has failed! ${reset}" >&2
@ -144,4 +196,3 @@ kube::update::test::stablemetrics() {
mv -f "$temp_file" "${KUBE_ROOT}/test/instrumentation/testdata/test-stable-metrics-list.yaml" mv -f "$temp_file" "${KUBE_ROOT}/test/instrumentation/testdata/test-stable-metrics-list.yaml"
echo "${green}Updated test list of stable metrics.${reset}" echo "${green}Updated test list of stable metrics.${reset}"
} }