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

Unable to define stork discovery provider in extension #23656

Closed
vsevel opened this issue Feb 14, 2022 · 11 comments
Closed

Unable to define stork discovery provider in extension #23656

vsevel opened this issue Feb 14, 2022 · 11 comments
Labels
area/stork kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@vsevel
Copy link
Contributor

vsevel commented Feb 14, 2022

Describe the bug

I have created an extension to host a stork service discovery custom implementation.
I use the extension from my application.
The application fails to start because it does not find the service discovery from the extension.
If I move the service discovery into the application, it works.
In addition the discovery configuration class does not get generated.

/cc @michalszynkiewicz

Expected behavior

A custom service discovery can be implemented in an extension, as if it was located in the application itself.

Actual behavior

The service discovery can not be found.
The configuration class does not get generated.

How to Reproduce?

fetch https://github.com/vsevel/stork-issue/tree/provider_in_ext

and execute:

mvn clean install -f my-ext/pom.xml
mvn clean install -f app/pom.xml

The build fails with:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.acme.ReactiveGreetingResourceTest
2022-02-14 09:14:52,318 INFO  [org.jbo.threads] (main) JBoss Threads version 3.4.2.Final
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 11.665 s <<< FAILURE! - in org.acme.ReactiveGreetingResourceTest
[ERROR] org.acme.ReactiveGreetingResourceTest.testHelloEndpoint  Time elapsed: 0.006 s  <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.IllegalArgumentException: ServiceDiscoveryProvider not found for type my2

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.1

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

No response

Additional information

No response

@vsevel vsevel added the kind/bug Something isn't working label Feb 14, 2022
@vsevel
Copy link
Contributor Author

vsevel commented Feb 14, 2022

to reproduce you can also make a build without tests, and run:

vsevel@newmac2:~/dev/github/stork-issue/app$ java -jar target/quarkus-app/quarkus-run.jar 
févr. 14, 2022 9:27:09 AM io.quarkus.runtime.ApplicationLifecycleManager run
ERROR: Failed to start application (with profile prod)
java.lang.IllegalArgumentException: ServiceDiscoveryProvider not found for type my2
        at io.smallrye.stork.Stork.<init>(Stork.java:86)
        at io.smallrye.stork.Stork.initialize(Stork.java:136)
        at io.smallrye.stork.Stork.initialize(Stork.java:140)
        at io.quarkus.stork.SmallRyeStorkRecorder.initialize(SmallRyeStorkRecorder.java:11)
        at io.quarkus.deployment.steps.SmallRyeStorkProcessor$initializeStork1856703159.deploy_0(Unknown Source)
        at io.quarkus.deployment.steps.SmallRyeStorkProcessor$initializeStork1856703159.deploy(Unknown Source)
        at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:103)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:120)
        at io.quarkus.runner.GeneratedMain.main(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:60)
        at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:31)

@michalszynkiewicz
Copy link
Member

Does it work for you if you move the classes out to a separate project, i.e. not an extension?

What are the benefits of having it as an extension?

@geoand
Copy link
Contributor

geoand commented Feb 14, 2022

@michalszynkiewicz why would it not work in the runtime module of an extension?

@michalszynkiewicz
Copy link
Member

I don't know, weird that it doesn't work at all. I looked at the code and it seems to be good.

@vsevel
Copy link
Contributor Author

vsevel commented Feb 14, 2022

What are the benefits of having it as an extension?

@michalszynkiewicz to support better our application teams, we try to factor as much as possible some of the transversal technical concerns into a common set of extensions that all applications will depend on.
the integration with our legacy service discovery is one of those technical concerns.
I could very well move it to a different library, if this this works technically. but why would I have to do this? I would rather keep the discovery in our extension, and only ask application to depend on the extension for sake of simplicity.
I did a quick test last week, and could get it to work. I did not spend too much time, so may be I missed something.
and I was not too sure what I was supposed to to. I tried adding a io.smallrye.stork.spi.ServiceDiscoveryProvider, a producing a ServiceProviderBuildItem in my processor, with no luck.
Please let me know what is the proper way to integrate a reusable custom service across apps. thanks.

@vsevel
Copy link
Contributor Author

vsevel commented Feb 14, 2022

in the reproducer's application.properties, change stork.hello-service.service-discovery=my2 to my3 (discovery embedded in the app) and it works.

@geoand
Copy link
Contributor

geoand commented Feb 14, 2022

Just as an FYI, ServiceProviderBuildItem is only useful for native mode.

@michalszynkiewicz let me know if you want me to look into this at all (sounds like it could be classloader related)

@michalszynkiewicz
Copy link
Member

michalszynkiewicz commented Feb 15, 2022

@geoand if you have time for it, it would be great. I have quite a few bugs to look into at the moment. If you're busy too I should get to this one this week too

@geoand
Copy link
Contributor

geoand commented Feb 16, 2022

Turns out there is an easy explanation for this :)

As you know, Stork uses an annotation processor, which under normal circumestances is on the compiler's classpath because of the presense of:

    <dependency>
      <groupId>io.smallrye.stork</groupId>
      <artifactId>stork-configuration-generator</artifactId>
      <scope>provided</scope>
    </dependency>

in the application's pom.xml.

In the cases of Quarkus extensions however, the runtime module of the extension needs to configure the quarkus-extension-processor like so:

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>io.quarkus</groupId>
              <artifactId>quarkus-extension-processor</artifactId>
              <version>${quarkus.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>

This configuration leads to the annotation processor in the stork-configuration-generator dependency to not be present on compile classpath.

The fix is easy and demonstrated by this diff:

diff --git a/my-ext/runtime/pom.xml b/my-ext/runtime/pom.xml
index 794f385..b9d0e54 100644
--- a/my-ext/runtime/pom.xml
+++ b/my-ext/runtime/pom.xml
@@ -18,11 +18,6 @@
       <groupId>io.quarkus</groupId>
       <artifactId>quarkus-smallrye-stork</artifactId>
     </dependency>
-    <dependency>
-      <groupId>io.smallrye.stork</groupId>
-      <artifactId>stork-configuration-generator</artifactId>
-      <scope>provided</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -51,6 +46,11 @@
               <artifactId>quarkus-extension-processor</artifactId>
               <version>${quarkus.version}</version>
             </path>
+            <path>
+              <groupId>io.smallrye.stork</groupId>
+              <artifactId>stork-configuration-generator</artifactId>
+              <version>1.0.0</version>
+            </path>
           </annotationProcessorPaths>
         </configuration>
       </plugin>

@geoand geoand closed this as completed Feb 16, 2022
@geoand geoand added the triage/invalid This doesn't seem right label Feb 16, 2022
@vsevel
Copy link
Contributor Author

vsevel commented Feb 16, 2022

ok. thanks for taking a look @geoand

@geoand
Copy link
Contributor

geoand commented Feb 16, 2022

yw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/stork kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants