Skip to content

Commit 5781905

Browse files
authored
Merge pull request #3613 from isala404/disable-connection-pool
Add support for disabling in-cluster endpoint connection pooling
2 parents c49638e + 444d219 commit 5781905

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

adapter/internal/oasparser/envoyconf/routes_with_clusters.go

+27
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,14 @@ func processEndpoints(clusterName string, clusterDetails *model.EndpointCluster,
514514

515515
addresses := []*corev3.Address{}
516516

517+
withinClusterEndpoint := false
518+
517519
for i, ep := range clusterDetails.Endpoints {
520+
521+
if ep.URLType == "http" && strings.HasSuffix(ep.Host, "svc.cluster.local") {
522+
withinClusterEndpoint = true
523+
}
524+
518525
// validating the basepath to be same for all upstreams of an api
519526
if strings.TrimSuffix(ep.Basepath, "/") != basePath {
520527
return nil, nil, errors.New("endpoint basepath mismatched for " + ep.RawURL + ". expected : " + basePath + " but found : " + ep.Basepath)
@@ -612,6 +619,26 @@ func processEndpoints(clusterName string, clusterDetails *model.EndpointCluster,
612619
TypedDnsResolverConfig: dnsResolverConf,
613620
}
614621

622+
// If the endpoint is within the cluster, set the max requests per connection to 1
623+
// This ensure cilium proxy will not reuse the connection
624+
if withinClusterEndpoint && os.Getenv("ROUTER_DISABLE_IN_CLUSTER_CONNECTION_POOLING") == "true" {
625+
config := &upstreams.HttpProtocolOptions{
626+
CommonHttpProtocolOptions: &corev3.HttpProtocolOptions{
627+
MaxRequestsPerConnection: wrapperspb.UInt32(1),
628+
},
629+
}
630+
631+
marshalledConfig, err := anypb.New(config)
632+
if err != nil {
633+
return nil, nil, errors.New("internal Error while marshalling the HTTP Protocol Options")
634+
}
635+
636+
// Add to cluster's TypedExtensionProtocolOptions instead of deprecated fields
637+
cluster.TypedExtensionProtocolOptions = map[string]*any.Any{
638+
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": marshalledConfig,
639+
}
640+
}
641+
615642
if len(clusterDetails.Endpoints) > 1 {
616643
cluster.HealthChecks = createHealthCheck()
617644
}

0 commit comments

Comments
 (0)