Skip to content

Commit

Permalink
feat(gateway): set cluster HTTP2 stream and connection window size (#…
Browse files Browse the repository at this point in the history
…4779)

* feat(gateway): set cluster HTTP2 stream and connection window size
* test(gateway): update golden files

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored Aug 9, 2022
1 parent 4c18e48 commit 12bf586
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 8 deletions.
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 @@ -190,7 +190,7 @@ func newClusterBuilder(
// the same, but it doesn't work.
switch protocol {
case core_mesh.ProtocolHTTP2, core_mesh.ProtocolGRPC:
builder.Configure(clusters.Http2())
builder.Configure(clusters.Http2FromEdge())
case core_mesh.ProtocolHTTP:
builder.Configure(clusters.Http())
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Clusters:
commonHttpProtocolOptions:
idleTimeout: 3600s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources: {}
Listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ Clusters:
commonHttpProtocolOptions:
idleTimeout: 3600s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources:
echo-service-bfae5b64a0fe8b74:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Clusters:
idleTimeout: 115s
maxStreamDuration: 117s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources: {}
Listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Clusters:
commonHttpProtocolOptions:
idleTimeout: 3600s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources: {}
Listeners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ Clusters:
commonHttpProtocolOptions:
idleTimeout: 3600s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources:
echo-service-bfae5b64a0fe8b74:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Clusters:
idleTimeout: 115s
maxStreamDuration: 117s
explicitHttpConfig:
http2ProtocolOptions: {}
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
Endpoints:
Resources: {}
Listeners:
Expand Down
6 changes: 6 additions & 0 deletions pkg/xds/envoy/clusters/configurers.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ func Http2() ClusterBuilderOpt {
})
}

func Http2FromEdge() ClusterBuilderOpt {
return ClusterBuilderOptFunc(func(config *ClusterBuilderConfig) {
config.AddV3(&v3.Http2Configurer{EdgeProxyWindowSizes: true})
})
}

func Http() ClusterBuilderOpt {
return ClusterBuilderOptFunc(func(config *ClusterBuilderConfig) {
config.AddV3(&v3.HttpConfigurer{})
Expand Down
18 changes: 17 additions & 1 deletion pkg/xds/envoy/clusters/v3/http2_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@ import (
envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"

util_proto "github.com/kumahq/kuma/pkg/util/proto"
)

// Window size defaults.
const DefaultInitialStreamWindowSize = 64 * 1024
const DefaultInitialConnectionWindowSize = 1024 * 1024

type Http2Configurer struct {
EdgeProxyWindowSizes bool
}

var _ ClusterConfigurer = &Http2Configurer{}

func (p *Http2Configurer) Configure(c *envoy_cluster.Cluster) error {
return UpdateCommonHttpProtocolOptions(c, func(options *envoy_upstream_http.HttpProtocolOptions) {
opts := &envoy_core.Http2ProtocolOptions{}

// These are from Envoy's best practices for edge proxy configuration:
// https://www.envoyproxy.io/docs/envoy/latest/configuration/best_practices/edge
if p.EdgeProxyWindowSizes {
opts.InitialStreamWindowSize = util_proto.UInt32(DefaultInitialStreamWindowSize)
opts.InitialConnectionWindowSize = util_proto.UInt32(DefaultInitialConnectionWindowSize)
}

if options.UpstreamProtocolOptions == nil {
options.UpstreamProtocolOptions = &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &envoy_core.Http2ProtocolOptions{},
Http2ProtocolOptions: opts,
},
},
}
Expand Down

0 comments on commit 12bf586

Please sign in to comment.