logstash icon indicating copy to clipboard operation
logstash copied to clipboard

Backport PR #15810 to 8.12: [CI] Send Java and ruby tests to sonarqube simultaneously

Open github-actions[bot] opened this issue 1 year ago • 2 comments

Backport PR #15810 to 8.12 branch, original message:


What does this PR do?

Makes the CI pipeline to Generate coverage reports for Java and Ruby tests Introduces an additional step to publish both tests results to SonarQube Enables coverage thresholds

Code coverage measurement for pull requests

Now we measure coverage of new code on each pull request. It shows whether newly added lines are covered or not. Example: I changed 2 ruby and 2 java files by adding lines outputting a "HEYA!" message. Only changed files are listed in the code coverage analisys: Screenshot 2024-01-16 at 14 16 27

logstash-core/lib/logstash/codecs/base.rb shows 0% coverage and Uncovered Lines on New Code: 2. That's because I added 2 lines puts('HEYA!') and both are not covered by existing tests.

logstash-core/src/main/java/org/logstash/Javafier.java shows 50% coverage and Uncovered Lines on New Code: 1. There are also 2 new lines. And 1 of them is covered by an existing test and the other line is not covered. Ideally we need to cover it by a test.

It also shows 14.3% coverage for the new code. That means my newly added HEYA! lines are covered by 14.3%.

If we open logstash-core/src/main/java/org/logstash/Javafier.java in Sonarqube for further details we can find the uncovered new line:

Screenshot 2024-01-16 at 14 21 21

Code coverage threshold(s)

We can set a quality gate for coverage of new code or entire project. There's also an assigned quality gate for Logstash.

The gate also watches the maintainability level using sonar lint and it expects it to be at least A.

Screenshot 2024-01-16 at 14 36 23

But in fact we achieved only C, hence we can see a comment from sonarqube: Screenshot 2024-01-16 at 14 37 02

And the PR merge is blocked.

If we change the required maintainability level to C - the PR checks will pass

Screenshot 2024-01-16 at 15 18 04

Checklist

  • [ ] My code follows the style guidelines of this project
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • [ ] I have added tests that prove my fix is effective or that my feature works

Related issues

  • Closes https://github.com/elastic/ingest-dev/issues/2408

github-actions[bot] avatar Jan 18 '24 13:01 github-actions[bot]

Quality Gate passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No Coverage information No data about Coverage
No Duplication information No data about Duplication

See analysis details on SonarQube

elastic-sonarqube[bot] avatar Jan 18 '24 14:01 elastic-sonarqube[bot]