-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(spanner): Cleanup GcpFallbackChannel creation and enable by default #12707
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
base: main
Are you sure you want to change the base?
Changes from all commits
d116c64
2958918
d3b9622
bca51a1
e3af9f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1164,61 +1164,49 @@ public void testFallbackIntegration_doesNotSwitchWhenThresholdNotMet() throws Ex | |
| OpenTelemetrySdk openTelemetry = | ||
| OpenTelemetrySdk.builder().setMeterProvider(meterProvider).build(); | ||
|
|
||
| SpannerOptions.useEnvironment( | ||
| new SpannerOptions.SpannerEnvironment() { | ||
| @Override | ||
| public boolean isEnableGcpFallback() { | ||
| return true; | ||
| } | ||
| }); | ||
| SpannerOptions.Builder builder = | ||
| SpannerOptions.newBuilder() | ||
| .setProjectId("test-project") | ||
| .setEnableDirectAccess(true) | ||
| .setHost("http://localhost:1") // Closed port | ||
| .setCredentials(NoCredentials.getInstance()) | ||
| .setOpenTelemetry(openTelemetry); | ||
| // Make sure the ExecuteBatchDml RPC fails quickly to keep the test fast. | ||
| // Note that the timeout is actually not used. It is the fact that it does not retry that | ||
| // makes it fail fast. | ||
| builder | ||
| .getSpannerStubSettingsBuilder() | ||
| .executeBatchDmlSettings() | ||
| .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10)); | ||
| // Setup Options with invalid host to force error | ||
| SpannerOptions options = builder.build(); | ||
|
|
||
| TestableGapicSpannerRpc rpc = new TestableGapicSpannerRpc(options); | ||
| try { | ||
| SpannerOptions.Builder builder = | ||
| SpannerOptions.newBuilder() | ||
| .setProjectId("test-project") | ||
| .setEnableDirectAccess(true) | ||
| .setHost("http://localhost:1") // Closed port | ||
| .setCredentials(NoCredentials.getInstance()) | ||
| .setOpenTelemetry(openTelemetry); | ||
| // Make sure the ExecuteBatchDml RPC fails quickly to keep the test fast. | ||
| // Note that the timeout is actually not used. It is the fact that it does not retry that | ||
| // makes it fail fast. | ||
| builder | ||
| .getSpannerStubSettingsBuilder() | ||
| .executeBatchDmlSettings() | ||
| .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10)); | ||
| // Setup Options with invalid host to force error | ||
| SpannerOptions options = builder.build(); | ||
|
|
||
| TestableGapicSpannerRpc rpc = new TestableGapicSpannerRpc(options); | ||
| try { | ||
| // Make a call that is expected to fail | ||
| SpannerException exception = | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| rpc.executeBatchDml( | ||
| com.google.spanner.v1.ExecuteBatchDmlRequest.newBuilder() | ||
| .setSession("projects/p/instances/i/databases/d/sessions/s") | ||
| .build(), | ||
| null)); | ||
| assertEquals(ErrorCode.UNAVAILABLE, exception.getErrorCode()); | ||
|
|
||
| // Wait briefly for the 10ms period to trigger the fallback check | ||
| Thread.sleep(10); | ||
|
|
||
| // Verify Fallback via Metrics | ||
| Collection<MetricData> metrics = metricReader.collectAllMetrics(); | ||
| boolean fallbackOccurred = | ||
| metrics.stream() | ||
| .anyMatch(md -> md.getName().contains("fallback_count") && hasValue(md)); | ||
|
|
||
| assertFalse("Fallback metric should not be present", fallbackOccurred); | ||
|
|
||
| } finally { | ||
| rpc.shutdown(); | ||
| } | ||
| // Make a call that is expected to fail | ||
| SpannerException exception = | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| rpc.executeBatchDml( | ||
| com.google.spanner.v1.ExecuteBatchDmlRequest.newBuilder() | ||
| .setSession("projects/p/instances/i/databases/d/sessions/s") | ||
| .build(), | ||
| null)); | ||
| assertEquals(ErrorCode.UNAVAILABLE, exception.getErrorCode()); | ||
|
|
||
| // Wait briefly for the 10ms period to trigger the fallback check | ||
| Thread.sleep(10); | ||
|
Contributor
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. The test waits for 10ms, but the production code now sets the fallback period to 3 minutes (Duration.ofMinutes(3)). This will likely cause the test to fail as the fallback check won't trigger within the sleep duration. Consider overriding the period in the test to a smaller value or adjusting the test expectations. Additionally, please remove the stale code comment '10ms period' instead of updating it, as it no longer reflects the implementation. References
|
||
|
|
||
| // Verify Fallback via Metrics | ||
| Collection<MetricData> metrics = metricReader.collectAllMetrics(); | ||
| boolean fallbackOccurred = | ||
| metrics.stream().anyMatch(md -> md.getName().contains("fallback_count") && hasValue(md)); | ||
|
|
||
| assertFalse("Fallback metric should not be present", fallbackOccurred); | ||
|
|
||
| } finally { | ||
| SpannerOptions.useDefaultEnvironment(); | ||
| rpc.shutdown(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1255,64 +1243,52 @@ public void testFallbackIntegration_switchesToFallbackOnFailure() throws Excepti | |
| OpenTelemetrySdk openTelemetry = | ||
| OpenTelemetrySdk.builder().setMeterProvider(meterProvider).build(); | ||
|
|
||
| SpannerOptions.useEnvironment( | ||
| new SpannerOptions.SpannerEnvironment() { | ||
| @Override | ||
| public boolean isEnableGcpFallback() { | ||
| return true; | ||
| } | ||
| }); | ||
| SpannerOptions.Builder builder = | ||
| SpannerOptions.newBuilder() | ||
| .setProjectId("test-project") | ||
| .setEnableDirectAccess(true) | ||
| .setHost("http://localhost:1") // Closed port | ||
| .setCredentials(NoCredentials.getInstance()) | ||
| .setOpenTelemetry(openTelemetry); | ||
| // Make sure the ExecuteBatchDml RPC fails quickly to keep the test fast. | ||
| // Note that the timeout is actually not used. It is the fact that it does not retry that | ||
| // makes it fail fast. | ||
| builder | ||
| .getSpannerStubSettingsBuilder() | ||
| .executeBatchDmlSettings() | ||
| .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10)); | ||
| // Setup Options with invalid host to force error | ||
| SpannerOptions options = builder.build(); | ||
|
|
||
| TestableGapicSpannerRpcWithLowerMinFailedCalls rpc = | ||
| new TestableGapicSpannerRpcWithLowerMinFailedCalls(options); | ||
| try { | ||
| SpannerOptions.Builder builder = | ||
| SpannerOptions.newBuilder() | ||
| .setProjectId("test-project") | ||
| .setEnableDirectAccess(true) | ||
| .setHost("http://localhost:1") // Closed port | ||
| .setCredentials(NoCredentials.getInstance()) | ||
| .setOpenTelemetry(openTelemetry); | ||
| // Make sure the ExecuteBatchDml RPC fails quickly to keep the test fast. | ||
| // Note that the timeout is actually not used. It is the fact that it does not retry that | ||
| // makes it fail fast. | ||
| builder | ||
| .getSpannerStubSettingsBuilder() | ||
| .executeBatchDmlSettings() | ||
| .setSimpleTimeoutNoRetriesDuration(Duration.ofSeconds(10)); | ||
| // Setup Options with invalid host to force error | ||
| SpannerOptions options = builder.build(); | ||
|
|
||
| TestableGapicSpannerRpcWithLowerMinFailedCalls rpc = | ||
| new TestableGapicSpannerRpcWithLowerMinFailedCalls(options); | ||
| try { | ||
| // Make a call that is expected to fail | ||
| SpannerException exception = | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| rpc.executeBatchDml( | ||
| com.google.spanner.v1.ExecuteBatchDmlRequest.newBuilder() | ||
| .setSession("projects/p/instances/i/databases/d/sessions/s") | ||
| .build(), | ||
| null)); | ||
| assertEquals(ErrorCode.UNAVAILABLE, exception.getErrorCode()); | ||
|
|
||
| // Wait briefly for the 10ms period to trigger the fallback check | ||
| Thread.sleep(10); | ||
|
|
||
| // Verify Fallback via Metrics | ||
| Collection<MetricData> metrics = metricReader.collectAllMetrics(); | ||
| boolean fallbackOccurred = | ||
| metrics.stream() | ||
| .anyMatch(md -> md.getName().contains("fallback_count") && hasValue(md)); | ||
|
|
||
| assertTrue( | ||
| "Fallback metric should be present, indicating GcpFallbackChannel is active", | ||
| fallbackOccurred); | ||
|
|
||
| } finally { | ||
| rpc.shutdown(); | ||
| } | ||
| // Make a call that is expected to fail | ||
| SpannerException exception = | ||
| assertThrows( | ||
| SpannerException.class, | ||
| () -> | ||
| rpc.executeBatchDml( | ||
| com.google.spanner.v1.ExecuteBatchDmlRequest.newBuilder() | ||
| .setSession("projects/p/instances/i/databases/d/sessions/s") | ||
| .build(), | ||
| null)); | ||
| assertEquals(ErrorCode.UNAVAILABLE, exception.getErrorCode()); | ||
|
|
||
| // Wait briefly for the 10ms period to trigger the fallback check | ||
| Thread.sleep(10); | ||
|
Contributor
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. |
||
|
|
||
| // Verify Fallback via Metrics | ||
| Collection<MetricData> metrics = metricReader.collectAllMetrics(); | ||
| boolean fallbackOccurred = | ||
| metrics.stream().anyMatch(md -> md.getName().contains("fallback_count") && hasValue(md)); | ||
|
|
||
| assertTrue( | ||
| "Fallback metric should be present, indicating GcpFallbackChannel is active", | ||
| fallbackOccurred); | ||
|
|
||
| } finally { | ||
| SpannerOptions.useDefaultEnvironment(); | ||
| rpc.shutdown(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
The Duration class is used in this file (e.g., at line 566) but it is not imported. Please add the missing import for java.time.Duration.