bazelbuild / bazelbuild/bazel

Filtering class files for code coverage in JacocoInstrumentationProcessor.java

Open
#28,209 4 comments 0 reactions 1 assignee Claimed by @c-mita View on GitHub
coverage P3 team-Rules-Java type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

The JacocoInstrumentationProcessor.processJarFiles() method currently applies JaCoCo instrumentation indiscriminately to all .class files within jar artifacts, without any option within Bazel configuration parameters to limit instrumentation only to a subset of class files.
As noted in the inline [TODO](https://github.com/bazelbuild/bazel/blob/master/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/instrumentation/JacocoInstrumentationProcessor.java#L103), there was a thought at one point in time to add `coverage_instrumentation_filter` param for that purpose.
Adding `coverage_instrumentation_filter` would allow fine-grained control over instrumentation scope, enabling us to specify inclusion/exclusion patterns that limit instrumentation to a targeted subset of classes within jars, which will reduce instrumentation overhead.

### Which category does this issue belong to?

Java Rules

### What underlying problem are you trying to solve with this feature?

Our codebase has a significant number of java files, but coverage analysis requirements typically target only a subset of recently modified ones. The current implementation's unfiltered instrumentation of all class files within large jar dependencies creates performance bottlenecks in both execution time and memory utilization.
1) In resource constrained CI/CD environment, those full jar instrumentation bottlenecks frequently trigger failure of the bazel server daemon and disruptive build terminations
2) Given our change velocity and CI/CD pipeline execution frequency, the aggregate cost of unnecessary instrumentation (both in terms of build latency and compute resource consumption) represents a significant operational expense

### Which operating system are you running Bazel on?

linux

### What is the output of `bazel info release`?

release 8.4.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### Have you found anything relevant by searching the web?

This is somewhat relevant https://github.com/bazelbuild/bazel/issues/21520
But it only adds exception handling if instrumentation fails, it still does not implement class file instrumentation filtering.

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.