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

Add --grpc_keepalive_time/grpc_keepalive_timeout #11957

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
package com.google.devtools.build.lib.authandtls;

import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter;
import com.google.devtools.common.options.Converters.DurationConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionMetadataTag;
import com.google.devtools.common.options.OptionsBase;

import java.time.Duration;
import java.util.List;

/**
Expand Down Expand Up @@ -100,4 +103,35 @@ public class AuthAndTLSOptions extends OptionsBase {
+ "value a valid TLS authority."
)
public String tlsAuthorityOverride;

@Option(
name = "grpc_keepalive_time",
defaultValue = "null",
converter = DurationConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"Configures keep-alive pings for outgoing gRPC connections. If this is set, then "
+ "Bazel sends pings after this much time of no read operations on the connection, "
+ "but only if there is at least one pending gRPC call. Times are treated as second "
+ "granularity; it is an error to set a value less than one second. By default, "
+ "keep-alive pings are disabled. You should coordinate with the service owner "
+ "before enabling this setting."
)
public Duration grpcKeepaliveTime;

@Option(
name = "grpc_keepalive_timeout",
defaultValue = "20s",
converter = DurationConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"Configures a keep-alive timeout for outgoing gRPC connections. If keep-alive pings are "
+ "enabled with --grpc_keepalive_time, then Bazel times out a connection if it does "
+ "not receive a ping reply after this much time. Times are treated as second "
+ "granularity; it is an error to set a value less than one second. If keep-alive "
+ "pings are disabled, then this setting is ignored."
)
public Duration grpcKeepaliveTimeout;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/** Utility methods for using {@link AuthAndTLSOptions} with Google Cloud. */
Expand Down Expand Up @@ -72,6 +73,10 @@ public static ManagedChannel newChannel(
newNettyChannelBuilder(targetUrl, proxy)
.negotiationType(
isTlsEnabled(target) ? NegotiationType.TLS : NegotiationType.PLAINTEXT);
if (options.grpcKeepaliveTime != null) {
builder.keepAliveTime(options.grpcKeepaliveTime.getSeconds(), TimeUnit.SECONDS);
builder.keepAliveTimeout(options.grpcKeepaliveTimeout.getSeconds(), TimeUnit.SECONDS);
}
if (interceptors != null) {
builder.intercept(interceptors);
}
Expand Down