Skip to content

Commit 4523a75

Browse files
committed
fix: add filter chain name and host rewrite support
Enable Envoy go-control-plane integration by adding missing filter chain name field and host_rewrite_specifier support. Signed-off-by: Eeshu-Yadav <eeshuyadav123@gmail.com>
1 parent 11dc375 commit 4523a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+556
-468
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ jobs:
4343
- name: Check formatting
4444
run: cargo fmt --all -- --check
4545

46-
- name: Run clippy (fail on warnings)
47-
run: cargo clippy --all-targets --all-features -- -D warnings
46+
- name: Run clippy (default features, recommended)
47+
run: cargo clippy --all-targets -- -D warnings
48+
49+
# Optionally, test allocators individually (never together):
50+
- name: Run clippy (jemalloc)
51+
run: cargo clippy --all-targets --no-default-features --features jemalloc -- -D warnings
52+
53+
- name: Run clippy (dhat-heap)
54+
run: cargo clippy --all-targets --no-default-features --features dhat-heap -- -D warnings
55+
56+
# Do NOT use --all-features: jemalloc and dhat-heap are mutually exclusive and will cause a build failure.
4857

4958
# Build and test that share artifacts
5059
build-and-test:

CI_LINTING_GUIDE.md

Whitespace-only changes.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ git submodule update --force
3737
cargo build
3838
```
3939

40+
> **Note:**
41+
> Do **not** use `--all-features` with `cargo build` or `cargo clippy`.
42+
> The `jemalloc` and `dhat-heap` features are mutually exclusive and will cause a build failure if both are enabled.
43+
> For CI/CD and development, use the default features. See the note in `.github/workflows/ci.yml` for more details.
44+
4045
### Running
4146
```console
4247
cargo run --bin orion -- --config orion/conf/orion-runtime.yaml

clippy.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# for `disallowed_method`:
22
# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
33
disallowed-methods = [
4-
{ path = "orion_data_plane_api::decode::SourceFmt::Protobuf", reason = "Should not be used anymore. Use TryFrom instead." },
5-
{ path = "orion_data_plane_api::decode::SourceFmt::Yaml", reason = "Should not be used anymore. Use TryFrom instead." },
4+
{ path = "orion_data_plane_api::decode::SourceFmt::Protobuf", reason = "Should not be used anymore. Use TryFrom instead.", allow-invalid = true },
5+
{ path = "orion_data_plane_api::decode::SourceFmt::Yaml", reason = "Should not be used anymore. Use TryFrom instead.", allow-invalid = true },
66
{ path = "tokio::time::timeout", reason = "Use pingora_timeout::fast_timeout::fast_timeout instead" },
77
]
88

orion-configuration/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod envoy_conversions {
122122
serde_yaml::Deserializer::from_reader(&envoy_file),
123123
&mut track,
124124
))
125-
.with_context(|| format!("failed to deserialize {}", track.path().to_string()))?;
125+
.with_context(|| format!("failed to deserialize {}", track.path()))?;
126126
Bootstrap::try_from(envoy).context("failed to convert into orion bootstrap")
127127
})()
128128
.with_context(|| format!("failed to read config from \"{}\"", envoy_path.as_ref().display()))
@@ -137,7 +137,7 @@ mod envoy_conversions {
137137
Self { runtime: Runtime::default(), logging: Log::default(), bootstrap }
138138
},
139139
(Some(config), maybe_override) => {
140-
let ShimConfig { runtime, logging, bootstrap, envoy_bootstrap } = deserialize_yaml(&config)
140+
let ShimConfig { runtime, logging, bootstrap, envoy_bootstrap } = deserialize_yaml(config)
141141
.with_context(|| format!("failed to deserialize \"{}\"", config.display()))?;
142142
let mut bootstrap = match (bootstrap, envoy_bootstrap) {
143143
(None, None) => Bootstrap::default(),
@@ -149,7 +149,7 @@ mod envoy_conversions {
149149
},
150150
};
151151
if let Some(bootstrap_override) = maybe_override {
152-
bootstrap = bootstrap_from_path_to_envoy_bootstrap(&bootstrap_override)?;
152+
bootstrap = bootstrap_from_path_to_envoy_bootstrap(bootstrap_override)?;
153153
}
154154
Self { runtime, logging, bootstrap }
155155
},
@@ -201,7 +201,7 @@ mod envoy_conversions {
201201
let deserialized: Config = serde_yaml::from_str(&serialized)?;
202202
if new_conf != deserialized {
203203
tracing::info!("\n{}\n", serde_yaml::to_string(&deserialized)?);
204-
panic!("failed to roundtrip config transcoding")
204+
return Err("failed to roundtrip config transcoding".into());
205205
}
206206
} else {
207207
tracing::info!("skipping {}", path.display())

orion-configuration/src/config/bootstrap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ mod envoy_conversions {
127127
grpc_async_client_manager_config,
128128
stats_flush,
129129
memory_allocator_manager: _,
130+
..
130131
} = envoy;
131132
unsupported_field!(
132133
// node,

orion-configuration/src/config/cluster.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ mod envoy_conversions {
251251
};
252252
use std::{collections::BTreeSet, net::SocketAddr, num::NonZeroU32};
253253

254+
#[allow(clippy::too_many_lines)]
254255
impl TryFrom<EnvoyCluster> for Cluster {
255256
type Error = GenericError;
256257
fn try_from(envoy: EnvoyCluster) -> Result<Self, Self::Error> {
@@ -496,10 +497,10 @@ mod envoy_conversions {
496497
}
497498
Ok(Self { endpoints })
498499
})();
499-
if !cluster_name.is_empty() {
500-
ret.with_name(cluster_name)
501-
} else {
500+
if cluster_name.is_empty() {
502501
ret
502+
} else {
503+
ret.with_name(cluster_name)
503504
}
504505
}
505506
}
@@ -677,7 +678,7 @@ mod envoy_conversions {
677678
SupportedEnvoyTransportSocket::DownstreamTlsContext(_) => {
678679
Err(GenericError::unsupported_variant("DownstreamTlsContext"))
679680
},
680-
SupportedEnvoyTransportSocket::UpstreamTlsContext(x) => x.try_into(),
681+
SupportedEnvoyTransportSocket::UpstreamTlsContext(x) => (*x).try_into(),
681682
}
682683
}
683684
}

orion-configuration/src/config/cluster/health_check.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct ClusterHealthCheck {
5555
/// An optional jitter amount from 0.0 to 1.0.
5656
/// If specified, during every interval we will add `interval` * `interval_jitter_percent` to the wait time.
5757
/// If `interval_jitter` and `interval_jitter_percent` are both set, both of them will be used to increase the wait time.
58-
#[serde(skip_serializing_if = "f32_is_zero", default = "Default::default")]
58+
#[serde(skip_serializing_if = "crate::config::cluster::health_check::f32_is_zero", default = "Default::default")]
5959
pub interval_jitter_percent: f32,
6060
/// The “unhealthy interval” is a health check interval that is used for hosts that are marked as unhealthy.
6161
/// As soon as the host is marked as healthy, Envoy will shift back to using the standard health check
@@ -79,7 +79,8 @@ pub struct ClusterHealthCheck {
7979
pub healthy_edge_interval: Option<Duration>,
8080
}
8181

82-
fn f32_is_zero(x: &f32) -> bool {
82+
#[allow(clippy::trivially_copy_pass_by_ref)]
83+
pub fn f32_is_zero(x: &f32) -> bool {
8384
*x == 0.0
8485
}
8586

@@ -197,8 +198,9 @@ pub struct HttpHealthCheck {
197198
pub path: Option<PathAndQuery>,
198199
}
199200

201+
#[allow(clippy::range_plus_one)]
200202
fn default_expected_statuses() -> Vec<Range<u16>> {
201-
vec![200..201]
203+
(200..201).map(|n| n..n + 1).collect()
202204
}
203205

204206
fn is_default_expected_statuses(value: &Vec<Range<u16>>) -> bool {
@@ -282,6 +284,7 @@ mod envoy_conversions {
282284
};
283285
use std::{ops::Range, str::FromStr};
284286

287+
#[allow(clippy::too_many_lines)]
285288
impl TryFrom<EnvoyHealthCheck> for HealthCheck {
286289
type Error = GenericError;
287290
fn try_from(value: EnvoyHealthCheck) -> Result<Self, Self::Error> {
@@ -348,7 +351,9 @@ mod envoy_conversions {
348351
GenericError::from_msg_with_cause("failed to convert {interval_jitter} to std::time::Duration", e)
349352
.with_node("interval_jitter")
350353
})?;
354+
#[allow(clippy::cast_precision_loss)]
351355
let interval_jitter_percent = {
356+
#[allow(clippy::cast_precision_loss)]
352357
let as_float = interval_jitter_percent as f32;
353358
if !as_float.is_finite() || as_float > 1.0 || as_float.is_sign_negative() {
354359
Err(GenericError::from_msg(format!(
@@ -357,8 +362,7 @@ mod envoy_conversions {
357362
} else {
358363
Ok(as_float)
359364
}
360-
}
361-
.with_node("interval_jitter_percent")?;
365+
}?;
362366
let unhealthy_threshold = required!(unhealthy_threshold)?.value;
363367
let unhealthy_threshold = unhealthy_threshold
364368
.try_into()
@@ -431,6 +435,7 @@ mod envoy_conversions {
431435
} else if start < 100 || end >= 600 {
432436
Err(GenericError::from_msg("invalid range [{start},{end}). Range has to be within [100,600)."))
433437
} else {
438+
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
434439
Ok((start as u16)..(end as u16))
435440
}
436441
})

orion-configuration/src/config/cluster/http_protocol_options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ enum ExplicitProtocolOptions {
7878

7979
impl Default for ExplicitProtocolOptions {
8080
fn default() -> Self {
81-
Self::Http1(Http1ProtocolOptions::default())
81+
Self::Http1(Http1ProtocolOptions)
8282
}
8383
}
8484

@@ -101,7 +101,7 @@ pub struct Http2ProtocolOptions {
101101

102102
impl Http2ProtocolOptions {
103103
pub fn max_concurrent_streams(&self) -> Option<usize> {
104-
self.max_concurrent_streams.map(usize::from)
104+
self.max_concurrent_streams
105105
}
106106
pub fn initial_stream_window_size(&self) -> Option<u32> {
107107
self.initial_stream_window_size.map(u32::from)
@@ -239,10 +239,10 @@ mod envoy_conversions {
239239
let common = common_http_protocol_options.map(CommonHttpOptions::try_from).transpose()?.unwrap_or_default();
240240
let (codec, http1_options, http2_options) = match upstream_protocol_options {
241241
UpstreamHttpProtocolOptions::Explicit(ExplicitProtocolOptions::Http1(http1)) => {
242-
(Codec::Http1, http1, Default::default())
242+
(Codec::Http1, http1, Http2ProtocolOptions::default())
243243
},
244244
UpstreamHttpProtocolOptions::Explicit(ExplicitProtocolOptions::Http2(http2)) => {
245-
(Codec::Http2, Default::default(), http2)
245+
(Codec::Http2, Http1ProtocolOptions, http2)
246246
},
247247
};
248248

orion-configuration/src/config/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a> DataSourceReader<'a> {
8888
}
8989
}
9090

91-
impl<'a> Read for DataSourceReader<'a> {
91+
impl Read for DataSourceReader<'_> {
9292
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
9393
match self {
9494
Self::OwnedBytes { bytes, read } => {
@@ -105,7 +105,7 @@ impl<'a> Read for DataSourceReader<'a> {
105105
}
106106
}
107107

108-
impl<'a> BufRead for DataSourceReader<'a> {
108+
impl BufRead for DataSourceReader<'_> {
109109
fn fill_buf(&mut self) -> std::io::Result<&[u8]> {
110110
match self {
111111
Self::OwnedBytes { bytes, read } => Ok(&bytes[*read..]),
@@ -134,7 +134,7 @@ pub struct StringMatcher {
134134
}
135135

136136
pub(crate) struct CaseSensitive<'a>(pub bool, pub &'a str);
137-
impl<'a> CaseSensitive<'a> {
137+
impl CaseSensitive<'_> {
138138
#[inline]
139139
pub fn equals(&self, b: &str) -> bool {
140140
if self.0 {

0 commit comments

Comments
 (0)