Skip to content

Commit

Permalink
[QA][Code Coverage] fixup for auto config handling
Browse files Browse the repository at this point in the history
Add support for automatic ftr config groups.
Add dasherize fn for unique names.
Bump pipeline lib version.
Force exit 0 to continue pipeline, so ingestion always happens.
Add dasherize fn for unique names
Split merge into two passes.
Add debugging utility fns.
  • Loading branch information
wayneseymour committed May 23, 2022
1 parent a487d7c commit 825b7fd
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 204 deletions.
63 changes: 8 additions & 55 deletions .buildkite/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .buildkite/package.json
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"kibana-buildkite-library": "git+https://git@github.com/elastic/kibana-buildkite-library#ae4994aba5f2e72edcc5914e2aa208086e4b7ea3"
"kibana-buildkite-library": "git+https://git@github.com/elastic/kibana-buildkite-library#a5010e2b33291290dc45d2c0013b5d5646fbfa09"
}
}
@@ -0,0 +1,6 @@
const { readFileSync, writeFileSync } = require('fs');
const FILE = process.argv[2];
console.log(`\n### process.env.KIBANA_DIR: \n\t${process.env.KIBANA_DIR}`);
console.log(`\n\t### Replacing paths in: \n\t${FILE}`);
// TODO-TRE: Drop hardcoded replacement
writeFileSync(FILE, readFileSync(FILE).toString().replaceAll(process.env.KIBANA_DIR, 'LEETRE'));
139 changes: 139 additions & 0 deletions .buildkite/scripts/steps/code_coverage/ftr_configs.sh
@@ -0,0 +1,139 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/common/util.sh
source .buildkite/scripts/steps/code_coverage/util.sh

export CODE_COVERAGE=1 # Kibana is bootstrapped differently for code coverage
echo "--- Print KIBANA_DIR"
echo "### KIBANA_DIR: $KIBANA_DIR"
.buildkite/scripts/bootstrap.sh

echo "--- Build Platform Plugins"
NODE_OPTIONS=--max_old_space_size=14336 node scripts/build_kibana_platform_plugins \
--no-examples --test-plugins --workers 4

is_test_execution_step

export JOB_NUM=$BUILDKITE_PARALLEL_JOB
export JOB=ftr-configs-${JOB_NUM}

FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${BUILDKITE_PARALLEL_JOB:-0}"

# a FTR failure will result in the script returning an exit code of 10
exitCode=0

configs="${FTR_CONFIG:-}"

if [[ "$configs" == "" ]]; then
echo "--- downloading ftr test run order"
buildkite-agent artifact download ftr_run_order.json .
# configs=$(jq -r '.groups[env.JOB_NUM | tonumber].names | first' ftr_run_order.json)
configs=$(jq -r '.groups[env.JOB_NUM | tonumber].names | .[]' ftr_run_order.json)
fi

echo "### Configs"
echo $configs

failedConfigs=""
results=()

while read -r config; do
if [[ ! "$config" ]]; then
continue
fi

echo "--- Print config name"
echo "### config: $config"

echo "--- $ node scripts/functional_tests --config $config --exclude-tag ''skipCoverage''"
start=$(date +%s)

# prevent non-zero exit code from breaking the loop
set +e
NODE_OPTIONS=--max_old_space_size=16384 \
./node_modules/.bin/nyc \
--nycrc-path ./src/dev/code_coverage/nyc_config/nyc.server.config.js \
node scripts/functional_tests \
--config="$config" \
--exclude-tag "skipCoverage"
lastCode=$?
set -e

dasherize() {
withoutExtension=${1%.*}
dasherized=$(echo "$withoutExtension" | tr '\/' '\-')
}
dasherize $config

if [[ -d "$KIBANA_DIR/target/kibana-coverage/functional" ]]; then
echo "--- Server and / or Client side code coverage collected"
if [[ -f "target/kibana-coverage/functional/coverage-final.json" ]]; then
mv target/kibana-coverage/functional/coverage-final.json "target/kibana-coverage/functional/${dasherized}-server-coverage.json"
fi
fi
# echo "--- Replace paths in configs loop, for SERVER COVERAGE"
# replacePaths "$KIBANA_DIR/target/kibana-coverage/functional"

timeSec=$(($(date +%s) - start))
if [[ $timeSec -gt 60 ]]; then
min=$((timeSec / 60))
sec=$((timeSec - (min * 60)))
duration="${min}m ${sec}s"
else
duration="${timeSec}s"
fi

results+=("- $config
duration: ${duration}
result: ${lastCode}")

if [ $lastCode -ne 0 ]; then
exitCode=10
echo "FTR exited with code $lastCode"
echo "^^^ +++"

if [[ "$failedConfigs" ]]; then
failedConfigs="${failedConfigs}"$'\n'"$config"
else
failedConfigs="$config"
fi
fi

dirListing "target/dir-listing-$dasherized.txt" target/kibana-coverage/functional
done <<<"$configs"

#dirListing "target/dir-listing-functional-post-loop.txt" target/kibana-coverage/functional
#fileHeads "target/file-heads-functional-post-loop.txt" target/kibana-coverage/functional

# Each browser unload event, creates a new coverage file.
# So, we merge them here.
if [[ -d "$KIBANA_DIR/target/kibana-coverage/functional" ]]; then
echo "--- Merging code coverage for FTR Configs"
NODE_OPTIONS=--max_old_space_size=16384 yarn nyc report \
--nycrc-path src/dev/code_coverage/nyc_config/nyc.functional.config.js --reporter json
rm -rf target/kibana-coverage/functional/*
mv target/kibana-coverage/functional-combined/coverage-final.json \
"target/kibana-coverage/functional/$(date +%s)-coverage-final.json"
else
echo "--- Code coverage not found in: $KIBANA_DIR/target/kibana-coverage/functional"
fi

#dirListing "target/dir-listing-functional-post-merge.txt" target/kibana-coverage/functional
#fileHeads "target/file-heads-functional-post-merge-before-replace.txt" target/kibana-coverage/functional

echo "--- Replace paths OUTSIDE OF configs loop, FOR FUNCTIONAL COVERAGE"
replacePaths "$KIBANA_DIR/target/kibana-coverage/functional"
#fileHeads "target/file-heads-functional-after-replace.txt" target/kibana-coverage/functional

if [[ "$failedConfigs" ]]; then
buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "$failedConfigs"
fi

echo "--- FTR configs complete"
printf "%s\n" "${results[@]}"
echo ""

# Force exit 0 to ensure the next build step starts.
exit 0
57 changes: 44 additions & 13 deletions .buildkite/scripts/steps/code_coverage/ingest.sh
Expand Up @@ -3,6 +3,8 @@
set -euo pipefail

source .buildkite/scripts/common/util.sh
source .buildkite/scripts/steps/code_coverage/util.sh
source .buildkite/scripts/steps/code_coverage/merge.sh

export CODE_COVERAGE=1
echo "--- Reading Kibana stats cluster creds from vault"
Expand All @@ -11,6 +13,9 @@ export PASS_FROM_VAULT="$(retry 5 5 vault read -field=password secret/kibana-iss
export HOST_FROM_VAULT="$(retry 5 5 vault read -field=host secret/kibana-issues/prod/coverage/elasticsearch)"
export TIME_STAMP=$(date +"%Y-%m-%dT%H:%M:00Z")

echo "--- Print KIBANA_DIR"
echo "### KIBANA_DIR: $KIBANA_DIR"

echo "--- Download previous git sha"
.buildkite/scripts/steps/code_coverage/reporting/downloadPrevSha.sh
previousSha=$(cat downloaded_previous.txt)
Expand All @@ -19,37 +24,63 @@ echo "--- Upload new git sha"
.buildkite/scripts/steps/code_coverage/reporting/uploadPrevSha.sh

.buildkite/scripts/bootstrap.sh

echo "--- Download coverage arctifacts"
buildkite-agent artifact download target/kibana-coverage/jest/* .

#dirListing "target/dir-listing-jest.txt" target/kibana-coverage/jest

buildkite-agent artifact download target/kibana-coverage/functional/* .
#dirListing "target/dir-listing-functional-after-download.txt" target/kibana-coverage/functional
#fileHeads "target/file-heads-functional-after-download.txt" target/kibana-coverage/functional

echo "--- process HTML Links"
.buildkite/scripts/steps/code_coverage/reporting/prokLinks.sh

echo "--- collect VCS Info"
.buildkite/scripts/steps/code_coverage/reporting/collectVcsInfo.sh

# replace path in json files and generate final reports
echo "--- Replace path in json files"
export COVERAGE_TEMP_DIR=$KIBANA_DIR/target/kibana-coverage
sed -i "s|/opt/local-ssd/buildkite/builds/kb-[[:alnum:]\-]\{20,27\}/elastic/kibana-code-coverage-main/kibana|${KIBANA_DIR}|g" $COVERAGE_TEMP_DIR/**/*.json

echo "--- Jest: merging coverage files and generating the final combined report"
#dirListing "target/dir-listing-jest-just-before-final-replace.txt" target/kibana-coverage/jest
echo "--- Final replace for jest"
replacePaths target/kibana-coverage/jest
#dirListing "target/dir-listing-jest-after-final-replace.txt" target/kibana-coverage/jest
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js
#dirListing "target/dir-listing-jest-after-report-merge.txt" target/kibana-coverage/jest-combined

echo "--- Functional: merging json files and generating the final combined report"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.functional.config.js

# archive reports to upload as build artifacts
set +e
echo "--- Final replace for functional"
#fileHeads "target/file-heads-functional-before-final-replace.txt" target/kibana-coverage/functional
#collect target/collect-functional-before-final-replace.tar.gz target/kibana-coverage/functional

#replacePaths target/kibana-coverage/functional
echo "### KIBANA_DIR: $KIBANA_DIR"
sed -ie "s|LEETRE|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json

#collect target/collect-functional-after-final-replace.tar.gz target/kibana-coverage/functional
#fileHeads "target/file-heads-functional-after-final-replace.txt" target/kibana-coverage/functional
#dirListing "target/dir-listing-functional-after-final-replace.txt" target/kibana-coverage/functional

echo "--- Begin Split and Merge"
splitCoverage target/kibana-coverage/functional
#dirListing "target/dir-listing-functional-after-splitCoverage.txt" target/kibana-coverage/functional
# splitMerge drops its result into: target/kibana-coverage/functional-combined
splitMerge
#dirListing "target/dir-listing-functional-combined-after-splitMerge.txt" target/kibana-coverage/functional-combined
#fileHeads "target/file-heads-functional-combined-after-splitMerge.txt" target/kibana-coverage/functional-combined
set -e


echo "--- Archive and upload combined reports"
tar -czf target/kibana-coverage/jest/kibana-jest-coverage.tar.gz target/kibana-coverage/jest-combined
tar -czf target/kibana-coverage/functional/kibana-functional-coverage.tar.gz target/kibana-coverage/functional-combined
buildkite-agent artifact upload 'target/kibana-coverage/jest/kibana-jest-coverage.tar.gz'
buildkite-agent artifact upload 'target/kibana-coverage/functional/kibana-functional-coverage.tar.gz'
collect target/kibana-coverage/jest/kibana-jest-coverage.tar.gz target/kibana-coverage/jest-combined
collect target/kibana-coverage/functional/kibana-functional-coverage.tar.gz target/kibana-coverage/functional-combined

echo "--- Upload coverage static site"
.buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh

echo "--- Ingest results to Kibana stats cluster"
.buildkite/scripts/steps/code_coverage/reporting/ingestData.sh 'elastic+kibana+code-coverage' ${BUILDKITE_BUILD_NUMBER} ${BUILDKITE_BUILD_URL} ${previousSha} 'src/dev/code_coverage/ingest_coverage/team_assignment/team_assignments.txt'
.buildkite/scripts/steps/code_coverage/reporting/ingestData.sh 'elastic+kibana+code-coverage' \
${BUILDKITE_BUILD_NUMBER} ${BUILDKITE_BUILD_URL} ${previousSha} \
'src/dev/code_coverage/ingest_coverage/team_assignment/team_assignments.txt'
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/code_coverage/jest_integration.sh
Expand Up @@ -10,4 +10,4 @@ is_test_execution_step

echo '--- Jest Integration code coverage'
node --max-old-space-size=14336 scripts/jest_integration --ci --coverage --coverageReporters json || true
mv target/kibana-coverage/jest/coverage-final.json "target/kibana-coverage/jest/jest-integration-coverage.json"
mv target/kibana-coverage/jest/coverage-final.json "target/kibana-coverage/jest/jest-integration-coverage.json"

0 comments on commit 825b7fd

Please sign in to comment.