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

Polish code with ResettableSystemProperties #40627

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import io.quarkus.deployment.util.ContainerRuntimeUtil;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.maven.dependency.ResolvedDependency;
import io.quarkus.runtime.ResettableSystemProperties;

public class JibProcessor {

Expand Down Expand Up @@ -255,15 +256,13 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig,
for (String additionalTag : containerImage.getAdditionalTags()) {
containerizer.withAdditionalTag(additionalTag);
}
String previousContextStorageSysProp = null;
try {
// Jib uses the Google HTTP Client under the hood which attempts to record traces via OpenCensus which is wired
// to delegate to OpenTelemetry.
// This can lead to problems with the Quarkus OpenTelemetry extension which expects Vert.x to be running,
// something that is not the case at build time, see https://github.com/quarkusio/quarkus/issues/22864.
previousContextStorageSysProp = System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP,
"default");

// Jib uses the Google HTTP Client under the hood which attempts to record traces via OpenCensus which is wired
// to delegate to OpenTelemetry.
// This can lead to problems with the Quarkus OpenTelemetry extension which expects Vert.x to be running,
// something that is not the case at build time, see https://github.com/quarkusio/quarkus/issues/22864.
try (var resettableSystemProperties = ResettableSystemProperties
.of(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP, "default")) {
JibContainer container = containerizeUnderLock(jibContainerBuilder, containerizer);
log.infof("%s container image %s (%s)\n",
containerImageConfig.isPushExplicitlyEnabled() ? "Pushed" : "Created",
Expand All @@ -272,12 +271,6 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig,
return container;
} catch (Exception e) {
throw new RuntimeException("Unable to create container image", e);
} finally {
if (previousContextStorageSysProp == null) {
System.clearProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP);
} else {
System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP, previousContextStorageSysProp);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.vertx.VertxHttpClientBuilder;
import io.quarkus.runtime.ResettableSystemProperties;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.file.FileSystemOptions;
Expand All @@ -35,21 +36,12 @@ private Vertx createVertxInstance() {
// This is done using the DISABLE_DNS_RESOLVER_PROP_NAME system property.
// The DNS resolver used by vert.x is configured during the (synchronous) initialization.
// So, we just need to disable the async resolver around the Vert.x instance creation.
String originalValue = System.getProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
Vertx vertx;
try {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, "true");
vertx = Vertx.vertx(new VertxOptions().setFileSystemOptions(
try (var resettableSystemProperties = ResettableSystemProperties.of(
DISABLE_DNS_RESOLVER_PROP_NAME, "true")) {
return Vertx.vertx(new VertxOptions().setFileSystemOptions(
new FileSystemOptions().setFileCachingEnabled(false).setClassPathResolvingEnabled(false)));
} finally {
// Restore the original value
if (originalValue == null) {
System.clearProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
} else {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, originalValue);
}

}
return vertx;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.quarkus.runtime.ResettableSystemProperties;
import io.quarkus.runtime.util.ClassPathUtils;
import io.smallrye.mutiny.Uni;
import io.vertx.core.VertxOptions;
Expand Down Expand Up @@ -62,20 +63,10 @@ private Vertx createVertxInstance() {
// This is done using the DISABLE_DNS_RESOLVER_PROP_NAME system property.
// The DNS resolver used by vert.x is configured during the (synchronous) initialization.
// So, we just need to disable the async resolver around the Vert.x instance creation.
String originalValue = System.getProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
Vertx vertx;
try {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, "true");
vertx = Vertx.vertx(new VertxOptions());
} finally {
// Restore the original value
if (originalValue == null) {
System.clearProperty(DISABLE_DNS_RESOLVER_PROP_NAME);
} else {
System.setProperty(DISABLE_DNS_RESOLVER_PROP_NAME, originalValue);
}
try (var resettableSystemProperties = ResettableSystemProperties.of(
DISABLE_DNS_RESOLVER_PROP_NAME, "true")) {
return Vertx.vertx(new VertxOptions());
}
return vertx;
}

public static WebClient createHttpClient(Vertx vertx, SpringCloudConfigClientConfig config) {
Expand Down
Loading