diff --git a/api/envoy/config/cluster/v3/cluster.proto b/api/envoy/config/cluster/v3/cluster.proto index 7012f4ef5c435..957c2b3341e3a 100644 --- a/api/envoy/config/cluster/v3/cluster.proto +++ b/api/envoy/config/cluster/v3/cluster.proto @@ -709,6 +709,7 @@ message Cluster { EdsClusterConfig eds_cluster_config = 3; // The timeout for new network connections to hosts in the cluster. + // If not set, a default value of 5s will be used. google.protobuf.Duration connect_timeout = 4 [(validate.rules).duration = {gt {}}]; // Soft limit on size of the cluster’s connections read and write buffers. If diff --git a/api/envoy/config/cluster/v4alpha/cluster.proto b/api/envoy/config/cluster/v4alpha/cluster.proto index 807b70a0ce8be..8adf5ea460e4e 100644 --- a/api/envoy/config/cluster/v4alpha/cluster.proto +++ b/api/envoy/config/cluster/v4alpha/cluster.proto @@ -718,6 +718,7 @@ message Cluster { EdsClusterConfig eds_cluster_config = 3; // The timeout for new network connections to hosts in the cluster. + // If not set, a default value of 5s will be used. google.protobuf.Duration connect_timeout = 4 [(validate.rules).duration = {gt {}}]; // Soft limit on size of the cluster’s connections read and write buffers. If diff --git a/docs/root/faq/configuration/timeouts.rst b/docs/root/faq/configuration/timeouts.rst index fd530474ea344..43a228e0c27a5 100644 --- a/docs/root/faq/configuration/timeouts.rst +++ b/docs/root/faq/configuration/timeouts.rst @@ -104,8 +104,8 @@ TCP --- * The cluster :ref:`connect_timeout ` specifies the amount - of time Envoy will wait for an upstream TCP connection to be established. This timeout has no - default, but is required in the configuration. + of time Envoy will wait for an upstream TCP connection to be established. If this value is not set, + a default value of 5 seconds will be used. .. attention:: diff --git a/docs/root/version_history/current.rst b/docs/root/version_history/current.rst index bd265aaccff6b..332df94449503 100644 --- a/docs/root/version_history/current.rst +++ b/docs/root/version_history/current.rst @@ -20,6 +20,7 @@ Minor Behavior Changes requests to S3, ES or Glacier, which used the literal string ``UNSIGNED-PAYLOAD``. Buffering can be now be disabled in favor of using unsigned payloads with compatible services via the new `use_unsigned_payload` filter option (default false). +* cluster: added default value of 5 seconds for :ref:`connect_timeout `. * http: disable the integration between :ref:`ExtensionWithMatcher ` and HTTP filters by default to reflects its experimental status. This feature can be enabled by seting ``envoy.reloadable_features.experimental_matching_api`` to true. diff --git a/generated_api_shadow/envoy/config/cluster/v3/cluster.proto b/generated_api_shadow/envoy/config/cluster/v3/cluster.proto index 0e8a711900dd7..d9e64b44ce88a 100644 --- a/generated_api_shadow/envoy/config/cluster/v3/cluster.proto +++ b/generated_api_shadow/envoy/config/cluster/v3/cluster.proto @@ -710,6 +710,7 @@ message Cluster { EdsClusterConfig eds_cluster_config = 3; // The timeout for new network connections to hosts in the cluster. + // If not set, a default value of 5s will be used. google.protobuf.Duration connect_timeout = 4 [(validate.rules).duration = {gt {}}]; // Soft limit on size of the cluster’s connections read and write buffers. If diff --git a/generated_api_shadow/envoy/config/cluster/v4alpha/cluster.proto b/generated_api_shadow/envoy/config/cluster/v4alpha/cluster.proto index 6cbc477cee886..d637591a2251c 100644 --- a/generated_api_shadow/envoy/config/cluster/v4alpha/cluster.proto +++ b/generated_api_shadow/envoy/config/cluster/v4alpha/cluster.proto @@ -718,6 +718,7 @@ message Cluster { EdsClusterConfig eds_cluster_config = 3; // The timeout for new network connections to hosts in the cluster. + // If not set, a default value of 5s will be used. google.protobuf.Duration connect_timeout = 4 [(validate.rules).duration = {gt {}}]; // Soft limit on size of the cluster’s connections read and write buffers. If diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index 52affaa72b46c..a4dbd0eeb21a7 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -741,7 +741,7 @@ ClusterInfoImpl::ClusterInfoImpl( runtime_.snapshot().getInteger(Http::MaxResponseHeadersCountOverrideKey, Http::DEFAULT_MAX_HEADERS_COUNT))), connect_timeout_( - std::chrono::milliseconds(PROTOBUF_GET_MS_REQUIRED(config, connect_timeout))), + std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(config, connect_timeout, 5000))), per_upstream_preconnect_ratio_(PROTOBUF_GET_WRAPPED_OR_DEFAULT( config.preconnect_policy(), per_upstream_preconnect_ratio, 1.0)), peekahead_ratio_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config.preconnect_policy(), diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index a72407a7981b8..ef1e342c7a7d0 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -2612,6 +2612,20 @@ TEST_F(ClusterInfoImplTest, TestTrackRemainingResourcesGauges) { EXPECT_EQ(4U, high_remaining_retries.value()); } +TEST_F(ClusterInfoImplTest, DefaultConnectTimeout) { + const std::string yaml = R"EOF( + name: cluster1 + type: STRICT_DNS + lb_policy: ROUND_ROBIN +)EOF"; + + auto cluster = makeCluster(yaml); + envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV3Yaml(yaml); + + EXPECT_FALSE(cluster_config.has_connect_timeout()); + EXPECT_EQ(std::chrono::seconds(5), cluster->info()->connectTimeout()); +} + TEST_F(ClusterInfoImplTest, Timeouts) { const std::string yaml = R"EOF( name: name