-
Notifications
You must be signed in to change notification settings - Fork 33
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
Do not use Google's HTTP client to get the default project ID #502
Merged
loicmathieu
merged 1 commit into
quarkiverse:main
from
snazy:default-project-id-no-google-http
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And use the same under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Took the approach that is used in Quarkus, differing between the "alpha" and "non-alpha" artifacts. |
||||||
</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> | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this test? Does it crash without the change (so it's a non-regression test?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fails without the prod code change. Added a comment.