-
Notifications
You must be signed in to change notification settings - Fork 105
feat(bigtable): unary direct access checker and it's implementation #2840
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
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.csm.tracers; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.MetricRegistry; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo; | ||
|
|
||
| @InternalApi | ||
| public class DefaultDirectPathCompatibleTracer implements DirectPathCompatibleTracer { | ||
| private final ClientInfo clientInfo; | ||
| private final MetricRegistry.RecorderRegistry recorder; | ||
|
|
||
| public DefaultDirectPathCompatibleTracer( | ||
| ClientInfo clientInfo, MetricRegistry.RecorderRegistry recorder) { | ||
| this.clientInfo = clientInfo; | ||
| this.recorder = recorder; | ||
| } | ||
|
|
||
| @Override | ||
| public void recordSuccess(String ipPreference) { | ||
| recorder.dpCompatGuage.recordSuccess(clientInfo, ipPreference); | ||
| } | ||
|
|
||
| @Override | ||
| public void recordFailure(String reason) { | ||
| recorder.dpCompatGuage.recordFailure(clientInfo, reason); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.csm.tracers; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
|
|
||
| /** Interface for recording DirectPath/DirectAccess eligibility metrics. */ | ||
| @InternalApi | ||
| public interface DirectPathCompatibleTracer { | ||
|
|
||
| /** | ||
| * Records that the environment is eligible and successfully connected via DirectPath. | ||
| * | ||
| * @param ipPreference The IP preference used (e.g., "ipv6"). | ||
| */ | ||
| void recordSuccess(String ipPreference); | ||
|
|
||
| /** | ||
| * Records that the environment is not eligible or failed to connect via DirectPath. | ||
| * | ||
| * @param reason The reason for the failure (e.g., "routing_check_failed"). | ||
| */ | ||
| void recordFailure(String reason); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.stub; | ||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import io.grpc.ManagedChannel; | ||
| import java.io.IOException; | ||
|
|
||
| @InternalApi | ||
| public interface BigtableChannelFactory { | ||
| ManagedChannel createSingleChannel() throws IOException; | ||
|
Comment on lines
+23
to
+24
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. why not use Supplier |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.stub; | ||
|
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. If this is unary/jetstream agnostic, then it should live in data.v2.internal...maybe create a pacakge for dp? |
||
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.tracers.DirectPathCompatibleTracer; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| @InternalApi | ||
| /* Evaluates whether a given channel supports Direct Access. */ | ||
| public interface DirectAccessChecker { | ||
| /** | ||
| * Evaluates if Direct Access is available by creating a test channel. | ||
| * | ||
| * @param channelFactory A factory to create the test channel | ||
| * @return true if the channel is eligible for Direct Access | ||
| */ | ||
| boolean check(BigtableChannelFactory channelFactory, @Nullable DirectPathCompatibleTracer tracer); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,6 +242,25 @@ public ClientOperationSettings getPerOpSettings() { | |
| return perOpSettings; | ||
| } | ||
|
|
||
| /** Applies common pool, message size, and keep-alive settings to the provided builder. */ | ||
| private static InstantiatingGrpcChannelProvider.Builder commonTraits( | ||
| InstantiatingGrpcChannelProvider.Builder builder) { | ||
| return builder | ||
| .setChannelPoolSettings( | ||
| ChannelPoolSettings.builder() | ||
| .setInitialChannelCount(10) | ||
| .setMinRpcsPerChannel(1) | ||
| // Keep it conservative as we scale the channel size every 1min | ||
| // and delta is 2 channels. | ||
| .setMaxRpcsPerChannel(25) | ||
| .setPreemptiveRefreshEnabled(true) | ||
| .build()) | ||
| .setMaxInboundMessageSize(MAX_MESSAGE_SIZE) | ||
| .setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval | ||
| .setKeepAliveTimeout( | ||
| Duration.ofSeconds(10)); // wait this long before considering the connection dead | ||
| } | ||
|
|
||
| /** Returns a builder for the default ChannelProvider for this service. */ | ||
| public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { | ||
| InstantiatingGrpcChannelProvider.Builder grpcTransportProviderBuilder = | ||
|
|
@@ -261,20 +280,24 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi | |
| Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS)); | ||
| } | ||
| } | ||
| return grpcTransportProviderBuilder | ||
| .setChannelPoolSettings( | ||
| ChannelPoolSettings.builder() | ||
| .setInitialChannelCount(10) | ||
| .setMinRpcsPerChannel(1) | ||
| // Keep it conservative as we scale the channel size every 1min | ||
| // and delta is 2 channels. | ||
| .setMaxRpcsPerChannel(25) | ||
| .setPreemptiveRefreshEnabled(true) | ||
| .build()) | ||
| .setMaxInboundMessageSize(MAX_MESSAGE_SIZE) | ||
| .setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval | ||
| .setKeepAliveTimeout( | ||
| Duration.ofSeconds(10)); // wait this long before considering the connection dead | ||
| return commonTraits(grpcTransportProviderBuilder); | ||
| } | ||
|
|
||
| /** Applies Direct Access traits (DirectPath & ALTS) to an existing builder. */ | ||
| public static InstantiatingGrpcChannelProvider.Builder applyDirectAccessTraits( | ||
| InstantiatingGrpcChannelProvider.Builder builder) { | ||
|
|
||
| builder | ||
| .setAttemptDirectPathXds() | ||
| .setAttemptDirectPath(true) | ||
| .setAllowNonDefaultServiceAccount(true); | ||
|
|
||
| if (!DIRECT_PATH_BOUND_TOKEN_DISABLED) { | ||
| builder.setAllowHardBoundTokenTypes( | ||
| Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS)); | ||
| } | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| @SuppressWarnings("WeakerAccess") | ||
|
|
@@ -609,12 +632,16 @@ private Builder() { | |
|
|
||
| perOpSettings = new ClientOperationSettings.Builder(); | ||
|
|
||
| // Note: RouteLookup evaluates and returns directpath targets | ||
| // only if Traffic Director sends the request (with grpc as target type) | ||
| // For GFE/CFE, sending setDirectAccessRequested | ||
| // is fine as GFE/CFE sends with gslb target type | ||
| featureFlags = | ||
| FeatureFlags.newBuilder() | ||
| .setReverseScans(true) | ||
| .setLastScannedRowResponses(true) | ||
| .setDirectAccessRequested(DIRECT_PATH_ENABLED) | ||
| .setTrafficDirectorEnabled(DIRECT_PATH_ENABLED) | ||
| .setDirectAccessRequested(true) | ||
| .setTrafficDirectorEnabled(true) | ||
|
Comment on lines
+643
to
+644
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. why you ignoring the env var? |
||
| .setPeerInfo(true); | ||
| } | ||
|
|
||
|
|
||
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.
dont make this nullable, instead add a NoopTracer in NoopMetrics