Skip to content

Commit

Permalink
Make production of quarkus.uuid lazy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
geoand committed Jan 8, 2025
1 parent 9289bab commit aef3a1f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ void generateConfigClass(
public void suppressNonRuntimeConfigChanged(
BuildProducer<SuppressNonRuntimeConfigChangedWarningBuildItem> suppressNonRuntimeConfigChanged) {
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.profile"));
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.uuid"));
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.default-locale"));
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.locales"));
suppressNonRuntimeConfigChanged.produce(new SuppressNonRuntimeConfigChangedWarningBuildItem("quarkus.test.arg-line"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ public interface ConfigConfig {
@WithDefault("warn")
BuildTimeMismatchAtRuntime buildTimeMismatchAtRuntime();

/**
* 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();

enum BuildTimeMismatchAtRuntime {
warn,
fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.quarkus.runtime.configuration;

import java.util.Set;
import java.util.UUID;

import org.eclipse.microprofile.config.spi.ConfigSource;

import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilderCustomizer;

Expand All @@ -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() {

private static final String QUARKUS_UUID = "quarkus.uuid";

@Override
public Set<String> getPropertyNames() {
return Set.of(QUARKUS_UUID);
}

@Override
public String getValue(String propertyName) {
if (propertyName.equals(QUARKUS_UUID)) {
return Holder.UUID_VALUE;
}
return null;
}

@Override
public String getName() {
return "QuarkusUUIDConfigSource";
}

@Override
public int getOrdinal() {
return Integer.MIN_VALUE;
}

// acts as a lazy value supplier
private static class Holder {
private static final String UUID_VALUE = UUID.randomUUID().toString();
}
});

builder.forClassLoader(Thread.currentThread().getContextClassLoader())
.addDefaultInterceptors()
Expand Down

0 comments on commit aef3a1f

Please sign in to comment.