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 support for disabling in-cluster endpoint connection pooling #3613

Merged
merged 3 commits into from
Oct 30, 2024
Merged
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
27 changes: 27 additions & 0 deletions adapter/internal/oasparser/envoyconf/routes_with_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,14 @@ func processEndpoints(clusterName string, clusterDetails *model.EndpointCluster,

addresses := []*corev3.Address{}

withinClusterEndpoint := false

for i, ep := range clusterDetails.Endpoints {

if ep.URLType == "http" && strings.HasSuffix(ep.Host, "svc.cluster.local") {
withinClusterEndpoint = true
}

// validating the basepath to be same for all upstreams of an api
if strings.TrimSuffix(ep.Basepath, "/") != basePath {
return nil, nil, errors.New("endpoint basepath mismatched for " + ep.RawURL + ". expected : " + basePath + " but found : " + ep.Basepath)
Expand Down Expand Up @@ -612,6 +619,26 @@ func processEndpoints(clusterName string, clusterDetails *model.EndpointCluster,
TypedDnsResolverConfig: dnsResolverConf,
}

// If the endpoint is within the cluster, set the max requests per connection to 1
// This ensure cilium proxy will not reuse the connection
if withinClusterEndpoint && os.Getenv("ROUTER_DISABLE_IN_CLUSTER_CONNECTION_POOLING") == "true" {
config := &upstreams.HttpProtocolOptions{
CommonHttpProtocolOptions: &corev3.HttpProtocolOptions{
MaxRequestsPerConnection: wrapperspb.UInt32(1),
},
}

marshalledConfig, err := anypb.New(config)
if err != nil {
return nil, nil, errors.New("internal Error while marshalling the HTTP Protocol Options")
}

// Add to cluster's TypedExtensionProtocolOptions instead of deprecated fields
cluster.TypedExtensionProtocolOptions = map[string]*any.Any{
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": marshalledConfig,
}
}

if len(clusterDetails.Endpoints) > 1 {
cluster.HealthChecks = createHealthCheck()
}
Expand Down
Loading