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

Announce combined coverage report on the BES #22171

Closed
wants to merge 4 commits into from
Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Apr 29, 2024

This allows BES consumers to access this file without guessing its path and existence, as well as when the actual coverage generation action runs locally.

Also removes an obsolete CoverageReport event.

RELNOTES: The combined coverage report produced via --combined_report=lcov is now announced on the BES via the new CoverageReport event.

@fmeum fmeum requested review from a team, gregestren and fweikert as code owners April 29, 2024 14:03
@fmeum fmeum removed request for a team, gregestren and fweikert April 29, 2024 14:03
@github-actions github-actions bot added team-Configurability Issues for Configurability team team-Remote-Exec Issues and PRs for the Execution (Remote) team team-Documentation Documentation improvements that cannot be directly linked to other team labels awaiting-review PR is awaiting review from an assigned reviewer labels Apr 29, 2024
@fmeum fmeum removed team-Configurability Issues for Configurability team team-Documentation Documentation improvements that cannot be directly linked to other team labels labels Apr 29, 2024
@fmeum
Copy link
Collaborator Author

fmeum commented May 3, 2024

@coeuvre Could you review this?

@michaeledgar
Copy link
Contributor

The feature makes perfect sense and I'm excited to see it submitted! I do think we can implement it without adding a new BEP event type, which is always preferred when possible. In particular, the BuildToolLogs event can be used to report files that contain information collected from the entire build.

Contributing a file to this collection is a bit tricky, but the hooks are there to do this. In general you will extend BazelCoverageReportModule to report this information in the BuildToolLogsCollection.

One roadmap, which is preferred but has a few missing details that you'd need to fill in, is:

  1. In BazelCoverageReportModule, add a new static inner class, strawman name CoverageReportCollector.
  2. Add to CoverageReportCollector a constructor that takes CoverageReportActionsWrapper and stores it in a final field, strawman name coverageActionsWrapper.
  3. Add to CoverageReportCollector a @Subscribe method that takes BuildCompleteEvent that adds the Paths to the BuildToolLogsCollection:
  4. Create the CoverageReportCollector and register it with the EventBus inside the CoverageReportActionFactory#createCoverageReportActionsWrapper() definition, after creating the CoverageReportActionsWrapper but before returning it.
    @Subscribe
    public void buildComplete(BuildCompleteEvent event) {
      var paths = extractCoveragePathsTODO(coverageActionsWrapper);
      for (var path : paths) {
        event
            .getResult()
            .getBuildToolLogCollection()
            .addLocalFile("coverage_report.lcov", path); // reusing the name "coverage_report.lcov" doesn't matter.
      }
    }

    private static Iterable<Path> extractCoveragePathsTODO(CoverageReportActionsWrapper coverageActionsWrapper) {
      return null; // TODO: Fill me in.
    }

Another roadmap is:

  1. Keep the CoverageReport which does not implement the BEP methods.
  2. In BazelCoverageReportModule, add a new static inner class, strawman name CoverageReportCollector.
  3. Add to CoverageReportCollector a @Subscribe method that takes CoverageReport and stores the collection of Path objects in a mutable field. This will need to be synchronized and the mutable ImmutableList<Path> field it sets should be @GuardedBy("this")
  4. Add to CoverageReportCollector a @Subscribe method, also synchronized, that takes BuildCompleteEvent and adds the Paths to the BuildToolLogsCollection:
  5. Create the CoverageReportCollector and register it with the EventBus inside the CoverageReportActionFactory#createCoverageReportActionsWrapper() definition, at/around line 99.
    @Subscribe
    public synchronized void buildComplete(BuildCompleteEvent event) {
      for (var path : coverageReport.getPaths()) {
        event
            .getResult()
            .getBuildToolLogCollection()
            .addLocalFile("coverage_report.lcov", path); // reusing the name "coverage_report.lcov" doesn't matter.
      }
    }

@brentleyjones
Copy link
Contributor

Could code coverage collection be done before the absolute end of the build, and thus would be delayed by adding it to BuildToolLogs? Related: #21475

fmeum added 3 commits May 3, 2024 20:01
RELNOTES: The combined coverage report produced via `--combined_report=lcov` is now announced on the BES via the new `CoverageReport` event.
This allows BES consumers to access this file without guessing its path and existence, as well as when the actual coverage generation action runs locally.

Also removes an unused `CoverageReport` event that appears to have become obsolete.

RELNOTES: The combined coverage report produced via `--combined_report=lcov` is now announced on the BES via the new `CoverageReport` event.
@fmeum
Copy link
Collaborator Author

fmeum commented May 3, 2024

@michaeledgar I implemented your first suggestion and could also look into #21475, but any insights from your side would be highly appreciated.

@fmeum fmeum requested a review from michaeledgar May 3, 2024 18:23
@fmeum
Copy link
Collaborator Author

fmeum commented May 9, 2024

@michaeledgar Gentle ping, would be great to get this into 7.2.0

@michaeledgar
Copy link
Contributor

@brentleyjones - So for #21745, please correct me if I'm wrong! But it seems to be dealing with the code coverage artifacts produced by individual targets. If accurate, those should definitely not be delayed until the end of the build (skymeld or no skymeld) and the fix is definitely to make sure those events are posted promptly!

For this issue: My understanding after the first review is that it aims to convey a coverage report that is only available after the execution phase is complete. (In the first version, the event was posted after buildArtifacts() is complete). If the execution phase is done, there should be ~no time between "all targets are done building" and "posting BuildToolLogs".

@meum - Commit 680facf looks great to me!

It may not surprise you to learn that this functionality already exists inside Blaze, with a few extra hacks that prevent its direct open-sourcing. But we can someday mash those hacks to fit the open-source contribution you've made, and will have extra motivation to do so now!

@Wyverald
Copy link
Member

Wyverald commented May 9, 2024

@meum - Commit 680facf looks great to me!

hey Michael, do you want to approve the PR? Or do you think more work is required here?

@fmeum
Copy link
Collaborator Author

fmeum commented May 10, 2024

@bazel-io fork 7.2.0

@michaeledgar michaeledgar added the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 10, 2024
@Wyverald Wyverald removed the awaiting-review PR is awaiting review from an assigned reviewer label May 10, 2024
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 11, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request May 11, 2024
This allows BES consumers to access this file without guessing its path and existence, as well as when the actual coverage generation action runs locally.

Also removes an obsolete `CoverageReport` event.

RELNOTES: The combined coverage report produced via `--combined_report=lcov` is now announced on the BES via the new `CoverageReport` event.

Closes bazelbuild#22171.

PiperOrigin-RevId: 632641499
Change-Id: I0c323a371ec2fdd085bea23a772a85b72c52093f
github-merge-queue bot pushed a commit that referenced this pull request May 11, 2024
This allows BES consumers to access this file without guessing its path
and existence, as well as when the actual coverage generation action
runs locally.

Also removes an obsolete `CoverageReport` event.

RELNOTES: The combined coverage report produced via
`--combined_report=lcov` is now announced on the BES via the new
`CoverageReport` event.

Closes #22171.

PiperOrigin-RevId: 632641499
Change-Id: I0c323a371ec2fdd085bea23a772a85b72c52093f

Commit
bb1fb53

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
@fmeum fmeum deleted the bep branch May 11, 2024 06:42
Kila2 pushed a commit to Kila2/bazel that referenced this pull request May 13, 2024
This allows BES consumers to access this file without guessing its path and existence, as well as when the actual coverage generation action runs locally.

Also removes an obsolete `CoverageReport` event.

RELNOTES: The combined coverage report produced via `--combined_report=lcov` is now announced on the BES via the new `CoverageReport` event.

Closes bazelbuild#22171.

PiperOrigin-RevId: 632641499
Change-Id: I0c323a371ec2fdd085bea23a772a85b72c52093f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Remote-Exec Issues and PRs for the Execution (Remote) team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants