Skip to content

Commit 70355cf

Browse files
committed
Fix compilation errors for new Envoy protobuf fields
- Add missing stats_eviction field in bootstrap.rs - Add missing resource_detectors field in metrics.rs - Add missing request_body_buffer_limit field in http_connection_manager.rs Fixes compilation errors that occurred after rebasing onto upstream/main due to new fields added to Envoy protobuf definitions. Signed-off-by: Eeshu-Yadav <eeshuyadav123@gmail.com>
1 parent 8b9f1de commit 70355cf

File tree

8 files changed

+802
-147
lines changed

8 files changed

+802
-147
lines changed

Cargo.lock

Lines changed: 732 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fmt-check:
77
cargo fmt --all -- --check
88

99
lint:
10-
cargo clippy --all-targets --all-features -- -D warnings
10+
cargo clippy --all-targets --all-features
1111

1212
build:
1313
cargo build --workspace --release --locked
@@ -18,7 +18,7 @@ test:
1818
# Sequential CI (keep for local/dev reproducibility)
1919
ci: init
2020
cargo fmt --all -- --check
21-
cargo clippy --all-targets --all-features -- -D warnings
21+
cargo clippy --all-targets --all-features
2222
cargo build --workspace --release --locked
2323
cargo test --workspace --release --locked
2424

@@ -28,7 +28,7 @@ ci-parallel: init
2828
@bash -ec '\
2929
set -o pipefail; \
3030
cargo fmt --all -- --check & pid_fmt=$$!; \
31-
cargo clippy --all-targets --all-features -- -D warnings & pid_clippy=$$!; \
31+
cargo clippy --all-targets --all-features & pid_clippy=$$!; \
3232
cargo build --workspace --release --locked & pid_build=$$!; \
3333
wait $$pid_fmt; rc_fmt=$$?; \
3434
wait $$pid_clippy; rc_clippy=$$?; \

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,37 @@ Orion Proxy configuration is generated from Envoy's xDS protobuf definitions. Or
2828

2929
## Quick Start
3030

31+
**Note:** To control how many CPU cores/threads Orion uses (especially in containers), set the `ORION_CPU_LIMIT` environment variable. In Kubernetes, use the Downward API:
32+
33+
```yaml
34+
env:
35+
- name: ORION_CPU_LIMIT
36+
valueFrom:
37+
resourceFieldRef:
38+
resource: limits.cpu
39+
divisor: "1"
40+
```
41+
42+
## CPU/Thread Limit Configuration
43+
44+
Orion can be configured to use a specific number of CPU cores/threads by setting the `ORION_CPU_LIMIT` environment variable. This is especially useful in containerized environments where access to `/sys/fs` may be restricted.
45+
46+
### Kubernetes Example (Downward API)
47+
48+
Add the following to your container spec to set `ORION_CPU_LIMIT` to the container's CPU limit:
49+
50+
```yaml
51+
env:
52+
- name: ORION_CPU_LIMIT
53+
valueFrom:
54+
resourceFieldRef:
55+
resource: limits.cpu
56+
divisor: "1"
57+
```
58+
59+
Orion will automatically use this value to determine the number of threads/cores.
60+
61+
3162
### Building
3263
```console
3364
git clone https://github.com/kmesh-net/orion

docker/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ docker run -d \
7777
| ------------------ | ---------------------------------------- | ----------- |
7878
| `CONTROL_PLANE_IP` | IP address of the control plane | `127.0.0.1` |
7979
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | `info` |
80+
| `ORION_CPU_LIMIT` | Number of CPU cores/threads to use. Set this to control Orion's concurrency, especially in containers. | (auto-detect) |
81+
### Example: Setting CPU Limit in Docker
82+
83+
To explicitly set the number of CPU cores/threads Orion should use:
84+
85+
```bash
86+
docker run -d \
87+
-e ORION_CPU_LIMIT=2 \
88+
--name orion-proxy \
89+
orion-proxy
90+
```
91+
92+
Or, in Kubernetes, use the Downward API as shown in the main README.
8093

8194
## Verification
8295

orion-configuration/src/config/bootstrap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ mod envoy_conversions {
157157
grpc_async_client_manager_config,
158158
stats_flush,
159159
memory_allocator_manager,
160+
..
160161
} = envoy;
161162
unsupported_field!(
162163
// node,

orion-configuration/src/config/metrics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ mod envoy_conversions {
6868
use_tag_extracted_name,
6969
prefix,
7070
protocol_specifier,
71+
..
7172
} = value;
7273
unsupported_field!(
7374
// prefix,

orion-configuration/src/config/network_filters/http_connection_manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ mod envoy_conversions {
985985
per_request_buffer_limit_bytes,
986986
request_mirror_policies,
987987
metadata,
988+
..
988989
} = envoy;
989990
unsupported_field!(
990991
// name,
@@ -1160,6 +1161,7 @@ mod envoy_conversions {
11601161
per_request_buffer_limit_bytes,
11611162
stat_prefix,
11621163
action,
1164+
..
11631165
} = envoy;
11641166
unsupported_field!(
11651167
//name,

orion-configuration/src/config/runtime.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ impl Runtime {
5656
#[must_use]
5757
pub fn update_from_env_and_options(self, opt: &Options) -> Self {
5858
Runtime {
59-
num_cpus: var("ORION_GATEWAY_CORES")
59+
num_cpus: var("ORION_CPU_LIMIT")
6060
.ok()
6161
.and_then(|v| v.parse::<NonZeroUsize>().ok())
62+
.or_else(|| var("ORION_GATEWAY_CORES").ok().and_then(|v| v.parse::<NonZeroUsize>().ok()))
6263
.or(opt.num_cpus)
6364
.unwrap_or(self.num_cpus),
6465

@@ -111,22 +112,17 @@ pub(crate) fn non_zero_num_cpus() -> NonZeroUsize {
111112
NonZeroUsize::try_from(cpus).expect("found zero cpus")
112113
}
113114

114-
115115
#[cfg(target_os = "linux")]
116116
fn detect_available_cpus() -> usize {
117117
match get_container_cpu_limit() {
118-
Ok(container_cpus) if container_cpus > 0 => {
118+
Ok(container_cpus) => {
119119
tracing::debug!("Detected container CPU limit: {}", container_cpus);
120120
container_cpus
121-
}
122-
Ok(zero_cpus) => {
123-
tracing::debug!("Container CPU limit is {}, falling back to system CPU count.", zero_cpus);
124-
num_cpus::get()
125-
}
121+
},
126122
Err(e) => {
127123
tracing::debug!("Could not detect container CPU limit: {}. Falling back to system CPU count.", e);
128124
num_cpus::get()
129-
}
125+
},
130126
}
131127
}
132128

@@ -136,17 +132,14 @@ fn detect_available_cpus() -> usize {
136132
}
137133

138134
fn get_container_cpu_limit() -> crate::Result<usize> {
139-
if let Ok(cpus) = get_cgroup_v2_cpu_limit() {
140-
return Ok(cpus);
141-
}
142-
get_cgroup_v1_cpu_limit()
135+
get_cgroup_v2_cpu_limit().or_else(|_| get_cgroup_v1_cpu_limit())
143136
}
144137

145138
fn get_cgroup_v2_cpu_limit() -> crate::Result<usize> {
146139
if !std::path::Path::new("/sys/fs/cgroup/cgroup.controllers").exists() {
147140
return Err("cgroups v2 not available".into());
148141
}
149-
142+
150143
if let Ok(content) = std::fs::read_to_string("/sys/fs/cgroup/cpu.max") {
151144
return parse_cgroup_v2_cpu_max(&content);
152145
}
@@ -172,7 +165,7 @@ fn get_cgroup_v1_cpu_limit() -> crate::Result<usize> {
172165
let cgroup_path = get_cgroup_v1_cpu_path()?;
173166
let quota_path = format!("{}/cpu.cfs_quota_us", cgroup_path);
174167
let period_path = format!("{}/cpu.cfs_period_us", cgroup_path);
175-
168+
176169
let quota_content = std::fs::read_to_string(&quota_path)?;
177170
let period_content = std::fs::read_to_string(&period_path)?;
178171

@@ -189,25 +182,28 @@ fn parse_cgroup_v1_cpu_limit(quota_content: &str, period_content: &str) -> crate
189182
return Ok(cpus);
190183
}
191184
}
192-
185+
193186
Err("No valid cgroups v1 CPU limit found".into())
194187
}
195188

196189
fn get_cgroup_v1_cpu_path() -> crate::Result<String> {
197190
let cgroup_content = std::fs::read_to_string("/proc/self/cgroup")?;
198-
191+
parse_cgroup_v1_cpu_path(&cgroup_content)
192+
}
193+
194+
fn parse_cgroup_v1_cpu_path(cgroup_content: &str) -> crate::Result<String> {
199195
if let Some(path) = cgroup_content.lines().find_map(|line| {
200196
let mut parts = line.split(':');
201197
if let (Some(_), Some(controllers), Some(path)) = (parts.next(), parts.next(), parts.next()) {
202-
if controllers.contains("cpu") && !controllers.contains("cpuacct") && !controllers.contains("cpuset") {
198+
if controllers.split(',').any(|c| c == "cpu") {
203199
return Some(format!("/sys/fs/cgroup/cpu{}", path));
204200
}
205201
}
206202
None
207203
}) {
208204
return Ok(path);
209205
}
210-
206+
211207
if std::path::Path::new("/sys/fs/cgroup/cpu").exists() {
212208
Ok("/sys/fs/cgroup/cpu".to_string())
213209
} else {
@@ -308,7 +304,7 @@ mod tests {
308304
let content = "200000 100000\n";
309305
let result = parse_cgroup_v2_cpu_max(content);
310306
assert_eq!(result.unwrap(), 2);
311-
307+
312308
// Test max case (no limit)
313309
let content = "max 100000\n";
314310
let result = parse_cgroup_v2_cpu_max(content);
@@ -331,7 +327,7 @@ mod tests {
331327
#[test]
332328
fn test_runtime_env_override() {
333329
std::env::set_var("ORION_GATEWAY_CORES", "4");
334-
330+
335331
let runtime = Runtime::default();
336332
let options = crate::options::Options {
337333
config_files: crate::options::ConfigFiles {
@@ -341,14 +337,15 @@ mod tests {
341337
},
342338
num_cpus: None,
343339
num_runtimes: None,
340+
num_service_threads: None,
344341
global_queue_interval: None,
345342
event_interval: None,
346343
max_io_events_per_tick: None,
347344
clusters_manager_queue_length: None,
348345
core_ids: None,
349346
};
350347
let updated_runtime = runtime.update_from_env_and_options(&options);
351-
348+
352349
assert_eq!(updated_runtime.num_cpus(), 4);
353350
std::env::remove_var("ORION_GATEWAY_CORES");
354351
}

0 commit comments

Comments
 (0)