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

chore: prepare showcase for Graal SDK 23.x #3574

Merged
merged 6 commits into from
Jan 24, 2025
Merged

Conversation

diegomarquezp
Copy link
Contributor

@diegomarquezp diegomarquezp commented Jan 20, 2025

Approach

Register java.time.Instant to the reflection configuration of gax-grpc (see grpc code interacting with this class)

This comes from a behavior change in Graal for JDK 22, which introduced a new class initialization strategy called strict image heap, which is enforced by default since then.

Proof:

com.google.showcase.v1beta1.EchoClientTest > blockExceptionTest SUCCESSFUL


Test run finished after 95953 ms
[        30 containers found      ]
[         0 containers skipped    ]
[        30 containers started    ]
[         0 containers aborted    ]
[        30 containers successful ]
[         0 containers failed     ]
[       337 tests found           ]
[         1 tests skipped         ]
[       336 tests started         ]
[         0 tests aborted         ]
[       336 tests successful      ]
[         0 tests failed          ]

[INFO]
[INFO] --- jacoco:0.8.12:report (report) @ gapic-showcase ---
[INFO] Loading execution data file /usr/local/google/home/diegomarquezp/google/sdk-platform-java/showcase/gapic-showcase/target/jacoco.exec
[INFO] Analyzed bundle 'GAPIC Showcase Client' with 125 classes
[WARNING] Classes in bundle 'GAPIC Showcase Client' do not match with execution data. For report generation the same class files must be used as at runtime.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceStub does not match.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonMessagingCallableFactory does not match.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonSequenceServiceCallableFactory does not match.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonTestingCallableFactory does not match.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonTestingStub does not match.
[WARNING] Execution data for class com/google/showcase/v1beta1/stub/HttpJsonMessagingStub does not match.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for GAPIC Showcase Client Core Parent 0.0.1-SNAPSHOT:
[INFO]
[INFO] GAPIC Showcase Client Core Parent .................. SUCCESS [  1.709 s]
[INFO] proto-gapic-showcase-v1beta1 ....................... SUCCESS [  0.900 s]
[INFO] grpc-gapic-showcase-v1beta1 ........................ SUCCESS [  0.385 s]
[INFO] GAPIC Showcase Client .............................. SUCCESS [05:29 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:34 min
[INFO] Finished at: 2025-01-20T19:04:42Z
[INFO] ------------------------------------------------------------------------

@product-auto-label product-auto-label bot added the size: xs Pull request size is extra small. label Jan 20, 2025
@@ -0,0 +1,3 @@
Args = --initialize-at-build-time=io.grpc.internal.TimeProvider,\
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know why they have to be added? Are they showcase specific or we have to add them to common modules like Gax as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's definitely at the grpc level. I'll test with another library to see if it happens and possible move this config to gax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I obtained this from trying the native tests in java-firestore

JUnit Vintage:SpannerClientTest
    ClassSource [className = 'com.google.cloud.spanner.v1.SpannerClientTest', filePosition = null]
    => org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures)
        java.lang.NoClassDefFoundError: Could not initialize class io.grpc.internal.TimeProvider
        java.lang.NullPointerException: <no message>
         io.grpc.internal.CallTracer$1.create(CallTracer.java:74)
         io.grpc.internal.ServerImpl.<init>(ServerImpl.java:164)
         io.grpc.internal.ServerImplBuilder.build(ServerImplBuilder.java:245)
         io.grpc.ForwardingServerBuilder.build(ForwardingServerBuilder.java:201)
         com.google.api.gax.grpc.testing.MockServiceHelper.<init>(MockServiceHelper.java:62)
         [...]
         com.google.cloud.spanner.v1.SpannerClientTest.stopServer(SpannerClientTest.java:112)
         java.base@23.0.1/java.lang.reflect.Method.invoke(Method.java:580)

I'll move this to gax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

So if I understand correctly, TimeProvider and InstantTimeProvider are now used during client initialization by grpc-java, hence we have to add them to native-image.properties? This is not due to GraalVM upgrade but rather a grpc upgrade?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, Diego! I think the solution makes sense.
However, looking at the change in grpc, we should've run into this error since two months ago, do we know why only GraalSDK 23.x triggered this error?

Copy link
Contributor Author

@diegomarquezp diegomarquezp Jan 24, 2025

Choose a reason for hiding this comment

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

I'll look into commits and release notes of the Graal SDK.

Copy link
Contributor Author

@diegomarquezp diegomarquezp Jan 24, 2025

Choose a reason for hiding this comment

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

Looks like Graal SDK 22 introduced a new class initialization strategy called strict image heap, which is enforced by default.

Since this is a behavior change affecting which classes are initialized, I'm leaning towards this new strategy being the cause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the parent feature: oracle/graal#4684
This was followed by the new strategy by default: oracle/graal#7474

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect, thanks! Do you mind adding these info to the description? Also be mindful that this change may affect handwritten libraries as well.

Copy link

Copy link

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@diegomarquezp diegomarquezp merged commit 540c8e5 into main Jan 24, 2025
51 of 52 checks passed
@diegomarquezp diegomarquezp deleted the showcase-graal-23 branch January 24, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: xs Pull request size is extra small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants