-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not use Google's HTTP client to get the default project ID
As described in [this issue](quarkusio/quarkus#35500), Quarkus w/ the Google clooud services and OpenCensus shim does not startup due to a static initialization issue. `com.google.cloud.ServiceOptions` is used by the extension to get the Google cloud default-project-ID, which uses Google's HTTP client, which uses OpenCensus, which triggers an initialization of OpenTelemetry, which conflicts with the OTel init from Quarkus. This change updates `GcpDefaultsConfigSourceFactory` to use Java's HTTP client. See also #487, the alternatives mentioned in [this comment](#487 (comment)) to implement a `ConfigSource` and in [this comment](#487 (comment)) to set `otel.java.global-autoconfigure.enabled=false)` end in the same OpenCensus/OpenTracing init race. Fixes quarkusio/quarkus#35500
- Loading branch information
Showing
4 changed files
with
225 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...st/java/io/quarkiverse/googlecloudservices/common/GcpDefaultsConfigSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkiverse.googlecloudservices.common; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.smallrye.config.ConfigSourceContext; | ||
import io.smallrye.config.ConfigValue; | ||
|
||
class GcpDefaultsConfigSourceFactoryTest { | ||
@Test | ||
void configSourceWorks() { | ||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("true").build()); | ||
|
||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory(() -> "test-project-id") | ||
.getConfigSources(context); | ||
assertThat(configSources).asList().hasSize(1); | ||
|
||
ConfigSource configSource = configSources.iterator().next(); | ||
assertThat(configSource.getProperties()).containsEntry("quarkus.google.cloud.project-id", "test-project-id"); | ||
} | ||
|
||
@Test | ||
void metadataServerDisabled() { | ||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("false").build()); | ||
|
||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory(() -> "test-project-id") | ||
.getConfigSources(context); | ||
assertThat(configSources).isEmpty(); | ||
} | ||
|
||
/** | ||
* Tests that OpenCensus does not get implicitly initialized and in turn does not "collide" with | ||
* OpenTelemetry, as used in Quarkus. | ||
*/ | ||
@Test | ||
void staticOpenCensusOpenTelemetryInit() { | ||
try { | ||
GlobalOpenTelemetry.resetForTest(); | ||
|
||
ConfigSourceContext context = Mockito.mock(ConfigSourceContext.class); | ||
Mockito.when(context.getValue("quarkus.google.cloud.enable-metadata-server")) | ||
.thenReturn(ConfigValue.builder().withValue("true").build()); | ||
|
||
// Uses the "real" implementation that tries to fetch the default-project-id | ||
Iterable<ConfigSource> configSources = new GcpDefaultsConfigSourceFactory().getConfigSources(context); | ||
assertThat(configSources).asList().hasSizeLessThanOrEqualTo(1); | ||
|
||
// This is a pretty ugly way, because it changes static state | ||
GlobalOpenTelemetry.set(OpenTelemetry.noop()); | ||
} finally { | ||
GlobalOpenTelemetry.resetForTest(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
<compiler-plugin.version>3.8.1</compiler-plugin.version> | ||
<enforcer-plugin.version>3.4.1</enforcer-plugin.version> | ||
<assertj.version>3.24.2</assertj.version> | ||
<opentelemetry-alpha.version>1.28.0-alpha</opentelemetry-alpha.version> | ||
</properties> | ||
<scm> | ||
<connection>scm:git:[email protected]:quarkiverse/quarkus-google-cloud-services.git</connection> | ||
|
@@ -63,6 +64,11 @@ | |
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentelemetry</groupId> | ||
<artifactId>opentelemetry-opencensus-shim</artifactId> | ||
<version>${opentelemetry-alpha.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
|