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

feat: configure overload manager #3082

Merged
merged 2 commits into from
Apr 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ envoyProxy:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
logging: {}
status: {}
gatewayClass:
Expand Down Expand Up @@ -508,6 +515,13 @@ xds:
envoy.restart_features.use_eds_cache_for_ads: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
overloadManager:
refreshInterval: 0.250s
resourceMonitors:
- name: envoy.resource_monitors.global_downstream_max_connections
typedConfig:
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
maxActiveDownstreamConnections: "50000"
staticResources:
clusters:
- connectTimeout: 0.250s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
}
]
},
"overloadManager": {
"refreshInterval": "0.250s",
"resourceMonitors": [
{
"name": "envoy.resource_monitors.global_downstream_max_connections",
"typedConfig": {
"@type": "type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig",
"maxActiveDownstreamConnections": "50000"
}
}
]
},
"staticResources": {
"clusters": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ xds:
envoy.restart_features.use_eds_cache_for_ads: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
overloadManager:
refreshInterval: 0.250s
resourceMonitors:
- name: envoy.resource_monitors.global_downstream_max_connections
typedConfig:
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
maxActiveDownstreamConnections: "50000"
staticResources:
clusters:
- connectTimeout: 0.250s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ xds:
envoy.restart_features.use_eds_cache_for_ads: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
overloadManager:
refreshInterval: 0.250s
resourceMonitors:
- name: envoy.resource_monitors.global_downstream_max_connections
typedConfig:
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
maxActiveDownstreamConnections: "50000"
staticResources:
clusters:
- connectTimeout: 0.250s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
}
]
},
"overloadManager": {
"refreshInterval": "0.250s",
"resourceMonitors": [
{
"name": "envoy.resource_monitors.global_downstream_max_connections",
"typedConfig": {
"@type": "type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig",
"maxActiveDownstreamConnections": "50000"
}
}
]
},
"staticResources": {
"clusters": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ xds:
envoy.restart_features.use_eds_cache_for_ads: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
overloadManager:
refreshInterval: 0.250s
resourceMonitors:
- name: envoy.resource_monitors.global_downstream_max_connections
typedConfig:
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
maxActiveDownstreamConnections: "50000"
staticResources:
clusters:
- connectTimeout: 0.250s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ xds:
envoy.restart_features.use_eds_cache_for_ads: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
overloadManager:
refreshInterval: 0.250s
resourceMonitors:
- name: envoy.resource_monitors.global_downstream_max_connections
typedConfig:
'@type': type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
maxActiveDownstreamConnections: "50000"
staticResources:
clusters:
- connectTimeout: 0.250s
Expand Down
23 changes: 22 additions & 1 deletion internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
infra.Config.Spec.Telemetry != nil {
proxyMetrics = infra.Config.Spec.Telemetry.Metrics
}

maxHeapSizeBytes := caclulateMaxHeapSizeBytes(deploymentConfig.Container.Resources)

// Get the default Bootstrap
bootstrapConfigurations, err := bootstrap.GetRenderedBootstrapConfig(proxyMetrics)
bootstrapConfigurations, err := bootstrap.GetRenderedBootstrapConfig(&bootstrap.RenderBootsrapConfigOptions{
ProxyMetrics: proxyMetrics,
MaxHeapSizeBytes: maxHeapSizeBytes,
})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -389,3 +395,18 @@ func expectedContainerEnv(containerSpec *egv1a1.KubernetesContainerSpec) []corev
return env
}
}

// caclulateMaxHeapSizeBytes calculates the maximum heap size in bytes as 80% of Envoy container memory limits.
// In case no limits are defined '0' is returned, which means no heap size limit is set.
func caclulateMaxHeapSizeBytes(envoyResourceRequirements *corev1.ResourceRequirements) uint64 {
shahar-h marked this conversation as resolved.
Show resolved Hide resolved
if envoyResourceRequirements == nil || envoyResourceRequirements.Limits == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also lets make this method best effort
so it returns a *unit64, when we cannot compute the size lets return nil
and not add a max any FixedHeapConfig for that case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you already handle 0, suggest changing the API signature to return a ptr instead so the caller can use nil as a way to make a decision

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is an illegal value for max_heap_size_bytes, so it means it's disabled. It can be returned in 2 cases:

  1. No memory limits are defined
  2. Memory limits are 0, which has the same affect as 1

I don't see a value in changing the signature to ptr unless I missed something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I verified it by defining 0 and got validation error from Envoy at runtime.

return 0
}

if memLimit, ok := envoyResourceRequirements.Limits[corev1.ResourceMemory]; ok {
memLimitBytes := memLimit.Value()
return uint64(float64(memLimitBytes) * 0.8)
}

return 0
shahar-h marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ func TestDeployment(t *testing.T) {
infra: newTestInfra(),
extraArgs: []string{"--key1 val1", "--key2 val2"},
},
{
caseName: "with-empty-memory-limits",
infra: newTestInfra(),
deploy: &egv1a1.KubernetesDeploymentSpec{
Container: &egv1a1.KubernetesContainerSpec{
Resources: &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("400m"),
},
},
},
},
},
}
for _, tc := range cases {
t.Run(tc.caseName, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 1717986918
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 1717986918
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 1717986918
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 1717986918
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- --log-level warn
- --cpuset-threads
- --drain-time-s 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ spec:
path_config_source:
path: "/sds/xds-trusted-ca.json"
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
- name: "envoy.resource_monitors.fixed_heap"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.fixed_heap.v3.FixedHeapConfig
max_heap_size_bytes: 1717986918
actions:
- name: "envoy.overload_actions.shrink_heap"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.fixed_heap"
threshold:
value: 0.98
- --log-level warn
- --cpuset-threads
command:
Expand Down
Loading