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

fix(kuma-cp): deprecate 'timeout.grpc' section (backport #4365) #4449

Merged
merged 1 commit into from
Jun 9, 2022
Merged
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
98 changes: 66 additions & 32 deletions api/mesh/v1alpha1/timeout.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/mesh/v1alpha1/timeout.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,27 @@ message Timeout {
// IdleTimeout is the time at which a downstream or upstream connection
// will be terminated if there are no active streams
google.protobuf.Duration idle_timeout = 2;
// StreamIdleTimeout is the amount of time that the connection manager
// will allow a stream to exist with no upstream or downstream activity
google.protobuf.Duration stream_idle_timeout = 3;
// MaxStreamDuration is the maximum time that a stream’s lifetime will
// span
google.protobuf.Duration max_stream_duration = 4;
}
Http http = 3;

// Grpc defines timeouts that are applied when the protocol is GRPC
message Grpc {
// StreamIdleTimeout is the amount of time that the connection manager
// will allow a stream to exist with no upstream or downstream activity
// Deprecated: use Http.StreamIdleTimeout instead
google.protobuf.Duration stream_idle_timeout = 1;
// MaxStreamDuration is the maximum time that a stream’s lifetime will
// span
// Deprecated: use Http.MaxStreamDuration instead
google.protobuf.Duration max_stream_duration = 2;
}
// Deprecated: set parameters through Http section
Grpc grpc = 4;
}
Conf conf = 3 [ (doc.required) = true ];
Expand Down
16 changes: 15 additions & 1 deletion docs/generated/resources/policy_timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,32 @@

IdleTimeout is the time at which a downstream or upstream connection
will be terminated if there are no active streams

- `streamIdleTimeout` (optional)

StreamIdleTimeout is the amount of time that the connection manager
will allow a stream to exist with no upstream or downstream activity

- `maxStreamDuration` (optional)

MaxStreamDuration is the maximum time that a stream’s lifetime will
span

- `grpc` (optional)

Deprecated: set parameters through Http section

Child properties:

- `streamIdleTimeout` (optional)

StreamIdleTimeout is the amount of time that the connection manager
will allow a stream to exist with no upstream or downstream activity
will allow a stream to exist with no upstream or downstream activity
Deprecated: use Http.StreamIdleTimeout instead

- `maxStreamDuration` (optional)

MaxStreamDuration is the maximum time that a stream’s lifetime will
span
Deprecated: use Http.MaxStreamDuration instead

2 changes: 1 addition & 1 deletion pkg/defaults/mesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func EnsureDefaultMeshResources(ctx context.Context, resManager manager.Resource
defaultResourceBuilders := map[string]func() model.Resource{
"allow-all": defaultTrafficPermissionResource,
"route-all": defaultTrafficRouteResource,
"timeout-all": defaultTimeoutResource,
"timeout-all": DefaultTimeoutResource,
"circuit-breaker-all": defaultCircuitBreakerResource,
"retry-all": defaultRetryResource,
}
Expand Down
32 changes: 26 additions & 6 deletions pkg/defaults/mesh/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)

var defaultTimeoutResource = func() model.Resource {
var DefaultTimeoutResource = func() model.Resource {
return &core_mesh.TimeoutResource{
Spec: &mesh_proto.Timeout{
Sources: []*mesh_proto.Selector{{
Expand All @@ -24,13 +24,33 @@ var defaultTimeoutResource = func() model.Resource {
IdleTimeout: util_proto.Duration(1 * time.Hour),
},
Http: &mesh_proto.Timeout_Conf_Http{
IdleTimeout: util_proto.Duration(1 * time.Hour),
RequestTimeout: util_proto.Duration(15 * time.Second),
},
Grpc: &mesh_proto.Timeout_Conf_Grpc{
StreamIdleTimeout: util_proto.Duration(5 * time.Minute),
IdleTimeout: util_proto.Duration(1 * time.Hour),
RequestTimeout: util_proto.Duration(15 * time.Second),
StreamIdleTimeout: util_proto.Duration(30 * time.Minute),
},
},
},
}
}

// DefaultInboundTimeout returns timeouts for the inbound side. This resource is not created
// in the store. It's used directly in InboundProxyGenerator. In the future, it could be replaced
// with a new InboundTimeout policy. The main idea around these values is to have them either
// bigger than outbound side timeouts or disabled.
var DefaultInboundTimeout = func() *mesh_proto.Timeout_Conf {
const factor = 2
upstream := DefaultTimeoutResource().(*core_mesh.TimeoutResource).Spec.GetConf()

return &mesh_proto.Timeout_Conf{
ConnectTimeout: util_proto.Duration(factor * upstream.GetConnectTimeout().AsDuration()),
Tcp: &mesh_proto.Timeout_Conf_Tcp{
IdleTimeout: util_proto.Duration(factor * upstream.GetTcp().GetIdleTimeout().AsDuration()),
},
Http: &mesh_proto.Timeout_Conf_Http{
RequestTimeout: util_proto.Duration(0),
IdleTimeout: util_proto.Duration(factor * upstream.GetHttp().GetIdleTimeout().AsDuration()),
StreamIdleTimeout: util_proto.Duration(factor * upstream.GetHttp().GetStreamIdleTimeout().AsDuration()),
MaxStreamDuration: util_proto.Duration(0),
},
}
}
2 changes: 1 addition & 1 deletion pkg/plugins/runtime/gateway/cluster_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func newClusterBuilder(
dest *route.Destination,
) *clusters.ClusterBuilder {
builder := clusters.NewClusterBuilder(version).Configure(
clusters.Timeout(protocol, timeoutPolicyFor(dest)),
clusters.Timeout(timeoutPolicyFor(dest).Spec.GetConf(), protocol),
clusters.CircuitBreaker(circuitBreakerPolicyFor(dest)),
clusters.OutlierDetection(circuitBreakerPolicyFor(dest)),
clusters.HealthCheck(protocol, healthCheckPolicyFor(dest)),
Expand Down
4 changes: 2 additions & 2 deletions pkg/xds/envoy/clusters/configurers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func LB(lb *mesh_proto.TrafficRoute_LoadBalancer) ClusterBuilderOpt {
})
}

func Timeout(protocol core_mesh.Protocol, timeout *core_mesh.TimeoutResource) ClusterBuilderOpt {
func Timeout(timeout *mesh_proto.Timeout_Conf, protocol core_mesh.Protocol) ClusterBuilderOpt {
return ClusterBuilderOptFunc(func(config *ClusterBuilderConfig) {
config.AddV3(&v3.TimeoutConfigurer{
Protocol: protocol,
Timeout: timeout,
Conf: timeout,
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("CircuitBreakerConfigurer", func() {
cluster, err := clusters.NewClusterBuilder(envoy.APIV3).
Configure(clusters.EdsCluster(given.clusterName)).
Configure(clusters.CircuitBreaker(given.circuitBreaker)).
Configure(clusters.Timeout(core_mesh.ProtocolTCP, DefaultTimeout())).
Configure(clusters.Timeout(DefaultTimeout(), core_mesh.ProtocolTCP)).
Build()

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("EdsClusterConfigurer", func() {
cluster, err := clusters.NewClusterBuilder(envoy.APIV3).
Configure(clusters.EdsCluster(given.clusterName)).
Configure(clusters.ClientSideMTLS(tracker, given.mesh, given.clientService, true, given.tags)).
Configure(clusters.Timeout(core_mesh.ProtocolTCP, DefaultTimeout())).
Configure(clusters.Timeout(DefaultTimeout(), core_mesh.ProtocolTCP)).
Build()

// then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = Describe("ClientSideTLSConfigurer", func() {
cluster, err := clusters.NewClusterBuilder(envoy.APIV3).
Configure(clusters.EdsCluster(given.clusterName)).
Configure(clusters.ClientSideTLS(given.endpoints)).
Configure(clusters.Timeout(core_mesh.ProtocolTCP, DefaultTimeout())).
Configure(clusters.Timeout(DefaultTimeout(), core_mesh.ProtocolTCP)).
Build()

// then
Expand Down
11 changes: 4 additions & 7 deletions pkg/xds/envoy/clusters/v3/clusters_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import (
"time"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/test"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)

func DefaultTimeout() *core_mesh.TimeoutResource {
return &core_mesh.TimeoutResource{Spec: &mesh_proto.Timeout{
Conf: &mesh_proto.Timeout_Conf{
ConnectTimeout: util_proto.Duration(5 * time.Second),
},
}}
func DefaultTimeout() *mesh_proto.Timeout_Conf {
return &mesh_proto.Timeout_Conf{
ConnectTimeout: util_proto.Duration(5 * time.Second),
}
}

func TestClusters(t *testing.T) {
Expand Down
Loading