verify-stable-metrics.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # Copyright 2019 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o pipefail
  17. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
  18. BAZEL_OUT_DIR="$KUBE_ROOT/bazel-bin"
  19. BAZEL_GEN_DIR="$KUBE_ROOT/bazel-genfiles"
  20. METRICS_LIST_PATH="test/instrumentation/stable-metrics-list.yaml"
  21. # detect if run from bazel
  22. if [ -z "${TEST_BINARY}" ]; then
  23. bazel build //test/instrumentation:list_stable_metrics
  24. if [ -d "$BAZEL_OUT_DIR" ]; then
  25. OUTPUT_FILE="$BAZEL_OUT_DIR/$METRICS_LIST_PATH"
  26. else
  27. # Handle bazel < 0.25
  28. # https://github.com/bazelbuild/bazel/issues/6761
  29. OUTPUT_FILE="$BAZEL_GEN_DIR/$METRICS_LIST_PATH"
  30. fi
  31. else
  32. OUTPUT_FILE="$KUBE_ROOT/$METRICS_LIST_PATH"
  33. fi
  34. if diff -u "$KUBE_ROOT/test/instrumentation/testdata/stable-metrics-list.yaml" "$OUTPUT_FILE"; then
  35. echo PASS
  36. exit 0
  37. fi
  38. echo 'Diffs in stable metrics detected, please run "test/instrumentation/update-stable-metrics.sh"'
  39. exit 1