Skip to content

Commit 8a1ab70

Browse files
committed
Make production of quarkus.uuid lazy
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
1 parent 0d6a99e commit 8a1ab70

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java

-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ void generateConfigClass(
332332
public void suppressNonRuntimeConfigChanged(
333333
BuildProducer<SuppressNonRuntimeConfigChangedWarningBuildItem> suppressNonRuntimeConfigChanged) {
334334
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.profile"));
335-
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.uuid"));
336335
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.default-locale"));
337336
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.locales"));
338337
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.test.arg-line"));

core/runtime/src/main/java/io/quarkus/runtime/ConfigConfig.java

-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ public interface ConfigConfig {
7474
@WithDefault("warn")
7575
BuildTimeMismatchAtRuntime buildTimeMismatchAtRuntime();
7676

77-
/**
78-
* A property that allows accessing a generated UUID.
79-
* It generates that UUID at startup time. So it changes between two starts including in dev mode.
80-
* <br>
81-
* Access this generated UUID using expressions: `${quarkus.uuid}`.
82-
*/
83-
Optional<String> uuid();
84-
8577
enum BuildTimeMismatchAtRuntime {
8678
warn,
8779
fail

core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeConfigBuilder.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package io.quarkus.runtime.configuration;
22

3+
import java.util.Set;
34
import java.util.UUID;
45

6+
import org.eclipse.microprofile.config.spi.ConfigSource;
7+
58
import io.smallrye.config.SmallRyeConfigBuilder;
69
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;
710

@@ -12,7 +15,7 @@ public class RuntimeConfigBuilder implements SmallRyeConfigBuilderCustomizer {
1215
@Override
1316
public void configBuilder(final SmallRyeConfigBuilder builder) {
1417
new QuarkusConfigBuilderCustomizer().configBuilder(builder);
15-
builder.withDefaultValue("quarkus.uuid", UUID.randomUUID().toString());
18+
builder.withSources(new UuiConfigSource());
1619

1720
builder.forClassLoader(Thread.currentThread().getContextClassLoader())
1821
.addDefaultInterceptors()
@@ -23,4 +26,37 @@ public void configBuilder(final SmallRyeConfigBuilder builder) {
2326
public int priority() {
2427
return Integer.MIN_VALUE;
2528
}
29+
30+
private static class UuiConfigSource implements ConfigSource {
31+
32+
private static final String QUARKUS_UUID = "quarkus.uuid";
33+
34+
@Override
35+
public Set<String> getPropertyNames() {
36+
return Set.of(QUARKUS_UUID);
37+
}
38+
39+
@Override
40+
public String getValue(String propertyName) {
41+
if (propertyName.equals(QUARKUS_UUID)) {
42+
return Holder.UUID_VALUE;
43+
}
44+
return null;
45+
}
46+
47+
@Override
48+
public String getName() {
49+
return "QuarkusUUIDConfigSource";
50+
}
51+
52+
@Override
53+
public int getOrdinal() {
54+
return Integer.MIN_VALUE;
55+
}
56+
57+
// acts as a lazy value supplier ensuring that the UUID will only be produced when requested
58+
private static class Holder {
59+
private static final String UUID_VALUE = UUID.randomUUID().toString();
60+
}
61+
}
2662
}

integration-tests/smallrye-config/src/test/java/io/quarkus/it/smallrye/config/QuarkusConfigTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ void uuid() {
1919
.then()
2020
.statusCode(OK.getStatusCode())
2121
.body("value", is(notNullValue()))
22-
.body("configSourceName", equalTo("DefaultValuesConfigSource"));
22+
.body("configSourceName", equalTo("QuarkusUUIDConfigSource"));
2323

2424
given()
2525
.get("/config/uuid")
2626
.then()
2727
.statusCode(OK.getStatusCode())
2828
.body("value", is(notNullValue()))
29-
.body("configSourceName", equalTo("DefaultValuesConfigSource"));
29+
.body("configSourceName", equalTo("QuarkusUUIDConfigSource"));
3030
}
3131
}

0 commit comments

Comments
 (0)