Coder Social home page Coder Social logo

Comments (7)

quarkus-bot avatar quarkus-bot commented on July 1, 2024

/cc @Ladicek (smallrye), @jmartisk (smallrye), @phillip-kruger (smallrye), @radcortez (smallrye)

from quarkus.

gsmet avatar gsmet commented on July 1, 2024

You're mentioning 3.8.0.CR1, you have the same issue with 3.7.3, right?

It would help if you could provide a simple reproducer. Thanks!

/cc @radcortez this looks concerning

from quarkus.

ikovalyov avatar ikovalyov commented on July 1, 2024

Based on my discoveres in version 3.2.6 ConfigUtils was creating SmallRyeConfigBuilder with addDiscoveredConverters being called in both build and run time.
In new version there are separate builders for build and run time and run time builder creates SmallRyeConfigBuilder without call to addDiscoveredConverters.

I think creating minimun reproducable example can take a while as we are using this code in our custom quarkus plugin.

from quarkus.

gsmet avatar gsmet commented on July 1, 2024

@radcortez FWIW, the important point here is that the code of the converter is generated with Gizmo.

@ikovalyov I think you should at least post how the converter is generated.

from quarkus.

radcortez avatar radcortez commented on July 1, 2024

Yes, we have the addDiscovered* to false in runtime to avoid the ServiceLoader. We discover the services during build time and register them directly (generated) with the builder.

That piece is done here:

@BuildStep
void generateBuilders(
ConfigurationBuildItem configItem,
List<ConfigMappingBuildItem> configMappings,
List<RunTimeConfigurationDefaultBuildItem> runTimeDefaults,
List<StaticInitConfigBuilderBuildItem> staticInitConfigBuilders,
List<RunTimeConfigBuilderBuildItem> runTimeConfigBuilders,
BuildProducer<GeneratedClassBuildItem> generatedClass,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) throws Exception {
Map<String, String> defaultValues = new HashMap<>();
// Default values from extensions @ConfigMapping
for (ConfigClassWithPrefix runTimeMapping : configItem.getReadResult().getRunTimeMappings()) {
defaultValues.putAll(ConfigMappings.getDefaults(runTimeMapping));
}
// Default values from user @ConfigMapping
for (ConfigMappingBuildItem configMapping : configMappings) {
defaultValues.putAll(ConfigMappings.getDefaults(configMapping.toConfigClassWithPrefix()));
}
// Default values from @ConfigRoot
defaultValues.putAll(configItem.getReadResult().getRunTimeDefaultValues());
// Default values from build item RunTimeConfigurationDefaultBuildItem override
for (RunTimeConfigurationDefaultBuildItem e : runTimeDefaults) {
defaultValues.put(e.getKey(), e.getValue());
}
// Recorded values from build time from any other source (higher ordinal then defaults, so override)
defaultValues.putAll(configItem.getReadResult().getRunTimeValues());
Set<String> converters = discoverService(Converter.class, reflectiveClass);
Set<String> interceptors = discoverService(ConfigSourceInterceptor.class, reflectiveClass);
Set<String> interceptorFactories = discoverService(ConfigSourceInterceptorFactory.class, reflectiveClass);
Set<String> configSources = discoverService(ConfigSource.class, reflectiveClass);
Set<String> configSourceProviders = discoverService(ConfigSourceProvider.class, reflectiveClass);
Set<String> configSourceFactories = discoverService(ConfigSourceFactory.class, reflectiveClass);
Set<String> secretKeyHandlers = discoverService(SecretKeysHandler.class, reflectiveClass);
Set<String> secretKeyHandlerFactories = discoverService(SecretKeysHandlerFactory.class, reflectiveClass);
Set<String> configCustomizers = discoverService(SmallRyeConfigBuilderCustomizer.class, reflectiveClass);
// For Static Init Config
Set<ConfigClassWithPrefix> staticMappings = new HashSet<>();
staticMappings.addAll(staticSafeConfigMappings(configMappings));
staticMappings.addAll(configItem.getReadResult().getBuildTimeRunTimeMappings());
Set<String> staticCustomizers = new HashSet<>(staticSafeServices(configCustomizers));
staticCustomizers.add(StaticInitConfigBuilder.class.getName());
String staticMappingsInfoClassName = "io.quarkus.runtime.generated.StaticInitMappingsInfo";
generateMappingsInfo(generatedClass, reflectiveClass, staticMappingsInfoClassName, staticMappings);
generateConfigBuilder(generatedClass, reflectiveClass, CONFIG_STATIC_NAME,
defaultValues,
converters,
interceptors,
staticSafeServices(interceptorFactories),
staticSafeServices(configSources),
staticSafeServices(configSourceProviders),
staticSafeServices(configSourceFactories),
secretKeyHandlers,
staticSafeServices(secretKeyHandlerFactories),
staticMappingsInfoClassName,
staticMappings,
staticCustomizers,
staticInitConfigBuilders.stream().map(StaticInitConfigBuilderBuildItem::getBuilderClassName).collect(toSet()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(CONFIG_STATIC_NAME).build());
// For RunTime Config
Set<ConfigClassWithPrefix> runTimeMappings = new HashSet<>();
runTimeMappings.addAll(runtimeConfigMappings(configMappings));
runTimeMappings.addAll(configItem.getReadResult().getBuildTimeRunTimeMappings());
runTimeMappings.addAll(configItem.getReadResult().getRunTimeMappings());
Set<String> runtimeCustomizers = new HashSet<>(configCustomizers);
runtimeCustomizers.add(RuntimeConfigBuilder.class.getName());
String runtimeMappingsInfoClassName = "io.quarkus.runtime.generated.RunTimeMappingsInfo";
generateMappingsInfo(generatedClass, reflectiveClass, runtimeMappingsInfoClassName, runTimeMappings);
generateConfigBuilder(generatedClass, reflectiveClass, CONFIG_RUNTIME_NAME,
defaultValues,
converters,
interceptors,
interceptorFactories,
configSources,
configSourceProviders,
configSourceFactories,
secretKeyHandlers,
secretKeyHandlerFactories,
runtimeMappingsInfoClassName,
runTimeMappings,
runtimeCustomizers,
runTimeConfigBuilders.stream().map(RunTimeConfigBuilderBuildItem::getBuilderClassName).collect(toSet()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(CONFIG_RUNTIME_NAME).build());
}

Maybe your generation is happening after this config build step and is not being picked up?

from quarkus.

ikovalyov avatar ikovalyov commented on July 1, 2024

Hi!
Yes, our code is generated on a runtime.
We indeed see it is triggered after executing code you mentioned.

from quarkus.

radcortez avatar radcortez commented on July 1, 2024

We indeed see it is triggered after executing code you mentioned.

Ok, so in that case, it is not going to be discovered by our code.

My recommendation is to directly register the converter with a RunTimeConfigBuilderBuildItem and a io.quarkus.runtime.configuration.ConfigBuilder. This may require some additional code generation because the withConverter requires a new instance of the registered Converter.

Or just turn the discovery on again in the builder, with the downside of extra operations in the native image. You probably need to add the service loader file as the native image resource manually. We don't do it automatically, because we determine everything at build time and register the converters directly to avoid that.

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.