Skip to content
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

feat: print debug headers when channel priming fails #1719

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;

Expand All @@ -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<String> ENCRYPTED_HEADERS_KEY =
Key.of("x-encrypted-debug-headers", Metadata.ASCII_STRING_MARSHALLER);

private final Map<String, List<String>> returnEncryptedHeaders;

static BigtableChannelPrimer create(
Credentials credentials, String projectId, String instanceId, String appProfileId) {
EnhancedBigtableStubSettings.Builder builder =
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -106,6 +132,12 @@ 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(
"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));
}
}
}
}
Expand Down