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

Default --instrumentation_filter when 2 targets share a prefix is incorrect #10949

Closed
keith opened this issue Mar 11, 2020 · 7 comments
Closed
Labels
coverage P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug

Comments

@keith
Copy link
Member

keith commented Mar 11, 2020

The instrumentation_filter flag appears to to have a few different default cases:

  1. If you're testing a single target like: //Modules/ResourceSupport:ResourceSupportTests it will default to //Modules/ResourceSupport[/:]
  2. If you're testing 2 targets like: //Modules/ResourceSupport:ResourceSupportTests and
    //Modules/LyftKit:LyftKitTests it will default to their common
    prefix: //Modules[/:]
  3. The unexpected case is if you test too targets like
    //Modules/TransitNearby:TransitNearbyTests and
    //Modules/TransitNearbyFlow:TransitNearbyFlowTests where they have
    a common prefix, it defaults to //Modules/TransitNearby[/:] which
    ends up excluding the TransitNearbyFlow files from the coverage manifest.

Am I correct in thinking that this is a bug and in that case it should either be //Modules[/:] or //Modules/TransitNearby without the [/:]

What operating system are you running Bazel on?

macOS

What's the output of bazel info release?

release 2.2.0

@dslomov dslomov added team-Rules-Server Issues for serverside rules included with Bazel untriaged labels Mar 16, 2020
@lberki lberki added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Nov 18, 2020
@limdor
Copy link
Contributor

limdor commented Nov 24, 2020

I just came across this issue today. @lberki could we add the coverage label?
@caiyulun I saw that you created a PR some time ago, are you planning to continue it? I understand that the missing part are only tests right?

@lberki
Copy link
Contributor

lberki commented Nov 25, 2020

sure can!

@limdor
Copy link
Contributor

limdor commented Nov 28, 2020

@lberki I would like to fix this issue, taking the open PR that @caiyulun created. In the PR @caiyulun mentioned 4 months ago that was working on tests but I assume that something prevented to continue on the topic. However I have some question about the code base, would it be here, in the PR, or in bazel-dev the place to ask? For the moment I will put it here in case you can answer right a way and if not I can move it to some other channel.

What is missing in the PR is a test case but InstrumentationFilterSupport has directly no tests. I was checking if the test should derive from BuildIntegrationTestCase or AnalysisTestCase but I cannot get an answer. I thought that these instrumentation filters are computed during the analysis phase but the file InstrumentationFilterSupport.java is inside buildtool folder and not analysis. There is no test in buildtool that derive from AnalysisTestCase.

I wanted to derive from AnalysisTestCase because the method under test is:
public static String computeInstrumentationFilter(EventHandler eventHandler, Collection<Target> testTargets)
And to get the target collection I was considering to use Target getTarget(String label) that it is only in AnalysisTestCase

Here my question: Can the new test derive from AnalysisTestCase and stay under the buildtool folder? Will it be enough or we really need to build some target to compute the instrumentation filters? I assume that BuildIntegrationTestCase would work but I thought that maybe is too much overkill and AnalysisTestCase should sufficient.

Bonus: I was also thinking if indeed InstrumentationFilterSupport.java should be moved from buildtool to analysis but I saw that is used in AnalysisPhaseRunner that is also under buildtool. In addition I saw that needsInstrumentationFilter is in BuildRequest.java that is also inside buildtool

@c-mita
Copy link
Member

c-mita commented Dec 2, 2020

The internal InstrumentationFilterTest class derives BuildViewTestCase, which is similar to AnalysisTestCase for the purposes of this discussion.

Since we have internal tests, I would not worry too much about where you implement your test case, since we don't need to pull in the test class itself and can instead, transfer the cases you write into the existing test class.

With a little bit of inlining, the existing tests look kind of like this:

@Test
private void testFoo() throws Exception {
  EventCollector events = new EventCollector(EventKind.INFO);
  scratch.file("foo/BUILD", "sh_test(name='t', srcs=['t.sh']")
  Collection<Target> targets = Collections.singletonList(getTarget("//foo:t");
  String expectedFilter = "^//foo[/:]";
  assertThat(InstrumentationFilterSupport.computeInstrumentationFilter(events, targets))
      .isEqualTo(expectedFilter);
}

(Caveat, I might have got the expectedFilter wrong, I haven't checked it).

It's not ideal, and it would be much nicer if we could get the test code open sourced, but I don't know where we are with that effort at the moment.

limdor added a commit to limdor/bazel that referenced this issue Dec 2, 2020
In case that two path share a prefix, the instrumentation filter is
not computed proper.
bazelbuild#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: bazelbuild#10949
@limdor
Copy link
Contributor

limdor commented Dec 2, 2020

Thanks for the hints @c-mita, I created a PR with the changes of the original PR, adding the missing include and adding some tests.
Just tell me if I got something wrong, last time I wrote Java code was more than 10 years ago :-)
#12607

bazel-io pushed a commit that referenced this issue Dec 7, 2020
In case that two path share a prefix, the instrumentation filter is
not computed proper.
#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: #10949

Closes #12607.

PiperOrigin-RevId: 346097533
@keith
Copy link
Member Author

keith commented Dec 7, 2020

Does that PR fix this one? If so I can close this

@limdor
Copy link
Contributor

limdor commented Dec 7, 2020

Yes, and I would also recommend to close #11690

@keith keith closed this as completed Dec 7, 2020
philwo pushed a commit that referenced this issue Dec 7, 2020
In case that two path share a prefix, the instrumentation filter is
not computed proper.
#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: #10949

Closes #12607.

PiperOrigin-RevId: 346097533
philwo pushed a commit that referenced this issue Dec 9, 2020
In case that two path share a prefix, the instrumentation filter is
not computed proper.
#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: #10949

Closes #12607.

PiperOrigin-RevId: 346097533
philwo pushed a commit that referenced this issue Dec 10, 2020
In case that two path share a prefix, the instrumentation filter is
not computed proper.
#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: #10949

Closes #12607.

PiperOrigin-RevId: 346097533
ulfjack pushed a commit to EngFlow/bazel that referenced this issue Mar 5, 2021
In case that two path share a prefix, the instrumentation filter is
not computed proper.
bazelbuild#10949
This PR takes as a base the one that was created by @caiyulun and
adds some tests.
Original PR: bazelbuild#10949

Closes bazelbuild#12607.

PiperOrigin-RevId: 346097533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Server Issues for serverside rules included with Bazel type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants