Skip to content

Commit 30c17d5

Browse files
committed
fix
1 parent 547f461 commit 30c17d5

12 files changed

Lines changed: 198 additions & 199 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricsImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public MetricsImpl(
9797
this.internalRecorder = metricRegistry.newRecorderRegistry(internalOtel.getMeterProvider());
9898
this.pacemaker = new Pacemaker(internalRecorder, clientInfo, "background");
9999
this.channelPoolMetricsTracer = new ChannelPoolMetricsTracer(internalRecorder, clientInfo);
100-
this.directPathCompatibleTracer = new DefaultDirectPathCompatibleTracer(clientInfo, internalRecorder);
100+
this.directPathCompatibleTracer =
101+
new DefaultDirectPathCompatibleTracer(clientInfo, internalRecorder);
101102
this.grpcOtel =
102103
GrpcOpenTelemetry.newBuilder()
103104
.sdk(internalOtel)

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/DefaultDirectPathCompatibleTracer.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121

2222
@InternalApi
2323
public class DefaultDirectPathCompatibleTracer implements DirectPathCompatibleTracer {
24-
private final ClientInfo clientInfo;
25-
private final MetricRegistry.RecorderRegistry recorder;
24+
private final ClientInfo clientInfo;
25+
private final MetricRegistry.RecorderRegistry recorder;
2626

27-
public DefaultDirectPathCompatibleTracer(
28-
ClientInfo clientInfo, MetricRegistry.RecorderRegistry recorder) {
29-
this.clientInfo = clientInfo;
30-
this.recorder = recorder;
31-
}
27+
public DefaultDirectPathCompatibleTracer(
28+
ClientInfo clientInfo, MetricRegistry.RecorderRegistry recorder) {
29+
this.clientInfo = clientInfo;
30+
this.recorder = recorder;
31+
}
3232

33-
@Override
34-
public void recordSuccess(String ipPreference) {
35-
recorder.dpCompatGuage.recordSuccess(clientInfo, ipPreference);
36-
}
33+
@Override
34+
public void recordSuccess(String ipPreference) {
35+
recorder.dpCompatGuage.recordSuccess(clientInfo, ipPreference);
36+
}
3737

38-
@Override
39-
public void recordFailure(String reason) {
40-
recorder.dpCompatGuage.recordFailure(clientInfo, reason);
41-
}
38+
@Override
39+
public void recordFailure(String reason) {
40+
recorder.dpCompatGuage.recordFailure(clientInfo, reason);
41+
}
4242
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/tracers/DirectPathCompatibleTracer.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@
1717

1818
import com.google.api.core.InternalApi;
1919

20-
/**
21-
* Interface for recording DirectPath/DirectAccess eligibility metrics.
22-
*/
20+
/** Interface for recording DirectPath/DirectAccess eligibility metrics. */
2321
@InternalApi
2422
public interface DirectPathCompatibleTracer {
2523

26-
/**
27-
* Records that the environment is eligible and successfully connected via DirectPath.
28-
*
29-
* @param ipPreference The IP preference used (e.g., "ipv6").
30-
*/
31-
void recordSuccess(String ipPreference);
24+
/**
25+
* Records that the environment is eligible and successfully connected via DirectPath.
26+
*
27+
* @param ipPreference The IP preference used (e.g., "ipv6").
28+
*/
29+
void recordSuccess(String ipPreference);
3230

33-
/**
34-
* Records that the environment is not eligible or failed to connect via DirectPath.
35-
*
36-
* @param reason The reason for the failure (e.g., "routing_check_failed").
37-
*/
38-
void recordFailure(String reason);
39-
}
31+
/**
32+
* Records that the environment is not eligible or failed to connect via DirectPath.
33+
*
34+
* @param reason The reason for the failure (e.g., "routing_check_failed").
35+
*/
36+
void recordFailure(String reason);
37+
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import io.grpc.ManagedChannel;
20-
2120
import java.io.IOException;
2221

2322
@InternalApi
2423
public interface BigtableChannelFactory {
25-
ManagedChannel createSingleChannel() throws IOException;
24+
ManagedChannel createSingleChannel() throws IOException;
2625
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import io.grpc.Metadata;
3333
import io.grpc.Status;
3434
import io.grpc.auth.MoreCallCredentials;
35-
3635
import java.io.IOException;
3736
import java.io.UnsupportedEncodingException;
3837
import java.net.URLEncoder;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ public static BigtableClientContext create(
166166
transportProvider.build(),
167167
channelPrimer,
168168
metrics.getChannelPoolMetricsTracer(),
169-
backgroundExecutor, metrics.getDirectPathCompatibleTracer()
170-
);
169+
backgroundExecutor,
170+
metrics.getDirectPathCompatibleTracer());
171171

172172
builder.setTransportChannelProvider(btTransportProvider);
173173
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/DirectAccessChecker.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import com.google.cloud.bigtable.data.v2.internal.csm.tracers.DirectPathCompatibleTracer;
20-
import io.grpc.Channel;
21-
2220
import javax.annotation.Nullable;
2321

2422
@InternalApi
2523
/* Evaluates whether a given channel supports Direct Access. */
2624
public interface DirectAccessChecker {
27-
/**
28-
* Evaluates if Direct Access is available by creating a test channel.
29-
*
30-
* @param channelFactory A factory to create the test channel
31-
* @return true if the channel is eligible for Direct Access
32-
*/
33-
boolean check(BigtableChannelFactory channelFactory, @Nullable DirectPathCompatibleTracer tracer);
25+
/**
26+
* Evaluates if Direct Access is available by creating a test channel.
27+
*
28+
* @param channelFactory A factory to create the test channel
29+
* @return true if the channel is eligible for Direct Access
30+
*/
31+
boolean check(BigtableChannelFactory channelFactory, @Nullable DirectPathCompatibleTracer tracer);
3432
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,21 @@ public ClientOperationSettings getPerOpSettings() {
244244

245245
/** Applies common pool, message size, and keep-alive settings to the provided builder. */
246246
private static InstantiatingGrpcChannelProvider.Builder commonTraits(
247-
InstantiatingGrpcChannelProvider.Builder builder) {
247+
InstantiatingGrpcChannelProvider.Builder builder) {
248248
return builder
249-
.setChannelPoolSettings(
250-
ChannelPoolSettings.builder()
251-
.setInitialChannelCount(10)
252-
.setMinRpcsPerChannel(1)
253-
// Keep it conservative as we scale the channel size every 1min
254-
// and delta is 2 channels.
255-
.setMaxRpcsPerChannel(25)
256-
.setPreemptiveRefreshEnabled(true)
257-
.build())
258-
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
259-
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
260-
.setKeepAliveTimeout(
261-
Duration.ofSeconds(10)); // wait this long before considering the connection dead
249+
.setChannelPoolSettings(
250+
ChannelPoolSettings.builder()
251+
.setInitialChannelCount(10)
252+
.setMinRpcsPerChannel(1)
253+
// Keep it conservative as we scale the channel size every 1min
254+
// and delta is 2 channels.
255+
.setMaxRpcsPerChannel(25)
256+
.setPreemptiveRefreshEnabled(true)
257+
.build())
258+
.setMaxInboundMessageSize(MAX_MESSAGE_SIZE)
259+
.setKeepAliveTime(Duration.ofSeconds(30)) // sends ping in this interval
260+
.setKeepAliveTimeout(
261+
Duration.ofSeconds(10)); // wait this long before considering the connection dead
262262
}
263263

264264
/** Returns a builder for the default ChannelProvider for this service. */
@@ -285,22 +285,21 @@ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProvi
285285

286286
/** Applies Direct Access traits (DirectPath & ALTS) to an existing builder. */
287287
public static InstantiatingGrpcChannelProvider.Builder applyDirectAccessTraits(
288-
InstantiatingGrpcChannelProvider.Builder builder) {
288+
InstantiatingGrpcChannelProvider.Builder builder) {
289289

290290
builder
291-
.setAttemptDirectPathXds()
292-
.setAttemptDirectPath(true)
293-
.setAllowNonDefaultServiceAccount(true);
291+
.setAttemptDirectPathXds()
292+
.setAttemptDirectPath(true)
293+
.setAllowNonDefaultServiceAccount(true);
294294

295295
if (!DIRECT_PATH_BOUND_TOKEN_DISABLED) {
296296
builder.setAllowHardBoundTokenTypes(
297-
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
297+
Collections.singletonList(InstantiatingGrpcChannelProvider.HardBoundTokenTypes.ALTS));
298298
}
299299

300300
return builder;
301301
}
302302

303-
304303
@SuppressWarnings("WeakerAccess")
305304
public static TransportChannelProvider defaultTransportChannelProvider() {
306305
return defaultGrpcTransportProviderBuilder().build();

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import io.grpc.MethodDescriptor;
3535
import io.grpc.Status;
3636
import io.grpc.alts.AltsContextUtil;
37-
3837
import java.net.Inet4Address;
3938
import java.net.Inet6Address;
4039
import java.net.InetSocketAddress;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/UnaryDirectAccessChecker.java

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,63 +22,65 @@
2222
import io.grpc.Channel;
2323
import io.grpc.ClientInterceptors;
2424
import io.grpc.ManagedChannel;
25-
26-
import javax.annotation.Nullable;
2725
import java.util.Optional;
2826
import java.util.logging.Level;
2927
import java.util.logging.Logger;
28+
import javax.annotation.Nullable;
3029

3130
/**
32-
* Evaluates whether a given channel has Direct Access (DirectPath) routing
33-
* by executing a RPC and inspecting the response headers.
31+
* Evaluates whether a given channel has Direct Access (DirectPath) routing by executing a RPC and
32+
* inspecting the response headers.
3433
*/
3534
@InternalApi
3635
public class UnaryDirectAccessChecker implements DirectAccessChecker {
37-
private static final Logger LOG = Logger.getLogger(UnaryDirectAccessChecker.class.getName());
38-
private final ChannelPrimer channelPrimer;
36+
private static final Logger LOG = Logger.getLogger(UnaryDirectAccessChecker.class.getName());
37+
private final ChannelPrimer channelPrimer;
3938

40-
private UnaryDirectAccessChecker(ChannelPrimer channelPrimer) {
41-
this.channelPrimer = channelPrimer;
42-
}
39+
private UnaryDirectAccessChecker(ChannelPrimer channelPrimer) {
40+
this.channelPrimer = channelPrimer;
41+
}
4342

44-
public static UnaryDirectAccessChecker create(ChannelPrimer channelPrimer) {
45-
return new UnaryDirectAccessChecker(channelPrimer);
46-
}
43+
public static UnaryDirectAccessChecker create(ChannelPrimer channelPrimer) {
44+
return new UnaryDirectAccessChecker(channelPrimer);
45+
}
4746

48-
@Override
49-
public boolean check(BigtableChannelFactory channelFactory, @Nullable DirectPathCompatibleTracer tracer) {
50-
ManagedChannel channel = null;
51-
try {
52-
channel = channelFactory.createSingleChannel();
53-
MetadataExtractorInterceptor interceptor = new MetadataExtractorInterceptor();
54-
Channel interceptedChannel = ClientInterceptors.intercept(channel, interceptor);
55-
channelPrimer.primeChannel(interceptedChannel);
47+
@Override
48+
public boolean check(
49+
BigtableChannelFactory channelFactory, @Nullable DirectPathCompatibleTracer tracer) {
50+
ManagedChannel channel = null;
51+
try {
52+
channel = channelFactory.createSingleChannel();
53+
MetadataExtractorInterceptor interceptor = new MetadataExtractorInterceptor();
54+
Channel interceptedChannel = ClientInterceptors.intercept(channel, interceptor);
55+
channelPrimer.primeChannel(interceptedChannel);
5656

57-
// Extract the sideband data populated by the interceptor
58-
MetadataExtractorInterceptor.SidebandData sidebandData = interceptor.getSidebandData();
57+
// Extract the sideband data populated by the interceptor
58+
MetadataExtractorInterceptor.SidebandData sidebandData = interceptor.getSidebandData();
5959

60-
boolean isEligible = Optional.ofNullable(sidebandData)
61-
.map(MetadataExtractorInterceptor.SidebandData::getPeerInfo)
62-
.map(PeerInfo::getTransportType)
63-
.map(type -> type == PeerInfo.TransportType.TRANSPORT_TYPE_DIRECT_ACCESS)
64-
.orElse(false);
60+
boolean isEligible =
61+
Optional.ofNullable(sidebandData)
62+
.map(MetadataExtractorInterceptor.SidebandData::getPeerInfo)
63+
.map(PeerInfo::getTransportType)
64+
.map(type -> type == PeerInfo.TransportType.TRANSPORT_TYPE_DIRECT_ACCESS)
65+
.orElse(false);
6566

66-
if (isEligible && tracer != null) {
67-
String ipProtocolStr = Optional.ofNullable(sidebandData)
68-
.map(MetadataExtractorInterceptor.SidebandData::getIpProtocol)
69-
.map(String::valueOf)
70-
.map(String::toLowerCase)
71-
.orElse("unknown");
72-
tracer.recordSuccess(ipProtocolStr);
73-
}
74-
return isEligible;
75-
} catch (Exception e) {
76-
LOG.log(Level.FINE, "Failed to evaluate direct access eligibility.", e);
77-
return false;
78-
} finally {
79-
if (channel != null) {
80-
channel.shutdownNow();
81-
}
82-
}
67+
if (isEligible && tracer != null) {
68+
String ipProtocolStr =
69+
Optional.ofNullable(sidebandData)
70+
.map(MetadataExtractorInterceptor.SidebandData::getIpProtocol)
71+
.map(String::valueOf)
72+
.map(String::toLowerCase)
73+
.orElse("unknown");
74+
tracer.recordSuccess(ipProtocolStr);
75+
}
76+
return isEligible;
77+
} catch (Exception e) {
78+
LOG.log(Level.FINE, "Failed to evaluate direct access eligibility.", e);
79+
return false;
80+
} finally {
81+
if (channel != null) {
82+
channel.shutdownNow();
83+
}
8384
}
85+
}
8486
}

0 commit comments

Comments
 (0)