Skip to content

Commit

Permalink
[QA][Code Coverage] follow up pr for ftr auto config handling & fix m…
Browse files Browse the repository at this point in the history
…erge (#131734)

* [QA][Code Coverage] fixup for auto config handling pr

## Summary

Embed buildkite pipeline definition.

Follow up pr to change cc per auto config handling.
Also, resolves #132706

Increase worker count for `node scripts/build_kibana_platform_plugins` to 4 workers.

Normalize file names within coverage files such that nyc correctly builds the combined summaries.
  _Ci runs this on myriad servers, so the paths are different, which "breaks" nyc's output_

Split the final merge of functional coverage into 2 passes due to [nyc issue](istanbuljs/nyc#1263)

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
wayneseymour and kibanamachine committed May 27, 2022
1 parent e310b20 commit 5f950e6
Show file tree
Hide file tree
Showing 16 changed files with 476 additions and 158 deletions.
30 changes: 30 additions & 0 deletions .buildkite/pipelines/code_coverage/daily.yml
@@ -0,0 +1,30 @@
steps:
- command: .buildkite/scripts/lifecycle/pre_build.sh
label: Pre-Build
timeout_in_minutes: 10
agents:
queue: kibana-default

- wait

- command: .buildkite/scripts/steps/test/pick_test_group_run_order.sh
label: 'Pick Test Group Run Order'
agents:
queue: kibana-default
env:
FTR_CONFIGS_DEPS: ''
LIMIT_CONFIG_TYPE: 'unit,functional,integration'
JEST_UNIT_SCRIPT: '.buildkite/scripts/steps/code_coverage/jest.sh'
JEST_INTEGRATION_SCRIPT: '.buildkite/scripts/steps/code_coverage/jest_integration.sh'
FTR_CONFIGS_SCRIPT: '.buildkite/scripts/steps/code_coverage/ftr_configs.sh'

- command: .buildkite/scripts/steps/code_coverage/ingest.sh
label: 'Merge and Ingest'
agents:
queue: c2-16
depends_on:
- jest
- jest-integration
- ftr-configs
timeout_in_minutes: 30
key: ingest
14 changes: 14 additions & 0 deletions .buildkite/scripts/steps/code_coverage/clean_coverage_paths.js
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const { readFileSync, writeFileSync } = require('fs');

const file = process.argv[2];
const search = process.argv[3];
const replace = process.argv[4];
writeFileSync(file, readFileSync(file).toString().replaceAll(search, replace));
122 changes: 122 additions & 0 deletions .buildkite/scripts/steps/code_coverage/ftr_configs.sh
@@ -0,0 +1,122 @@
#!/usr/bin/env bash

set -euo pipefail

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

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

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

functionalTarget="$KIBANA_DIR/target/kibana-coverage/functional"
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 | .[]' ftr_run_order.json)
fi

echo "--- Config(s) for this FTR Group:"
echo "${configs[@]}"

failedConfigs=""
results=()

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

start=$(date +%s)

# prevent non-zero exit code from breaking the loop
set +e
runFTRInstrumented "$config"
lastCode=$?
set -e
dasherize() {
local withoutExtension=${1%.*}
dasherized=$(echo "$withoutExtension" | tr '\/' '\-')
}
dasherize "$config"

if [[ -d "$functionalTarget" ]]; then
echo "--- Server and / or Client side code coverage collected"
if [[ -f "target/kibana-coverage/functional/coverage-final.json" ]]; then
# We potentially have more than one file with the same name being created,
# so we make them unique here.
mv target/kibana-coverage/functional/coverage-final.json "target/kibana-coverage/functional/${dasherized}-server-coverage.json"
fi
fi

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

echo "--- Config complete: $config"
done <<<"$configs"

# Each browser unload event, creates a new coverage file.
# So, we merge them here.
if [[ -d "$functionalTarget" ]]; then
reportMergeFunctional
uniqueifyFunctional "$(date +%s)"
else
echo "--- Code coverage not found in: $functionalTarget"
fi

# Nyc uses matching absolute paths for reporting / merging
# So, set all coverage json files to a specific prefx.
# The prefix will be changed to the kibana dir, in the final stage,
# so nyc doesnt error.
echo "--- Normalize file paths prefix"
replacePaths "$KIBANA_DIR/target/kibana-coverage/functional" "$KIBANA_DIR" "CC_REPLACEMENT_ANCHOR"

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

echo "--- FTR configs complete, result(s):"
printf "%s\n" "${results[@]}"
echo ""

# So the last step "knows" this config ran
uploadRanFile "ftr_configs"

# Force exit 0 to ensure the next build step starts.
exit 0
43 changes: 27 additions & 16 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,43 @@ echo "--- Upload new git sha"
.buildkite/scripts/steps/code_coverage/reporting/uploadPrevSha.sh

.buildkite/scripts/bootstrap.sh
echo "--- Download coverage arctifacts"

echo "--- Download coverage artifacts"
buildkite-agent artifact download target/kibana-coverage/jest/* .
buildkite-agent artifact download target/kibana-coverage/functional/* .
buildkite-agent artifact download target/ran_files/* .
ls -l target/ran_files/* || echo "### No ran-files found"

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"
echo "--- Jest: Reset file paths prefix, merge coverage files, and generate the final combined report"
# Jest: Reset file paths prefix to Kibana Dir of final worker
replacePaths "$KIBANA_DIR/target/kibana-coverage/jest" "CC_REPLACEMENT_ANCHOR" "$KIBANA_DIR"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js

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
echo "--- Functional: Reset file paths prefix, merge coverage files, and generate the final combined report"
# Functional: Reset file paths prefix to Kibana Dir of final worker
set +e
sed -ie "s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json
echo "--- Begin Split and Merge for Functional"
splitCoverage target/kibana-coverage/functional
splitMerge
set -e

# archive reports to upload as build artifacts
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'
collectAndUpload target/kibana-coverage/jest/kibana-jest-coverage.tar.gz \
target/kibana-coverage/jest-combined
collectAndUpload 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'
10 changes: 3 additions & 7 deletions .buildkite/scripts/steps/code_coverage/jest.sh
Expand Up @@ -3,18 +3,14 @@
set -euo pipefail

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

is_test_execution_step

.buildkite/scripts/bootstrap.sh

echo '--- Jest code coverage'

.buildkite/scripts/steps/code_coverage/jest_parallel.sh jest.config.js

tar -czf kibana-jest-thread-coverage.tar.gz target/kibana-coverage/jest

echo "--- Merging code coverage for a thread"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js --reporter json
rm -rf target/kibana-coverage/jest/*
mv target/kibana-coverage/jest-combined/coverage-final.json "target/kibana-coverage/jest/jest-merged-coverage-$(date +%s%3N).json"
# So the last step "knows" this config ran
uploadRanFile "jest"
9 changes: 7 additions & 2 deletions .buildkite/scripts/steps/code_coverage/jest_integration.sh
Expand Up @@ -3,11 +3,16 @@
set -euo pipefail

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

is_test_execution_step

.buildkite/scripts/bootstrap.sh

JOB=${BUILDKITE_PARALLEL_JOB:-0}

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"
.buildkite/scripts/steps/code_coverage/jest_parallel.sh jest.integration.config.js

# So the last step "knows" this config ran
uploadRanFile "jest_integration"

0 comments on commit 5f950e6

Please sign in to comment.