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

Produce quarkus.uuid lazily #45434

Merged
merged 1 commit into from
Jan 10, 2025
Merged

Produce quarkus.uuid lazily #45434

merged 1 commit into from
Jan 10, 2025

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jan 8, 2025

This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed

The goal is the same as that of #33941

@geoand geoand mentioned this pull request Jan 8, 2025
@geoand geoand changed the title Make production of quarkus.uuid lazy Produce quarkus.uuid lazily Jan 8, 2025
@franz1981
Copy link
Contributor

Nice one!

@geoand
Copy link
Contributor Author

geoand commented Jan 8, 2025

🙏🏽 ❤️

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

That would be awesome if it worked. It's a shame everybody pays the price for it.

Now I suppose anyone ending using the random infra will pay the price at some point but simple apps might not have any random around so it would clearly be a win.

Comment on lines -77 to -84
/**
* A property that allows accessing a generated UUID.
* It generates that UUID at startup time. So it changes between two starts including in dev mode.
* <br>
* Access this generated UUID using expressions: `${quarkus.uuid}`.
*/
Optional<String> uuid();

Copy link
Member

Choose a reason for hiding this comment

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

Does it actually change something to remove this? Asking because it's the only way to document it in the config.

Copy link
Member

Choose a reason for hiding this comment

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

If a property is declared in a mapping (or the old root), it is always eagerly populated. It wouldn't matter if quarkus.uuid is lazy. This is always trigger the load.

Copy link
Member

Choose a reason for hiding this comment

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

OK. I suppose we need to make sure it's properly documented elsewhere then.

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to do it manually. We don't have a way to do it in the processor. We can ignore properties for documentation, but we can't ignore properties for mapping.

@@ -12,7 +15,38 @@ public class RuntimeConfigBuilder implements SmallRyeConfigBuilderCustomizer {
@Override
public void configBuilder(final SmallRyeConfigBuilder builder) {
new QuarkusConfigBuilderCustomizer().configBuilder(builder);
builder.withDefaultValue("quarkus.uuid", UUID.randomUUID().toString());
builder.withSources(new ConfigSource() {
Copy link
Member

Choose a reason for hiding this comment

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

Looks interesting. If the ConfigSource are kept around at runtime, we might want to move this to a static nested class to avoid keeping the builder reference around?

That being said, better to wait for @radcortez 's feedback before polishing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 on all counts

Copy link
Member

Choose a reason for hiding this comment

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

If we want a quick solution, I'm okay with moving forward with this.

My idea was to add some sort of lazy type that can be declared in the mapping. This would allow keeping the declaration for documentation purposes and flattening sources if there are other cases.

Alternatively, we could just do this as a build step for the extensions that need it (it would have worked if it was done that way when it was first introduced). Unfortunately, we can't tell if users are now relying on it outside of the required extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we want a quick solution, I'm okay with moving forward with this.

That's totally up to you. The reason I vote for having this now is that we usually do the performance optimization in sprints (I don't mean the Agile sense of the word) and if we don't get this in now, who knows when we'll get around to it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In any case, I updated the PR to use an inner class instead of an anonymous one.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth merging this but I also agree having a lazy type in SmallRye Config would be nice for the future and we could revisit this patch then.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, another alternative (breaking) is to totally drop this from the Config system and add a specific API for it (this is similar to the issue we have with ports).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought of that, but this property seems pretty pervasive so I didn't want to cause such problems until after the next LTS :)

@geoand geoand marked this pull request as ready for review January 8, 2025 13:21
@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 8, 2025

This comment has been minimized.

@gsmet
Copy link
Member

gsmet commented Jan 8, 2025

FWIW, the fault tolerance issue is unrelated, it popped up in other PRs. I pinged @Ladicek with the details in another PR.

@geoand
Copy link
Contributor Author

geoand commented Jan 8, 2025

🙏

@radcortez
Copy link
Member

FWIW, the fault tolerance issue is unrelated, it popped up in other PRs. I pinged @Ladicek with the details in another PR.

Ah, good to hear, I was going crazy thinking I caused it in another PR :)

@gsmet
Copy link
Member

gsmet commented Jan 9, 2025

We need to be careful though as it gets the build stuck so PRs are not properly tested: anything beyong these tests is not exercised...

This comment has been minimized.

Verified

This commit was signed with the committer’s verified signature.
khusika Khusika Dhamar Gusti
This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed
Copy link

quarkus-bot bot commented Jan 9, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 8a1ab70.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ JVM Tests - JDK 21

📦 extensions/infinispan-cache/deployment

io.quarkus.cache.infinispan.InfinispanCacheTest.testGetAsyncWithParallelCalls - History

  • expected: "thread1" but was: "thread2" - org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError: 

expected: "thread1"
 but was: "thread2"
	at io.quarkus.cache.infinispan.InfinispanCacheTest.testGetAsyncWithParallelCalls(InfinispanCacheTest.java:283)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:513)
	at io.quarkus.test.QuarkusUnitTest.interceptTestMethod(QuarkusUnitTest.java:427)

⚙️ JVM Tests - JDK 17 Windows

📦 integration-tests/grpc-hibernate

com.example.grpc.hibernate.VertxBlockingRawTest.shouldAdd - History

  • Condition with Lambda expression in com.example.grpc.hibernate.BlockingRawTestBase was not fulfilled within 30 seconds. - org.awaitility.core.ConditionTimeoutException
org.awaitility.core.ConditionTimeoutException: Condition with Lambda expression in com.example.grpc.hibernate.BlockingRawTestBase was not fulfilled within 30 seconds.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1006)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:975)
	at com.example.grpc.hibernate.BlockingRawTestBase.shouldAdd(BlockingRawTestBase.java:59)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)

@geoand geoand merged commit 62bdeaa into quarkusio:main Jan 10, 2025
52 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.18 - main milestone Jan 10, 2025
@geoand geoand deleted the quarkus.uuid branch January 10, 2025 04:41
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 10, 2025
@geoand
Copy link
Contributor Author

geoand commented Jan 15, 2025

It seems like there are plenty more places where UUID.randomUUID() is used during startup that would need to be "fixed" as well.

geoand added a commit to geoand/quarkus that referenced this pull request Jan 15, 2025

Verified

This commit was signed with the committer’s verified signature.
khusika Khusika Dhamar Gusti
Follow up of: quarkusio#45434
carlesarnal pushed a commit to carlesarnal/quarkus that referenced this pull request Feb 6, 2025

Verified

This commit was signed with the committer’s verified signature.
khusika Khusika Dhamar Gusti
Follow up of: quarkusio#45434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants