Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage setup on CI #49003

Merged
merged 15 commits into from
Jan 8, 2020
Merged

Conversation

dmlemeshko
Copy link
Member

@dmlemeshko dmlemeshko commented Oct 22, 2019

Summary

Integrating code coverage (currently mocha, jest, and functional tests) into our CI
Currently running on Jenkins: kibana-code-coverage job

Details

Build and tests execution part:

  1. The same flow we do in PRs excluding the Kibana build creation (we run functional tests from source)
  2. The optimizer is running with --optimize.useBundleCache=true to reuse cache if it's available and avoid concurrent source modification. However, x-pack ciGroups have different configs and it will force to reoptimize. To solve the issue, x-pack functional tests are executed on 3 workers, not 1.
  3. Coverage is saved as JSON files under target/kibana-coverage/[mocha|jest|functional] path, mocha generates HTML report straight away (no need to merge oss & x-pack results) We archive coverage as kibana-coverage.tar.gz and upload to GCS along with usual tests artifacts.

Jenkins 2019-12-19 12-51-05

Code coverage merging part:

  1. download archives from GCS
  2. bootstrap Kibana from x-pack (it is required for HTML report to have valid links to source code)
  3. extract archives, replace paths in JSON files to match actual KIbana path on worker
  4. merging coverage for jest and functional tests to have oss+x-pack combined report, archive and upload as artifacts:

cov

Combined coverage for mocha, jest and functional tests is provided in 2 formats:

  • json-summary, to push data into build stats ES and monitor coverage within the time period
  • html, to publish as a static web-site on GCS and have quick access

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@dmlemeshko
Copy link
Member Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@dmlemeshko
Copy link
Member Author

/cc @wayneseymour @LeeDr

.ci/Jenkinsfile_coverage Outdated Show resolved Hide resolved
.ci/Jenkinsfile_coverage Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@wayneseymour wayneseymour marked this pull request as ready for review October 23, 2019 17:16
@wayneseymour wayneseymour requested a review from a team as a code owner October 23, 2019 17:16
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@wayneseymour
Copy link
Member

Squash to single commmit, cherry pick this guy ontop of something historical, Like a week prior or so, ....keep iterating over like 10 weeks so we can visualize.

run the reports on like 5 big gce instances to create the reports

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

wayneseymour added a commit to wayneseymour/kibana that referenced this pull request Oct 31, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@spalger
Copy link
Contributor

spalger commented Nov 18, 2019

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@dmlemeshko dmlemeshko added release_note:skip Skip the PR/issue when compiling release notes v8.0.0 labels Nov 20, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@dmlemeshko dmlemeshko added the test-coverage issues & PRs for improving code test coverage label Dec 19, 2019
@elastic elastic deleted a comment from elasticmachine Dec 30, 2019
@dmlemeshko
Copy link
Member Author

@elasticmachine merge upstream

@wayneseymour wayneseymour reopened this Jan 6, 2020
@wayneseymour
Copy link
Member

@dmlemeshko is there no issue with all of the coverage archives having the same name? I noticed it in the image you posted.

'xpack-ciGroup10': kibanaPipeline.getXpackCiGroupWorker(10),
]),
])
kibanaPipeline.jobRunner('tests-l', false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmlemeshko 'tests-l' ==== some large instance for testing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the default one (PRs) has not enough space for coverage processing (25+ GB)

@@ -193,7 +193,7 @@ export default () =>
.default('localhost'),
watchPrebuild: Joi.boolean().default(false),
watchProxyTimeout: Joi.number().default(10 * 60000),
useBundleCache: Joi.boolean().default(Joi.ref('$prod')),
useBundleCache: Joi.boolean().default(!!process.env.CODE_COVERAGE ? true : Joi.ref('$prod')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the schema is the best place to put logic like this...

Actually, do you need to set this at all? It's always set to true here:

buildArgs: ['--optimize.useBundleCache=true'],

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is somehow without setting useBundleCache in a schema, I'm getting flaky tests and maybe it is because we don't make a build, but run tests from the source. This change was also made in discussion with @spalger. If I remove it, tests are started to fail for code coverage runs.

yarn run grunt run:pluginFunctionalTestsRelease --from=source;
yarn run grunt run:exampleFunctionalTestsRelease --from=source;
yarn run grunt run:interpreterFunctionalTestsRelease;
checks-reporter-with-killswitch " Functional tests with code coverage / Group ${CI_GROUP}" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need GitHub checks support? If not, you can just replace these two lines with just yarn run grunt "run:functionalTests_ciGroup${CI_GROUP}";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for the other spots where you have checks-reporter-with-killswitch

node ./legacy/plugins/canvas/scripts/shareable_runtime
checks-reporter-with-killswitch "X-Pack Jest Coverage" node scripts/jest --ci --verbose --coverage
# rename file in order to be unique one
mv ../target/kibana-coverage/jest/coverage-final.json ../target/kibana-coverage/jest/xpack-coverage-final.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a test fails in the above command, will the file still get output? If so, it won't get renamed, because the script will exit when the test fails

kibanaPipeline.jobRunner('tests-l', false) {
kibanaPipeline.downloadCoverageArtifacts()
kibanaPipeline.bash(
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually put scripts that get this long into their own files, e.g. in test/scripts or in .ci... Not required though. You could also change it to ''' instead of """ and you wouldn't need to worry about escaping the $s (since you aren't using interpolation)

@@ -17,12 +17,23 @@
* under the License.
*/

require('../src/setup_node_env');
require('@kbn/test').runTestsCli([
// eslint-disable-next-line no-restricted-syntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would all of these changes feel better as a separate file (e.g. scripts/functional_tests_for_coverage.js or similar)? You'd be able to skip the list combining and eslint disables... I can't decide, just a thought

Copy link
Member Author

@dmlemeshko dmlemeshko Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was in a separate file initially, but I talked to Spencer and made it this way. @spalger is ok or better in an own file?

Copy link
Member

@wayneseymour wayneseymour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, but Brian's comments make sense.

node ./legacy/plugins/canvas/scripts/shareable_runtime
node scripts/jest --ci --verbose --coverage
# rename file in order to be unique one
test -f ../target/kibana-coverage/jest/coverage-final.json \
Copy link
Contributor

@brianseeders brianseeders Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail the build if the file isn't there (because it returns a non-zero exit code), in case that isn't what you want.

Also, you still might have the problem I mentioned before:

If node scripts/jest --ci --verbose --coverage has a test that fails, this script will exit before the rename happens. So, later on, when you expect the file to be called xpack-coverage-final.json, it will be called coverage-final.json. Is this a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if any test will fail coverage-final.json won't be generated. And actually we agreed not to proceed with coverage merging if any tests failed.

So exiting before renaming is fine, build should be red and next step (merge) is not starting. If the tests pass, json file is expected to be generated and I rename it because the json with the same name will be generated for oss jest tests.
During merge step I extract both oss and xpack in the same folder for merging, names should be unique to avoid overwriting.
What do you think is the best solution with context I provided?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just asked @LeeDr and he feels we should not push the coverage data if there's a failure as that will skew the coverage numbers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, just wanted to make sure the file not getting renamed wasn't going to cause a downstream issue!

@dmlemeshko
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dmlemeshko dmlemeshko merged commit 26ce610 into elastic:master Jan 8, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 9, 2020
* master: (23 commits)
  [Vis: Default editor] Reactify the timelion editor (elastic#52990)
  [Discover] fix histogram min interval (elastic#53979)
  [Telemetry] [Monitoring] Only retry fetching usage once monito… (elastic#54309)
  [docs][APM] Add runtime index config documentation (elastic#53907)
  [SIEM] Detection engine timeline (elastic#53783)
  Filter scripted fields preview field list to source fields (elastic#53826)
  Management - New platform api (elastic#52579)
  Reset region and Account when switching inventory (elastic#54287)
  [SIEM] [Case] Case workflow api schema (elastic#51535)
  Code coverage setup on CI (elastic#49003)
  [ML] DF Analytics Results: adds link to docs (elastic#54189)
  Update schemas boolean, byteSize, and duration to coerce strings (elastic#54177)
  [Metrics UI] Pass relevant shouldAllowEdit capabilities into SettingsPage (elastic#49781)
  [Canvas] Fixes bugs with autoplay and refresh (elastic#53149)
  [ML] DF Analytics Classification: ensure confusion matrix can be fetched (elastic#53629)
  Fix Vega react eslint errors (elastic#54259)
  Remove non existing codeowners (elastic#54274)
  use correct type (elastic#54244)
  [Dashboard] Removing 100% as dshDashboardViewport height (elastic#54263)
  add `examples/` to no-restricted-path config (elastic#54252)
  ...
@dmlemeshko
Copy link
Member Author

linking #22221

@dmlemeshko dmlemeshko deleted the code-coverage-on-ci branch March 24, 2020 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes test-coverage issues & PRs for improving code test coverage v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants