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

[improve][CI] Generate unit test code coverage reports and upload to Codecov #17382

Merged
merged 12 commits into from
Oct 11, 2022
Merged

[improve][CI] Generate unit test code coverage reports and upload to Codecov #17382

merged 12 commits into from
Oct 11, 2022

Conversation

yaalsn
Copy link
Contributor

@yaalsn yaalsn commented Sep 1, 2022

Motivation

Add code coverage to make sure good quality of PRs. Although unit tests run in different runners, by using Codecov the coverage XML reports can be aggregated automately.

We can add the coverage to take a look first and then adjust the rule of coverage.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

Check the box below or label this PR directly.

Need to update docs?

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

Matching PR in forked repository

PR in forked repository: https://github.com/yaalsn/pulsar/pull/7

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Sep 1, 2022
@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 1, 2022

https://github.com/codecov/sourcegraph-codecov/blob/master/README.md This Chrome ext can show code coverage information from Codecov on GitHub directly which means no need to jump to Codecov to take look.

@tisonkun
Copy link
Member

tisonkun commented Sep 1, 2022

@yaalsn can you share the report of Pulsar right now? I'm afraid that we just add one more workflow while no one cares about it especially when the result is overwhelming all consumers.

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 1, 2022

@tisonkun Thanks for your reminder.

https://app.codecov.io/gh/apache/pulsar/tree/add-code-coverage This is this PR's coverage report, and Codecov will comment a message to this PR's body after the CI uploads the report.

Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

LGTM

@nodece nodece added the area/ci label Sep 1, 2022
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

It's a significant change to run Pulsar CI every commit on master. Comments inline.

Except that, the new steps take a few seconds to complete. I'm +0 to introduce it. Although, I'd say I never read a coverage report and don't find it helpful. If anyone who gets benefit from such a report instead of be bothered, please let me know (how).

@@ -25,6 +25,7 @@ on:
push:
branches:
- branch-*
- master
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should run tests for every commit on the master. If you want to generate a codecov report every day, you may schedule a daily cron job. Anyway, this is a significant change to the CI workflow.

cc @codelipenghui @lhotari

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, for each PR, we should only generate the codecov report for the new changes. I'm not sure does codecov can support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't find any configuration on report for the new changes except require_changes in comment selection and patch in coverage/status section, but It seems they are not what @codelipenghui wants. Could you help to take a look again?

https://docs.codecov.com/docs/codecovyml-reference

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

I started the same work a couple of months ago here #14600 - my pull is no more valid because I did with the old CI
but I suggest you to add the jacoco config file (see my pull) and I will close mine

Also we need to discuss it on dev@
we need to document why it's important, how to see it and what are the future plans.
That was my thread discussion https://lists.apache.org/thread/o002mmb85jf2948ffq0fsgmg3cvbmh64

you can start replying to that

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Thank you for your initiative @yaalsn !

I agree with @tisonkun and with @nicoloboschi
we should discuss on dev@ and if the community really wants to go this path we must define a work flow.

I have seen (and also promoted) a few times to add Codecov or other similar tools in other OSS projects.
it is pretty hard to make it useful, especially with big projects like Pulsar.

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 15, 2022

I added some configuration to codecov.yml in my repo's pulsar because of the apache/pulsar's runner resources lacking. This is the result: https://github.com/yaalsn/pulsar/pull/11

  1. We can get the uncovered part from Files Changed

image

  1. The coverage and impacted files general information in comment

image

  1. Status check in action check, but it doesn't block the merge even if the coverage down

image

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 15, 2022

@tisonkun @nicoloboschi Could you take a look at the coverage data again? It looks good to me, what do you think?

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Rest LGTM. Since it doesn't affect the CI workload a lot, it's OK we fire the gun and give this report a try.

pom.xml Outdated
Comment on lines 1960 to 1957
<outputDirectory>target/report</outputDirectory>
<excludes>
<exclude>**/*.jar</exclude>
</excludes>
Copy link
Member

Choose a reason for hiding this comment

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

Why do you make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just need to scan class file code coverage not jar files'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And it may lead to some error if we scan the jar files.

codecov.yml Outdated Show resolved Hide resolved
@tisonkun
Copy link
Member

@yaalsn interesting. The result seems not quite correct or useful.

@tisonkun
Copy link
Member

image

And it seems quite noisy. Perhaps some settings are incorrect.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2022

Codecov Report

❗ No coverage uploaded for pull request base (master@2b9ffac). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #17382   +/-   ##
=========================================
  Coverage          ?   45.92%           
  Complexity        ?    17525           
=========================================
  Files             ?     1569           
  Lines             ?   127638           
  Branches          ?    14038           
=========================================
  Hits              ?    58614           
  Misses            ?    63028           
  Partials          ?     5996           
Flag Coverage Δ
unittests 45.92% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 15, 2022

@yaalsn interesting. The result seems not quite correct or useful.

@tisonkun Because there are some flaky tests, and if the job run success, the result will be different. If we want to turn off the email notification, we need to disable the comment from codecov too.

Another way is to change the behaviour to default, and it will send a email at the first time. (but it is not the final result)

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 15, 2022

/pulsarbot rerun-failure-checks

3 similar comments
@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 16, 2022

/pulsarbot rerun-failure-checks

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 18, 2022

/pulsarbot rerun-failure-checks

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 19, 2022

/pulsarbot rerun-failure-checks

@nodece
Copy link
Member

nodece commented Sep 19, 2022

Hi @yaalsn, the CI looks broken, we should rerun all jobs.

Error: Failed to execute goal on project pulsar-all-docker-image: Could not resolve dependencies for project org.apache.pulsar:pulsar-all-docker-image:pom:2.11.0-SNAPSHOT: The following artifacts could not be resolved: org.apache.pulsar:pulsar-io-distribution:pom:2.11.0-SNAPSHOT, org.apache.pulsar:pulsar-offloader-distribution:tar.gz:bin:2.11.0-SNAPSHOT: org.apache.pulsar:pulsar-io-distribution:pom:2.11.0-SNAPSHOT was not found in https://repository.apache.org/snapshots during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of apache.snapshots has elapsed or updates are forced -> [Help 1]

@yaalsn yaalsn closed this Sep 19, 2022
@yaalsn yaalsn reopened this Sep 19, 2022
@yaalsn yaalsn closed this Sep 20, 2022
@yaalsn yaalsn reopened this Sep 21, 2022
@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 21, 2022

/pulsarbot rerun-failure-checks

@yaalsn
Copy link
Contributor Author

yaalsn commented Sep 21, 2022

/pulsarbot rerun-failure-checks

@@ -129,7 +129,7 @@ function test_group_proxy() {

function test_group_other() {
mvn_test --clean --install \
-pl '!org.apache.pulsar:distribution,!org.apache.pulsar:pulsar-offloader-distribution,!org.apache.pulsar:pulsar-server-distribution,!org.apache.pulsar:pulsar-io-distribution' \
-pl '!org.apache.pulsar:distribution,!org.apache.pulsar:pulsar-offloader-distribution,!org.apache.pulsar:pulsar-server-distribution,!org.apache.pulsar:pulsar-io-distribution,!org.apache.pulsar:pulsar-all-docker-image' \
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

If we don't exclude org.apache.pulsar:pulsar-all-docker-image, then there will appear this error.

Copy link
Member

Choose a reason for hiding this comment

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

Although I think it's something related to network, it does no harm to exclude org.apache.pulsar:pulsar-all-docker-image in test_group_other.

@codelipenghui
Copy link
Contributor

@tisonkun @nicoloboschi @eolivelli Could you please help review this PR again?

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

Good to go :)

@@ -129,7 +129,7 @@ function test_group_proxy() {

function test_group_other() {
mvn_test --clean --install \
-pl '!org.apache.pulsar:distribution,!org.apache.pulsar:pulsar-offloader-distribution,!org.apache.pulsar:pulsar-server-distribution,!org.apache.pulsar:pulsar-io-distribution' \
-pl '!org.apache.pulsar:distribution,!org.apache.pulsar:pulsar-offloader-distribution,!org.apache.pulsar:pulsar-server-distribution,!org.apache.pulsar:pulsar-io-distribution,!org.apache.pulsar:pulsar-all-docker-image' \
Copy link
Member

Choose a reason for hiding this comment

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

Although I think it's something related to network, it does no harm to exclude org.apache.pulsar:pulsar-all-docker-image in test_group_other.

Comment on lines -1955 to +1957
<outputDirectory>target/report</outputDirectory>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
Copy link
Member

Choose a reason for hiding this comment

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

I don't know the reason you made this change. Could you explain it a bit @yaalsn?

The last time you changed to **/*.jar and now a new change, we need some background here.

However, given that the CI result looks good, I assume this change is OK.

Copy link
Contributor Author

@yaalsn yaalsn Oct 10, 2022

Choose a reason for hiding this comment

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

@tisonkun You can take a look at this one. Third-party classes and jars are in target/META-INF path and may lead to some errors, so we need to exlude this path.

Copy link
Member

Choose a reason for hiding this comment

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

@yaalsn Thank you. One more question: why remove <outputDirectory>target/report</outputDirectory>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tisonkun Because I think the default value makes sense: target/jacoco directory means jacoco reports but target/report means multi kinds of reports.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tisonkun Thanks for your comments! I think all the questions are very good which I met during this PR, others see the discussion can know clearly about these.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci doc-not-needed Your PR changes do not impact docs ready-to-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants