From 31d574c65816e8f7e1a144e24bf8015ba69cfbf5 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Thu, 20 Apr 2023 15:05:45 -0400 Subject: [PATCH 1/2] feat: print debug headers when channel priming fails --- .../data/v2/stub/BigtableChannelPrimer.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java index ecbef85be5..95bc688aca 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java @@ -15,18 +15,27 @@ */ package com.google.cloud.bigtable.data.v2.stub; +import static io.grpc.Metadata.Key; + import com.google.api.core.BetaApi; import com.google.api.gax.core.FixedCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.ChannelPrimer; +import com.google.api.gax.grpc.GrpcCallContext; +import com.google.api.gax.grpc.GrpcResponseMetadata; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.rpc.FixedTransportChannelProvider; import com.google.auth.Credentials; import com.google.bigtable.v2.PingAndWarmRequest; import com.google.cloud.bigtable.data.v2.internal.NameUtil; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import io.grpc.ManagedChannel; +import io.grpc.Metadata; import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; @@ -43,6 +52,15 @@ class BigtableChannelPrimer implements ChannelPrimer { private final EnhancedBigtableStubSettings settingsTemplate; + private static final String RETURN_ENCRYPTED_HEADERS_KEY = "x-return-encrypted-headers"; + + private static final String RETURN_ENCRYPTED_HEADERS_TYPE = "all_response"; + + private static final Key ENCRYPTED_HEADERS_KEY = + Key.of("x-encrypted-debug-headers", Metadata.ASCII_STRING_MARSHALLER); + + private final Map> returnEncryptedHeaders; + static BigtableChannelPrimer create( Credentials credentials, String projectId, String instanceId, String appProfileId) { EnhancedBigtableStubSettings.Builder builder = @@ -62,6 +80,8 @@ static BigtableChannelPrimer create( private BigtableChannelPrimer(EnhancedBigtableStubSettings settingsTemplate) { Preconditions.checkNotNull(settingsTemplate, "settingsTemplate can't be null"); this.settingsTemplate = settingsTemplate; + this.returnEncryptedHeaders = + ImmutableMap.of(RETURN_ENCRYPTED_HEADERS_KEY, Arrays.asList(RETURN_ENCRYPTED_HEADERS_TYPE)); } @Override @@ -96,8 +116,14 @@ private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException .setAppProfileId(primingSettings.getAppProfileId()) .build(); + GrpcResponseMetadata responseMetadata = new GrpcResponseMetadata(); + try { - stub.pingAndWarmCallable().call(request); + GrpcCallContext callContext = + GrpcCallContext.createDefault().withExtraHeaders(returnEncryptedHeaders); + stub.pingAndWarmCallable().call(request, responseMetadata.addHandlers(callContext)); + + responseMetadata.getMetadata(); } catch (Throwable e) { // TODO: Not sure if we should swallow the error here. We are pre-emptively swapping // channels if the new @@ -106,6 +132,11 @@ private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException e = e.getCause(); } LOG.warning(String.format("Failed to prime channel: %s", e)); + if (responseMetadata.getMetadata() != null) { + LOG.warning( + "Encrypted debug header is " + + responseMetadata.getMetadata().get(ENCRYPTED_HEADERS_KEY)); + } } } } From 1ef1082694ba543a36b6b61aeaeea929745d8a05 Mon Sep 17 00:00:00 2001 From: Mattie Fu Date: Wed, 24 Jan 2024 13:48:38 -0500 Subject: [PATCH 2/2] address comment --- .../cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java index 95bc688aca..77702c3d91 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableChannelPrimer.java @@ -134,7 +134,8 @@ private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException LOG.warning(String.format("Failed to prime channel: %s", e)); if (responseMetadata.getMetadata() != null) { LOG.warning( - "Encrypted debug header is " + "Channel priming failed, which implies a connection issue. When opening a support case, " + + "include this encrypted debug values in the support case: " + responseMetadata.getMetadata().get(ENCRYPTED_HEADERS_KEY)); } }