Merge pull request #106190 from MikeSpreitzer/integration-scrape-etcd

Add periodic etcd scraping to integration tests
This commit is contained in:
Kubernetes Prow Robot
2021-11-09 15:30:38 -08:00
committed by GitHub
4 changed files with 200 additions and 0 deletions

View File

@@ -91,7 +91,39 @@ 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.XXXXXX)/etcd-scrapes
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 +%s).scrape"
}
kube::etcd::stop() {
if [[ -n "${ETCD_SCRAPE_PID:-}" ]] && [[ -n "${ETCD_SCRAPE_DIR:-}" ]] ; then
kill "${ETCD_SCRAPE_PID}" &>/dev/null || :
wait "${ETCD_SCRAPE_PID}" &>/dev/null || :
kube::etcd::scrape || :
(
# shellcheck disable=SC2015
cd "${ETCD_SCRAPE_DIR}"/.. && \
tar czf etcd-scrapes.tgz etcd-scrapes && \
rm -rf etcd-scrapes || :
)
fi
if [[ -n "${ETCD_PID-}" ]]; then
kill "${ETCD_PID}" &>/dev/null || :
wait "${ETCD_PID}" &>/dev/null || :