quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.41k stars 2.57k forks source link

no post-process filtering in native image tracing agent #41579

Open vsevel opened 3 weeks ago

vsevel commented 3 weeks ago

Describe the bug

I have tried Native Image Tracing Agent Integration. I was expecting entries to be filtered out in native-image-agent-final-config if elements were already covered by quarkus declarations.

for instance imagine the following code:

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/foo")
    public String foo() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = MyFoo.class.getDeclaredMethod("getFoo");
        return (String) method.invoke(new MyFoo());
    }

and test

    @Test
    public void foo() {
        given()
                .when().get("/hello/foo")
                .then()
                .statusCode(200)
                .body(is("bar"));
    }

with the following MyFoo class:

public class MyFoo {

    String foo = "bar";

    public String getFoo() {
        return foo;
    }
}

when running mvn clean verify -DskipITs=false -Dquarkus.test.integration-test-profile=test-with-native-agent, I get the expected element in reflect-config.json:

{
  "name":"org.acme.MyFoo",
  "methods":[{"name":"getFoo","parameterTypes":[] }]
},

then I annotate MyFoo:

@RegisterForReflection
public class MyFoo {
...

and re-run the verify. I am expecting that the org.acme.MyFoo in reflect-config.json would disappear. but that is not the case.

moreover, reflect-config.json has the exact same size in target/native-image-agent-base-config/ and target/native-image-agent-final-config/:

$ ls -al target/native-image-agent-final-config/
total 12
drwxr-xr-x 1 Sevel 1049089   0 Jul  1 11:08 .
drwxr-xr-x 1 Sevel 1049089   0 Jul  1 11:08 ..
-rw-r--r-- 1 Sevel 1049089 113 Jul  1 11:08 jni-config.json
-rw-r--r-- 1 Sevel 1049089   4 Jul  1 11:08 proxy-config.json
-rw-r--r-- 1 Sevel 1049089 994 Jul  1 11:08 reflect-config.json
-rw-r--r-- 1 Sevel 1049089 261 Jul  1 11:08 resource-config.json
-rw-r--r-- 1 Sevel 1049089  71 Jul  1 11:08 serialization-config.json

$ ls -al target/native-image-agent-base-config/
total 20
drwxr-xr-x 1 Sevel 1049089    0 Jul  1 11:08 .
drwxr-xr-x 1 Sevel 1049089    0 Jul  1 11:08 ..
drwxr-xr-x 1 Sevel 1049089    0 Jul  1 11:08 agent-extracted-predefined-classes
-rw-r--r-- 1 Sevel 1049089  113 Jul  1 11:08 jni-config.json
-rw-r--r-- 1 Sevel 1049089   65 Jul  1 11:08 predefined-classes-config.json
-rw-r--r-- 1 Sevel 1049089    4 Jul  1 11:08 proxy-config.json
-rw-r--r-- 1 Sevel 1049089  994 Jul  1 11:08 reflect-config.json
-rw-r--r-- 1 Sevel 1049089 2219 Jul  1 11:08 resource-config.json
-rw-r--r-- 1 Sevel 1049089   71 Jul  1 11:08 serialization-config.json

Expected behavior

{
  "name":"org.acme.MyFoo",
  "methods":[{"name":"getFoo","parameterTypes":[] }]
}

should disappear if I annotate MyFoo with RegisterForReflection.

Actual behavior

the entry is still there. similarly there is not filtering on included resources.

How to Reproduce?

create an application: quarkus create app tracingagent add /foo entry point with some reflection on class MyFoo annotate MyFoo with RegisterForReflection execute mvn clean verify -DskipITs=false -Dquarkus.test.integration-test-profile=test-with-native-agent open target/native-image-agent-final-config/reflect-config.json => MyFoo is there (and should not be)

Output of uname -a or ver

No response

Output of java -version

java 21

Quarkus version or git rev

3.12.0

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

quarkus-bot[bot] commented 3 weeks ago

/cc @brunobat (tracing), @radcortez (tracing), @zakkak (native-image)

vsevel commented 3 weeks ago

cc @galderz