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

Do not use Google's HTTP client to get the default project ID #502

Merged

Conversation

snazy
Copy link
Contributor

@snazy snazy commented Sep 14, 2023

As described in this issue, 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 to implement a ConfigSource and in this comment to set otel.java.global-autoconfigure.enabled=false) end in the same OpenCensus/OpenTracing init race.

Fixes quarkusio/quarkus#35500

@snazy
Copy link
Contributor Author

snazy commented Sep 14, 2023

/cc @geoand

@snazy
Copy link
Contributor Author

snazy commented Sep 14, 2023

Manually verified that Quarkus starts w/ the OpenCensus-shim.

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@snazy
Copy link
Contributor Author

snazy commented Sep 14, 2023

Also manually verified (in jshell in a GCP VM) that the getAppEngineProjectIdFromMetadataServer() function yields the default project ID

.header("Metadata-Flavor", "Google").build();
HttpResponse.BodyHandler<String> bodyHandler = HttpResponse.BodyHandlers.ofString();
HttpResponse<String> response = client.send(request, bodyHandler);
return headerContainsMetadataFlavor(response) ? response.body() : "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it respond null and not empty if not metadata (as the remaining if chain check for nullity)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Good catch!

}

@Test
void staticOpenCensusOpenTelemetryInit() {
Copy link
Collaborator

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?)

Copy link
Contributor Author

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.

@@ -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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<opentelemetry-alpha.version>1.28.0-alpha</opentelemetry-alpha.version>
<opentelemetry.version>1.28.0-alpha</opentelemetry.version>

And use the same under

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@snazy snazy force-pushed the default-project-id-no-google-http branch from 8ec386e to 80d7368 Compare September 18, 2023 12:39
Comment on lines 122 to 130
<!-- <plugin>-->
<!-- <artifactId>maven-surefire-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <systemProperties>-->
<!-- <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>-->
<!-- <gcloud.test>true</gcloud.test>-->
<!-- </systemProperties>-->
<!-- </configuration>-->
<!-- </plugin>-->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you comment this? If it's not needed you can remove it but as far as I remember this is needed to have logs property formatted on tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over (sorry)

I initially added it, because I was thinking of some @QuarkusTest, but then realized that it's good enough to check the static-init race.

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 quarkiverse#487, the alternatives mentioned in [this comment](quarkiverse#487 (comment)) to implement a `ConfigSource` and in [this comment](quarkiverse#487 (comment)) to set `otel.java.global-autoconfigure.enabled=false)` end in the same OpenCensus/OpenTracing init race.

Fixes quarkusio/quarkus#35500
@snazy snazy force-pushed the default-project-id-no-google-http branch from 80d7368 to 14e3bc6 Compare September 18, 2023 15:59
Copy link
Collaborator

@loicmathieu loicmathieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll merge it tomorrow for the next release based on Quarkus 3.4

@snazy
Copy link
Contributor Author

snazy commented Sep 18, 2023

@loicmathieu I personally don't mind (can wait for 3.4, if the 3.4 platform-bom references it), but could be useful for other users to have this also in 3.3.x.

@loicmathieu loicmathieu merged commit e744107 into quarkiverse:main Sep 19, 2023
1 check passed
@snazy snazy deleted the default-project-id-no-google-http branch September 19, 2023 08:05
@loicmathieu
Copy link
Collaborator

@all-contributors please add @snazy for code

@allcontributors
Copy link
Contributor

@loicmathieu

I've put up a pull request to add @snazy! 🎉

@loicmathieu
Copy link
Collaborator

2.5.0 is released with the fix.
If there is a strong need to backport it ot 2.4.0 (which is based on Quarkus 3.3) I can do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenTelemetry / OpenCensus race (since Quarkus 3.3.0)
3 participants