feat: Add E2E fallback to the spanner client.#4282
feat: Add E2E fallback to the spanner client.#4282kinsaurralde wants to merge 23 commits intogoogleapis:mainfrom
Conversation
Summary of ChangesHello @kinsaurralde, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant reliability enhancement to the Spanner client by adding an end-to-end fallback mechanism. This ensures that client connections remain robust by automatically falling back to a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces E2E fallback for the Spanner client, allowing it to fall back to CloudPath when DirectPath is unavailable. This is a significant feature for improving connection reliability. The implementation also includes a good refactoring that moves the logic for creating the default channel provider builder into a helper function.
My review includes a few suggestions to improve code quality and maintainability:
- Using the primitive
booleaninstead of theBooleanwrapper for a method parameter to avoid potentialNullPointerException. - Adding a comment to explain a particularly complex piece of code for creating the fallback channel builder, which will help future maintainers.
- Converting an anonymous inner class to a more concise lambda expression.
Overall, the changes are well-structured, and the new fallback mechanism is a valuable addition.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Show resolved
Hide resolved
| cloudPathBuilder.intercept(new ClientInterceptor() { | ||
| @Override | ||
| public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
| MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
| return next.newCall(method, callOptions.withCallCredentials(MoreCallCredentials.from(credentials))); | ||
| } | ||
| }); |
There was a problem hiding this comment.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an end-to-end fallback mechanism for the Spanner client, enabling it to switch from DirectPath to CloudPath when DirectPath is unavailable. The implementation is well-structured, leveraging a custom FallbackChannelBuilder to integrate with GAX. Additionally, the logic for creating the channel provider has been thoughtfully refactored into a reusable helper function. The new tests effectively validate the fallback functionality. I've included one suggestion to refactor the test helpers to improve maintainability by reducing code duplication. Overall, this is a valuable and well-executed feature.
I am having trouble creating individual review comments. Click here to see my feedback.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java (1083-1100)
To reduce code duplication, you can merge TestableGapicSpannerRpc and TestableGapicSpannerRpcWithLowerMinFailedCalls into a single helper class that accepts the minFailedCalls value in its constructor. This makes the test setup more flexible and maintainable.
After applying this suggestion, you can remove the TestableGapicSpannerRpcWithLowerMinFailedCalls class and update the tests to instantiate the new TestableGapicSpannerRpc class like this:
new TestableGapicSpannerRpc(options, 10)fortestFallbackIntegration_doesNotSwitchWhenThresholdNotMetnew TestableGapicSpannerRpc(options, 1)fortestFallbackIntegration_switchesToFallbackOnFailure
static class TestableGapicSpannerRpc extends GapicSpannerRpc {
private final int minFailedCallsForTest;
public TestableGapicSpannerRpc(SpannerOptions options, int minFailedCallsForTest) {
super(options);
this.minFailedCallsForTest = minFailedCallsForTest;
}
@Override
GcpFallbackChannelOptions createFallbackChannelOptions(
GcpFallbackOpenTelemetry fallbackTelemetry, int minFailedCalls) {
// Override default 1-minute period to 10ms for instant testing
return GcpFallbackChannelOptions.newBuilder()
.setPrimaryChannelName("directpath")
.setFallbackChannelName("cloudpath")
.setMinFailedCalls(this.minFailedCallsForTest)
.setPeriod(Duration.ofMillis(10))
.setGcpFallbackOpenTelemetry(fallbackTelemetry)
.build();
}
}
Adding E2E fallback will allow spanner clients to fallback to cloudpath when directpath is unavailable.
Also moves the logic to create defaultChannelProviderBuilder into a helper function.