Add periodic etcd scraping to integration tests

.. to help understand where and why things go bad.
This commit is contained in:
Mike Spreitzer 2021-11-05 19:58:48 +00:00
parent cb040e5097
commit dc07025470
2 changed files with 31 additions and 0 deletions

View File

@ -91,7 +91,35 @@ kube::etcd::start() {
curl -fs -X POST "${KUBE_INTEGRATION_ETCD_URL}/v3/kv/put" -d '{"key": "X3Rlc3Q=", "value": ""}'
}
kube::etcd::start_scraping() {
if [[ -d "${ARTIFACTS:-}" ]]; then
ETCD_SCRAPE_DIR="${ARTIFACTS}/etcd-scrapes"
else
ETCD_SCRAPE_DIR=$(mktemp -d -t test-etcd-scrapes.XXXXXX)
fi
kube::log::info "Periodically scraping etcd to ${ETCD_SCRAPE_DIR} ."
mkdir -p "${ETCD_SCRAPE_DIR}"
(
while sleep 30; do
kube::etcd::scrape
done
) &
ETCD_SCRAPE_PID=$!
}
kube::etcd::scrape() {
curl -s -S "${KUBE_INTEGRATION_ETCD_URL}/metrics" > "${ETCD_SCRAPE_DIR}/next" && mv "${ETCD_SCRAPE_DIR}/next" "${ETCD_SCRAPE_DIR}/$(date +%H%M%S).scrape"
}
kube::etcd::stop() {
if [[ -n "${ETCD_SCRAPE_PID:-}" ]]; then
kill "${ETCD_SCRAPE_PID}" &>/dev/null || :
wait "${ETCD_SCRAPE_PID}" &>/dev/null || :
kube::etcd::scrape || :
# shellcheck disable=SC2015
tar czf "${ETCD_SCRAPE_DIR}/scrapes.tgz" "${ETCD_SCRAPE_DIR}"/*.scrape && rm "${ETCD_SCRAPE_DIR}"/*.scrape || :
fi
if [[ -n "${ETCD_PID-}" ]]; then
kill "${ETCD_PID}" &>/dev/null || :
wait "${ETCD_PID}" &>/dev/null || :

View File

@ -64,6 +64,9 @@ runTests() {
kube::log::status "Starting etcd instance"
CLEANUP_REQUIRED=1
kube::etcd::start
# shellcheck disable=SC2034
local ETCD_SCRAPE_PID # Set in kube::etcd::start_scraping, used in cleanup
kube::etcd::start_scraping
kube::log::status "Running integration test cases"
make -C "${KUBE_ROOT}" test \