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

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

Open
wants to merge 1 commit into
base: 8.12
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

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

* Ruby code coverage with SimpleCov json formatter

* [CI] Send Java and ruby tests to sonarqube simultaneously

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Enabled COVERAGE for ruby tests

* Added compiled classes to artifacts

* Test change

* Removed test changes

* Returned back ENABLE_SONARQUBE condition

* Removed debug line

* Diable Ruby coverage if ENABLE_SONARQUBE is not true

* Run sonar scan on pull requests and onn push to main

* Run sonar can on release branches

(cherry picked from commit 2c83a52)
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants