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

Add support for service registry service binding #21618

Merged
merged 1 commit into from
Jan 6, 2022

Conversation

secondsun
Copy link
Contributor

@secondsun secondsun commented Nov 22, 2021

This pull request adds to the apicurio registry avro extension the ability to consume service bindings injected by the service binding operator. This work is being done as part of adding service registry binding to the rhoas operator and cli.

The SBO provides the following bindings

  • oauthTokenUrl binds to channels' apicurio.auth.token.endpoint property +
  • clientId binds to channels' apicurio.auth.client.id property+
  • oauthRealm binds to channels' apicurio.auth.realm property+
  • registry binds to channels' apicurio.registry.url and mp.messaging.connector.smallrye-kafka.apicurio.registry.url properties+

== How to Test

=== Prerequisites

  • OpenShift 4.9 cluster with rhoas-operator and service binding operator installed
  • rhoas Cli
  • oc cli
  • console.redhat.com account

=== Cluster and Services Setup

Ensure that you have logged into your cluster with oc, and have logged into your Application Services account with rhoas login. Create a kafka instance with rhoas kafka create, and a service registry instance with rhoas service-registry create. Once your kafka and service registry entries are ready, create a kafka topic called movies. You can use hroas kafka topic create. You will then execute rhoas cluster connect twice - connecting the kafka instance and your service registry instance separately with each run. When you connect the kafka instance, you will be prompted to update your kafka ACLs and provided a command to do so using a service account that was created. It is important you do this.

We have provided a sample application(https://github.com/secondsun/kafka-avro-schema-quickstart/). This application is deployed to OpenShift as a container. One you have deployed the container, use rhoas cluster bind to first bind the kafka connection, then execute the command again to bind the service registry. Once the pod has restartted, use the route provided by openshift to navigate to /movies.html. You should see a screen showing a random movie title.

There is a version of the application already containerized with the extension here : quuay.io/secondsun/kafka-avro-schema-quickstart:latest

A video of the process is here :

https://www.youtube.com/watch?v=ul9JDjXLquw

@quarkus-bot
Copy link

quarkus-bot bot commented Nov 22, 2021

Thanks for your pull request!

The title of your pull request does not follow our editorial rules. Could you have a look?

  • title should preferably start with an uppercase character (if it makes sense!)
  • title should not start with chore/docs/feat/fix/refactor but be a proper sentence

This message is automatically generated by a bot.

@secondsun
Copy link
Contributor Author

@wtrocki @cescoffier @carlesarnal Here is the Binding extension for service registry. Proceed to comment.

@secondsun secondsun changed the title feat: service binding support for service registry feat: Add support for service registry service binding Nov 22, 2021
@secondsun secondsun changed the title feat: Add support for service registry service binding Add support for service registry service binding Nov 22, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 22, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 0937c8f

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/apicurio-registry-avro/runtime 
! Skipped: devtools/bom-descriptor-json docs extensions/apicurio-registry-avro/deployment and 8 more

📦 extensions/apicurio-registry-avro/runtime

Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.17.0:validate (default) on project quarkus-apicurio-registry-avro: File '/home/runner/work/quarkus/quarkus/extensions/apicurio-registry-avro/runtime/src/main/java/io/quarkus/apicurio/registry/binding/ServiceRegistryBindingConverter.java' has not been previously formatted. Please format file and commit before running validation!

@secondsun secondsun force-pushed the srs_binding_enhancement branch from 0937c8f to edc2559 Compare November 22, 2021 15:15
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 22, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building edc2559

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/apicurio-registry-avro/runtime 
! Skipped: devtools/bom-descriptor-json docs extensions/apicurio-registry-avro/deployment and 8 more

📦 extensions/apicurio-registry-avro/runtime

Failed to execute goal io.quarkus:quarkus-bootstrap-maven-plugin:999-SNAPSHOT:extension-descriptor (generate-extension-descriptor) on project quarkus-apicurio-registry-avro: Deployment artifact io.quarkus:quarkus-apicurio-registry-avro-deployment::jar:999-SNAPSHOT is missing the following dependencies from its configuration: io.quarkus:quarkus-kubernetes-service-binding-deployment::jar

Copy link
Contributor

@carlesarnal carlesarnal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I just think that maybe we should replace the combination of realm + auth URL by the token endpoint.

@secondsun secondsun force-pushed the srs_binding_enhancement branch from edc2559 to 1e1e5ee Compare November 22, 2021 18:40
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 22, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 1e1e5ee

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/apicurio-registry-avro/runtime 
! Skipped: devtools/bom-descriptor-json docs extensions/apicurio-registry-avro/deployment and 8 more

📦 extensions/apicurio-registry-avro/runtime

Failed to execute goal io.quarkus:quarkus-bootstrap-maven-plugin:999-SNAPSHOT:extension-descriptor (generate-extension-descriptor) on project quarkus-apicurio-registry-avro: Deployment artifact io.quarkus:quarkus-apicurio-registry-avro-deployment::jar:999-SNAPSHOT is missing the following dependencies from its configuration: io.quarkus:quarkus-kubernetes-service-binding-deployment::jar

@secondsun secondsun force-pushed the srs_binding_enhancement branch from 1e1e5ee to a1f0237 Compare November 22, 2021 19:22
extensions/apicurio-registry-avro/deployment/pom.xml Outdated Show resolved Hide resolved
BuildProducer<ServiceProviderBuildItem> serviceProvider) {
if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) {
serviceProvider.produce(
new ServiceProviderBuildItem("io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to that PR, but maybe we should have an SPI in the service binding extension with a dedicated build item (which will also about the capability check)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean here. Can you elaborate a bit please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine that instead to do:

 if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) {
            serviceProvider.produce(
                    new ServiceProviderBuildItem("io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter", ServiceRegistryBindingConverter.class.getName()));

You do:

producer.produce(new ServiceBindingConverter(ServiceRegistryBindingConverter.class));

Then the SBO processor would consumer this new build item and register the SPI provider.

Of course to avoid a dependency on the SBO extension deployment model, we would need to create an SPI module.

registryUrl = binding.getProperties().get("registryurl");
}
if (registryUrl != null) {
properties.put("mp.messaging.connector.smallrye-kafka.apicurio.registry.url", registryUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use "kafka." instead of "mp.messaging.connector.smallrye-kafka."

So, bare clients using Kafka default config will have the apicurio URL configured too.

@geoand
Copy link
Contributor

geoand commented Nov 24, 2021

Can you please squash the commits?

@secondsun secondsun force-pushed the srs_binding_enhancement branch from 5726377 to cc74e12 Compare November 24, 2021 22:39
@secondsun secondsun requested a review from cescoffier November 24, 2021 22:40
@secondsun
Copy link
Contributor Author

I've implemented some feedback you all gave and have rerequested reviews. As an additional note : this works with native clients now, but it didn't before.

The image is at quay.io/secondsun/kafka-avro-schema-quickstart:native

@secondsun
Copy link
Contributor Author

Ok, it seems like the binding works, but whatever I did to inject the http client causes vertx's connections to drop and not reconnect. I'll roll that back on Monday, but in the meantime if anyone sees anything that might cause that please comment.

@geoand
Copy link
Contributor

geoand commented Nov 26, 2021

Looks like all that's left for this to be ready is to use the Vert.x client, right?

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to use the vertx client.

@secondsun
Copy link
Contributor Author

@geoand Sadly no, when I've updated to use the vertx client I get different errors.

For some reason the spi won't use the vertx client and is insisting on the jdk client.

2021-12-02 04:12:03,489 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.util.ServiceConfigurationError: io.apicurio.rest.client.spi.ApicurioHttpClientProvider: Provider io.apicurio.rest.client.JdkHttpClientProvider not found
	at java.util.ServiceLoader.fail(ServiceLoader.java:589)
	at java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1212)
	at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:106)
	at java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
	at java.util.ServiceLoader$2.next(ServiceLoader.java:1306)
	at java.util.ServiceLoader$2.next(ServiceLoader.java:1297)
	at java.util.ServiceLoader$3.next(ServiceLoader.java:1395)
	at io.apicurio.rest.client.auth.OidcAuth.resolveProviderInstance(OidcAuth.java:81)
	at io.apicurio.rest.client.auth.OidcAuth.resolveApicurioHttpClient(OidcAuth.java:85)
	at io.apicurio.rest.client.auth.OidcAuth.<init>(OidcAuth.java:65)
	at io.apicurio.registry.serde.AbstractSchemaResolver.configureAuthWithUrl(AbstractSchemaResolver.java:232)
	at io.apicurio.registry.serde.AbstractSchemaResolver.configureClientWithBearerAuthentication(AbstractSchemaResolver.java:203)
	at io.apicurio.registry.serde.AbstractSchemaResolver.configure(AbstractSchemaResolver.java:75)
	at io.apicurio.registry.serde.DefaultSchemaResolver.configure(DefaultSchemaResolver.java:56)
	at io.apicurio.registry.serde.SchemaResolverConfigurer.configure(SchemaResolverConfigurer.java:75)
	at io.apicurio.registry.serde.AbstractKafkaSerDe.configure(AbstractKafkaSerDe.java:68)
	at io.apicurio.registry.serde.AbstractKafkaDeserializer.configure(AbstractKafkaDeserializer.java:62)
	at io.apicurio.registry.serde.avro.AvroKafkaDeserializer.configure(AvroKafkaDeserializer.java:68)
	at io.smallrye.reactive.messaging.kafka.fault.DeserializerWrapper.configure(DeserializerWrapper.java:82)
	at io.smallrye.reactive.messaging.kafka.impl.ReactiveKafkaConsumer.<init>(ReactiveKafkaConsumer.java:79)
	at io.smallrye.reactive.messaging.kafka.impl.KafkaSource.<init>(KafkaSource.java:93)
	at io.smallrye.reactive.messaging.kafka.KafkaConnector.getPublisherBuilder(KafkaConnector.java:173)
	at io.smallrye.reactive.messaging.kafka.KafkaConnector_ClientProxy.getPublisherBuilder(KafkaConnector_ClientProxy.zig:159)
	at io.smallrye.reactive.messaging.impl.ConnectorFactories.lambda$wrap$4(ConnectorFactories.java:80)
	at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.createPublisher(ConfiguredChannelFactory.java:174)
	at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.register(ConfiguredChannelFactory.java:136)
	at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory.initialize(ConfiguredChannelFactory.java:108)
	at io.smallrye.reactive.messaging.impl.ConfiguredChannelFactory_ClientProxy.initialize(ConfiguredChannelFactory_ClientProxy.zig:189)
	at java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at io.smallrye.reactive.messaging.extension.MediatorManager.start(MediatorManager.java:189)
	at io.smallrye.reactive.messaging.extension.MediatorManager_ClientProxy.start(MediatorManager_ClientProxy.zig:220)
	at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle.onApplicationStart(SmallRyeReactiveMessagingLifecycle.java:41)
	at io.quarkus.smallrye.reactivemessaging.runtime.SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.notify(SmallRyeReactiveMessagingLifecycle_Observer_onApplicationStart_4e8937813d9e8faff65c3c07f88fa96615b70e70.zig:111)
	at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:320)
	at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:302)
	at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:73)
	at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
	at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
	at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(LifecycleEventsBuildStep$startupEvent1144526294.zig:80)
	at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(LifecycleEventsBuildStep$startupEvent1144526294.zig:40)
	at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:677)
	at io.quarkus.runtime.Application.start(Application.java:101)
	at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:104)
	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(GeneratedMain.zig:29)



@geoand
Copy link
Contributor

geoand commented Dec 2, 2021

That doesn't seem to be a Quarkus specific issue

@cescoffier
Copy link
Member

@secondsun check if you don't have a META-INF/services file declaring the wrong client.

@secondsun
Copy link
Contributor Author

secondsun commented Dec 2, 2021

@cescoffier I don't have a META-INF/services file; I think it is coming in from a dependency. I will double check though.

@cescoffier
Copy link
Member

Even in the artifact providing OidcAuth? Look how the lookup is done and why it uses the wrong client.

@carlesarnal
Copy link
Contributor

@secondsun this seems like a bug in the library providing OidcAuth, I'll take a look as soon as I can.

@secondsun
Copy link
Contributor Author

@cescoffier I'll dig into that. @carlesarnal Do you have some time to take a look with me? You've helped with issues in the past and I think you're more familiar with this dependency.

@cescoffier
Copy link
Member

I can help, but I don't know Apicurio code at all. @carlesarnal has a lot more knowledge on that code.

@carlesarnal
Copy link
Contributor

@cescoffier I'll dig into that. @carlesarnal Do you have some time to take a look with me? You've helped with issues in the past and I think you're more familiar with this dependency.

I think there's a bug in the underlying library but haven't had the time to go through it yet. I'll try to take a look tomorrow.

@secondsun
Copy link
Contributor Author

Thanks guys, I'm taking a look today and will let you guys know what I find / send prs where I need to if I get lucky

@cescoffier
Copy link
Member

@secondsun

 @BuildStep
    void registerSPIClient(BuildProducer<ServiceProviderBuildItem> services) throws IOException {

        services.produce(
                new ServiceProviderBuildItem(ApicurioHttpClientProvider.class.getName(),
                        "io.apicurio.rest.client.JdkHttpClientProvider"));
    }

This code is not correct, it references the wrong client. Can you try using the Vert.x one?

@secondsun
Copy link
Contributor Author

secondsun commented Dec 2, 2021

@cescoffier Above I've attatched a stack trace using the vertx client as you've suggested, I just hadn't committed it because it hasn't worked.

@secondsun secondsun force-pushed the srs_binding_enhancement branch from cc74e12 to d171f13 Compare December 2, 2021 15:45
@secondsun
Copy link
Contributor Author

I've worked with @carlesarnal and he's fixed the underlying bug in the registry. I've tested his snapshot with this PR and it fixes all of my issues as well. When central catches up with things we can bump the version of the registry and this should be good to merge. Thanks guys.

@secondsun secondsun requested a review from cescoffier December 6, 2021 14:55
@secondsun secondsun force-pushed the srs_binding_enhancement branch from d171f13 to 5be0e25 Compare December 6, 2021 14:56
@secondsun
Copy link
Contributor Author

@carlesarnal I saw the new registry was released, does that mean this is ready to merge?
@cescoffier I've implemented your feedback and requested a rereview.

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's see what @carlesarnal and @geoand say.

Comment on lines +50 to +53
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this now needed for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlesarnal
Copy link
Contributor

carlesarnal commented Dec 7, 2021

@carlesarnal I saw the new registry was released, does that mean this is ready to merge? @cescoffier I've implemented your feedback and requested a rereview.

No, unfortunately, I was on PTO and we missed that release, I'll try to get the fix into the next one. I'll ping you once we do a release so we can update this.

@secondsun secondsun force-pushed the srs_binding_enhancement branch from 5be0e25 to 7ce16d2 Compare January 4, 2022 15:09
@secondsun
Copy link
Contributor Author

@carlesarnal the registry has been updated and this can be merged but right? Cc @cescoffier

@cescoffier
Copy link
Member

cescoffier commented Jan 5, 2022

LGTM, @geoand any comment before we click on the big red button?

@secondsun secondsun requested a review from cescoffier January 5, 2022 21:25
@secondsun
Copy link
Contributor Author

@cescoffier It looks like there is an outstanding change in your last review, can you clear that?

@cescoffier cescoffier merged commit 9a40f35 into quarkusio:main Jan 6, 2022
@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Jan 6, 2022
@cescoffier
Copy link
Member

Thanks!

@carlesarnal
Copy link
Contributor

@carlesarnal the registry has been updated and this can be merged but right? Cc @cescoffier

Sorry, PTO time for me. Yes, it has been updated and this should work just fine (I guess you already checked it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants