diff --git a/Cargo.lock b/Cargo.lock index 8a467cd9..ffb872f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -487,9 +487,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "2.9.3" +version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" dependencies = [ "serde", ] @@ -546,21 +546,13 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "castaway" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" -dependencies = [ - "rustversion", -] - [[package]] name = "cc" -version = "1.2.34" +version = "1.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" +checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3" dependencies = [ + "find-msvc-tools", "jobserver", "libc", "shlex", @@ -647,9 +639,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" +checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931" dependencies = [ "clap_builder", "clap_derive", @@ -657,9 +649,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" +checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6" dependencies = [ "anstream", "anstyle", @@ -669,9 +661,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.45" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ "heck", "proc-macro2", @@ -710,21 +702,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "compact_str" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" -dependencies = [ - "castaway", - "cfg-if", - "itoa", - "rustversion", - "ryu", - "serde", - "static_assertions", -] - [[package]] name = "cookie" version = "0.18.1" @@ -873,9 +850,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.4.0" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" +checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc" dependencies = [ "powerfmt", ] @@ -1005,6 +982,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650" + [[package]] name = "fixedbitset" version = "0.5.7" @@ -1798,9 +1781,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "lru-cache" @@ -2114,7 +2097,6 @@ dependencies = [ "bounded-integer", "bytes", "clap", - "compact_str", "exponential-backoff", "http", "http-serde-ext", @@ -2133,6 +2115,7 @@ dependencies = [ "serde_path_to_error", "serde_regex", "serde_yaml", + "smol_str", "tempfile", "thiserror 1.0.69", "tracing", @@ -2171,7 +2154,6 @@ dependencies = [ "ahash", "bitflags", "chrono", - "compact_str", "criterion", "dhat", "http", @@ -2200,10 +2182,10 @@ dependencies = [ name = "orion-interner" version = "0.1.0" dependencies = [ - "compact_str", "http", "lasso", "serde", + "smol_str", ] [[package]] @@ -2218,7 +2200,6 @@ dependencies = [ "atomic-time", "bounded-integer", "bytes", - "compact_str", "enum_dispatch", "exponential-backoff", "futures", @@ -2310,7 +2291,6 @@ dependencies = [ "axum 0.8.4", "axum-test", "caps", - "compact_str", "dhat", "futures", "http", @@ -2329,6 +2309,7 @@ dependencies = [ "regex", "serde", "serde_json", + "smol_str", "thiserror 1.0.69", "tikv-jemallocator", "tokio", @@ -2346,7 +2327,6 @@ dependencies = [ "arc-swap", "arrayvec", "bounded-integer", - "compact_str", "http", "opentelemetry", "opentelemetry-otlp", @@ -2517,9 +2497,9 @@ checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" [[package]] name = "potential_utf" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" dependencies = [ "zerovec", ] @@ -3504,12 +3484,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.41" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" +checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031" dependencies = [ "deranged", - "itoa", "num-conv", "powerfmt", "serde", @@ -3519,15 +3498,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.4" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" +checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" [[package]] name = "time-macros" -version = "0.2.22" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" +checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3" dependencies = [ "num-conv", "time-core", @@ -3944,9 +3923,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ "getrandom 0.3.3", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index b2011252..2ce6b4a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ orion-xds = { path = "orion-xds" } abort-on-drop = "0.2" bounded-integer = "0.5.8" bytes = "1" -compact_str = { version = "0.8.0", features = ["serde"] } +smol_str = { version = "0.3.2", features = ["serde"] } exponential-backoff = "1.2.0" futures = "0.3" http = "1.0" diff --git a/orion-configuration/Cargo.toml b/orion-configuration/Cargo.toml index b443e403..f763e5ff 100644 --- a/orion-configuration/Cargo.toml +++ b/orion-configuration/Cargo.toml @@ -13,8 +13,8 @@ base64 = "0.22.1" base64-serde = "0.7.0" bounded-integer = { version = "0.5.8", features = ["serde", "types"] } bytes.workspace = true +smol_str.workspace = true clap = { version = "4.5.46", features = ["derive"] } -compact_str.workspace = true exponential-backoff.workspace = true http.workspace = true http-serde-ext = "1.0.2" diff --git a/orion-configuration/src/config/bootstrap.rs b/orion-configuration/src/config/bootstrap.rs index 3739d3c2..6dc57b87 100644 --- a/orion-configuration/src/config/bootstrap.rs +++ b/orion-configuration/src/config/bootstrap.rs @@ -20,8 +20,8 @@ use std::time::Duration; use crate::config::{ cluster::Cluster, common::is_default, core::Address, listener::Listener, metrics::StatsSink, secret::Secret, }; -use compact_str::CompactString; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] pub struct Bootstrap { @@ -40,15 +40,15 @@ pub struct Bootstrap { } impl Bootstrap { - pub fn get_ads_configs(&self) -> &[CompactString] { + pub fn get_ads_configs(&self) -> &[SmolStr] { self.dynamic_resources.as_ref().map(|dr| dr.grpc_cluster_specifiers.as_slice()).unwrap_or_default() } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct Node { - pub id: CompactString, - pub cluster_id: CompactString, + pub id: SmolStr, + pub cluster_id: SmolStr, } impl Node { @@ -65,7 +65,7 @@ impl Node { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct DynamicResources { - pub grpc_cluster_specifiers: Vec, + pub grpc_cluster_specifiers: Vec, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] @@ -88,7 +88,6 @@ mod envoy_conversions { #![allow(deprecated)] use super::{Admin, Bootstrap, DynamicResources, Node, StaticResources}; use crate::config::{common::*, grpc::Duration, metrics::StatsSink}; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::envoy::config::{ bootstrap::v3::{ bootstrap::{DynamicResources as EnvoyDynamicResources, StaticResources as EnvoyStaticResources}, @@ -101,6 +100,7 @@ mod envoy_conversions { }, metrics::v3::stats_sink::ConfigType, }; + use smol_str::SmolStr; impl Bootstrap { pub fn deserialize_from_envoy(rdr: R) -> Result { @@ -310,7 +310,7 @@ mod envoy_conversions { ) .with_node("target_specifier")?; let cluster_name = required!(cluster_name).with_node("target_specifier")?; - cluster_specifiers.push(CompactString::from(cluster_name)) + cluster_specifiers.push(SmolStr::from(cluster_name)) }, EnvoyGrpcTargetSpecifier::GoogleGrpc(_) => { return Err(GenericError::unsupported_variant("GoogleGrpc")) diff --git a/orion-configuration/src/config/cluster.rs b/orion-configuration/src/config/cluster.rs index 0dbd5054..76aa9a29 100644 --- a/orion-configuration/src/config/cluster.rs +++ b/orion-configuration/src/config/cluster.rs @@ -30,13 +30,13 @@ use super::{ transport::{BindDevice, CommonTlsValidationContext, TlsParameters, UpstreamTransportSocketConfig}, }; -use compact_str::CompactString; use http::HeaderName; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use smol_str::SmolStr; use std::{fmt::Display, num::NonZeroU32, time::Duration}; #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Cluster { - pub name: CompactString, + pub name: SmolStr, #[serde(flatten)] pub discovery_settings: ClusterDiscoveryType, #[serde(skip_serializing_if = "Option::is_none", default = "Default::default")] @@ -213,7 +213,7 @@ pub struct TlsConfig { // We could technically fall back to using the endpoint adress/name for the sni // where no sni is configured here but that would require a major refactor. // previous behaviour was to set sni to the empty string if missing. - pub sni: CompactString, + pub sni: SmolStr, #[serde(skip_serializing_if = "is_default", default)] pub parameters: TlsParameters, #[serde(skip_serializing_if = "Option::is_none", default = "Default::default", flatten)] @@ -226,7 +226,7 @@ pub struct TlsConfig { #[serde(rename_all = "snake_case")] pub enum TlsSecret { #[serde(rename = "tls_certificate_sds")] - SdsConfig(CompactString), + SdsConfig(SmolStr), #[serde(rename = "tls_certificate")] Certificate(TlsCertificate), } @@ -259,7 +259,6 @@ mod envoy_conversions { }, util::duration_from_envoy, }; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::{ envoy::{ config::{ @@ -285,6 +284,7 @@ mod envoy_conversions { }, google::protobuf::Any, }; + use smol_str::SmolStr; use http::HeaderName; use std::{collections::BTreeSet, num::NonZeroU32}; @@ -420,20 +420,20 @@ mod envoy_conversions { }, } } else if let Some(metadata_key) = &config.metadata_key { - let key = CompactString::from(&metadata_key.key); + let key = SmolStr::from(&metadata_key.key); let path = metadata_key.path.iter() .filter_map(|path_segment| { if let Some(segment) = &path_segment.segment { match segment { Segment::Key(key_str) => { - Some(CompactString::from(key_str)) + Some(SmolStr::from(key_str)) } } } else { None } }) - .collect::>(); + .collect::>(); OriginalDstRoutingMethod::MetadataKey(MetadataKey { key, path }) } else { OriginalDstRoutingMethod::Default @@ -460,7 +460,6 @@ mod envoy_conversions { } else { Ok(None) }?; - let name = CompactString::from(&name); let discovery_type = extract_discovery_type(&required!(cluster_discovery_type)?) .with_node("cluster_discovery_type")?; if discovery_type == EnvoyDiscoveryType::OriginalDst { @@ -568,7 +567,7 @@ mod envoy_conversions { .map_err(|_| GenericError::from_msg("Failed to convert cleanup_interval into Duration")) .with_node("cleanup_interval")?; Ok(Self { - name, + name: SmolStr::from(&name), discovery_settings, bind_device, transport_socket, diff --git a/orion-configuration/src/config/cluster/cluster_specifier.rs b/orion-configuration/src/config/cluster/cluster_specifier.rs index 6b03fc90..3b690811 100644 --- a/orion-configuration/src/config/cluster/cluster_specifier.rs +++ b/orion-configuration/src/config/cluster/cluster_specifier.rs @@ -15,21 +15,21 @@ // // -use compact_str::CompactString; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use std::{borrow::Cow, num::NonZeroU32}; #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[serde(untagged)] pub enum ClusterSpecifier { - Cluster(CompactString), + Cluster(SmolStr), WeightedCluster(Vec), } impl ClusterSpecifier { pub fn name(&self) -> Cow<'_, str> { match self { - ClusterSpecifier::Cluster(name) => name.into(), + ClusterSpecifier::Cluster(name) => name.as_str().into(), ClusterSpecifier::WeightedCluster(clusters) => { clusters.iter().map(|c| c.cluster.as_str()).collect::>().join(",").into() }, @@ -39,7 +39,7 @@ impl ClusterSpecifier { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct WeightedClusterSpecifier { - pub cluster: CompactString, + pub cluster: SmolStr, pub weight: NonZeroU32, } @@ -48,7 +48,6 @@ mod envoy_conversions { #![allow(deprecated)] use super::{ClusterSpecifier, WeightedClusterSpecifier}; use crate::config::common::*; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::envoy::{ config::route::v3::{ route_action::ClusterSpecifier as EnvoyClusterSpecifier, @@ -59,6 +58,7 @@ mod envoy_conversions { WeightedCluster as EnvoyTcpWeightedCluster, }, }; + use smol_str::{SmolStr, ToSmolStr}; impl TryFrom for ClusterSpecifier { type Error = GenericError; @@ -84,9 +84,7 @@ mod envoy_conversions { type Error = GenericError; fn try_from(value: EnvoyClusterSpecifier) -> Result { match value { - EnvoyClusterSpecifier::Cluster(cluster) => { - required!(cluster).map(CompactString::from).map(Self::Cluster) - }, + EnvoyClusterSpecifier::Cluster(cluster) => required!(cluster).map(SmolStr::from).map(Self::Cluster), EnvoyClusterSpecifier::WeightedClusters(envoy) => envoy.try_into(), EnvoyClusterSpecifier::ClusterHeader(_) => Err(GenericError::unsupported_variant("ClusterHeader")), EnvoyClusterSpecifier::ClusterSpecifierPlugin(_) => { @@ -126,7 +124,7 @@ mod envoy_conversions { typed_per_filter_config, host_rewrite_specifier )?; - let cluster: CompactString = required!(name)?.into(); + let cluster: String = required!(name)?; (|| -> Result<_, GenericError> { // we could allow for default = 1 if missing in ng to allow equaly balanced clusters with shorthand notation let weight = weight.map(|x| x.value).ok_or(GenericError::MissingField("weight"))?; @@ -134,7 +132,7 @@ mod envoy_conversions { .try_into() .map_err(|_| GenericError::from_msg("clusterweight has to be > 0")) .with_node("weight")?; - Ok(Self { cluster: cluster.clone(), weight }) + Ok(Self { cluster: cluster.to_smolstr(), weight }) })() .with_name(cluster) } diff --git a/orion-configuration/src/config/cluster/health_check.rs b/orion-configuration/src/config/cluster/health_check.rs index 784de79b..aef48042 100644 --- a/orion-configuration/src/config/cluster/health_check.rs +++ b/orion-configuration/src/config/cluster/health_check.rs @@ -16,12 +16,12 @@ // use crate::config::common::is_default; -use compact_str::CompactString; use http::{ uri::{Authority, PathAndQuery}, Method, }; use serde::{ser::SerializeStruct, Deserialize, Serialize}; +use smol_str::SmolStr; use std::{ops::Range, str::FromStr, time::Duration}; pub use super::http_protocol_options::Codec; @@ -254,7 +254,7 @@ pub struct TcpHealthCheck { #[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)] pub struct GrpcHealthCheck { - pub service_name: CompactString, + pub service_name: SmolStr, } #[cfg(feature = "envoy-conversions")] diff --git a/orion-configuration/src/config/common.rs b/orion-configuration/src/config/common.rs index df273cf3..376de725 100644 --- a/orion-configuration/src/config/common.rs +++ b/orion-configuration/src/config/common.rs @@ -15,9 +15,9 @@ // // -use compact_str::CompactString; use regex::Regex; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use std::{ borrow::Cow, error::Error, @@ -220,8 +220,8 @@ impl WithNodeOnResult for Result { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct MetadataKey { - pub key: CompactString, - pub path: Vec, + pub key: SmolStr, + pub path: Vec, } #[cfg(feature = "envoy-conversions")] diff --git a/orion-configuration/src/config/core.rs b/orion-configuration/src/config/core.rs index a66b6019..53f99b3f 100644 --- a/orion-configuration/src/config/core.rs +++ b/orion-configuration/src/config/core.rs @@ -18,9 +18,9 @@ use crate::config::common::*; use base64::engine::general_purpose::STANDARD; use base64_serde::base64_serde_type; -use compact_str::CompactString; use regex::Regex; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use std::{ fmt::Debug, hash::{Hash, Hasher}, @@ -31,18 +31,18 @@ base64_serde_type!(Base64Standard, STANDARD); #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum DataSource { - Path(CompactString), + Path(SmolStr), InlineBytes(#[serde(with = "Base64Standard")] Vec), - InlineString(CompactString), - EnvironmentVariable(CompactString), + InlineString(SmolStr), + EnvironmentVariable(SmolStr), } #[derive(thiserror::Error, Debug)] pub enum DataSourceReadError { #[error("failed to read file \"{0}\"")] - IoError(CompactString, #[source] std::io::Error), + IoError(SmolStr, #[source] std::io::Error), #[error("failed to read environment variable \"{0}\"")] - EnvError(CompactString, #[source] std::env::VarError), + EnvError(SmolStr, #[source] std::env::VarError), } impl DataSource { @@ -199,10 +199,10 @@ impl StringMatcher { #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum StringMatcherPattern { - Exact(CompactString), - Prefix(CompactString), - Suffix(CompactString), - Contains(CompactString), + Exact(SmolStr), + Prefix(SmolStr), + Suffix(SmolStr), + Contains(SmolStr), Regex(#[serde(with = "serde_regex")] Regex), } diff --git a/orion-configuration/src/config/listener.rs b/orion-configuration/src/config/listener.rs index b65e9252..08565528 100644 --- a/orion-configuration/src/config/listener.rs +++ b/orion-configuration/src/config/listener.rs @@ -25,9 +25,9 @@ use super::{ }; use crate::config::listener; use crate::config::network_filters::tracing::{TracingConfig, TracingKey}; -use compact_str::CompactString; use ipnet::IpNet; use serde::{Deserialize, Serialize, Serializer}; +use smol_str::SmolStr; use std::hash::{DefaultHasher, Hash, Hasher}; use std::{ collections::HashMap, @@ -39,7 +39,7 @@ use orion_interner::StringInterner; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Listener { - pub name: CompactString, + pub name: SmolStr, pub address: SocketAddr, #[serde(with = "serde_filterchains")] pub filter_chains: HashMap, @@ -133,7 +133,7 @@ mod serde_filterchains { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct FilterChain { pub filter_chain_match_hash: u64, - pub name: CompactString, + pub name: SmolStr, #[serde(skip_serializing_if = "Option::is_none", default = "Default::default")] pub tls_config: Option, #[serde(skip_serializing_if = "Vec::is_empty", default = "Default::default")] @@ -145,7 +145,7 @@ pub struct FilterChain { #[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub struct ServerNameMatch { //eg example.com - name: CompactString, + name: SmolStr, // should we also match on anything.example.com? (but not anythingexample.com) match_subdomains: bool, } @@ -324,7 +324,6 @@ mod envoy_conversions { transport::SupportedEnvoyTransportSocket, util::{envoy_u32_to_u16, u32_to_u16}, }; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::{ envoy::{ config::{ @@ -345,6 +344,7 @@ mod envoy_conversions { google::protobuf::Any, prost::Message, }; + use smol_str::SmolStr; impl TryFrom for Listener { type Error = GenericError; @@ -421,7 +421,7 @@ mod envoy_conversions { bypass_overload_manager, fcds_config )?; - let name: CompactString = required!(name)?.into(); + let name: String = required!(name)?; (|| -> Result<_, GenericError> { let name = name.clone(); let address = Address::into_addr(convert_opt!(address)?)?; @@ -462,7 +462,14 @@ mod envoy_conversions { .with_node("socket_options"); } let bind_device = bind_device.into_iter().next(); - Ok(Self { name, address, filter_chains, bind_device, with_tls_inspector, proxy_protocol_config }) + Ok(Self { + name: name.into(), + address, + filter_chains, + bind_device, + with_tls_inspector, + proxy_protocol_config, + }) }()) .with_name(name) } @@ -490,7 +497,7 @@ mod envoy_conversions { // transport_socket, transport_socket_connect_timeout // name, )?; - let name: CompactString = required!(name)?.into(); + let name = required!(name)?; (|| -> Result<_, GenericError> { let name = name.clone(); let filter_chain_match = filter_chain_match @@ -573,7 +580,13 @@ mod envoy_conversions { filter_chain_match.hash(&mut s); Ok(FilterChainWrapper(( filter_chain_match, - FilterChain { filter_chain_match_hash: s.finish(), name, rbac, terminal_filter, tls_config }, + FilterChain { + filter_chain_match_hash: s.finish(), + name: SmolStr::new(&name), + rbac, + terminal_filter, + tls_config, + }, ))) }()) .with_name(name) @@ -639,7 +652,7 @@ mod envoy_conversions { #[derive(Debug, Clone)] struct Filter { #[allow(unused)] - pub name: Option, + pub name: Option, pub filter: SupportedEnvoyFilter, } @@ -647,7 +660,7 @@ mod envoy_conversions { type Error = GenericError; fn try_from(envoy: EnvoyFilter) -> Result { let EnvoyFilter { name, config_type } = envoy; - let name = name.is_used().then_some(CompactString::from(name)); + let name = name.is_used().then_some(name); let result = (|| -> Result<_, GenericError> { let filter: SupportedEnvoyFilter = match required!(config_type)? { @@ -655,7 +668,7 @@ mod envoy_conversions { EnvoyConfigType::TypedConfig(typed_config) => SupportedEnvoyFilter::try_from(typed_config), } .with_node("config_type")?; - Ok(Self { name: name.clone(), filter }) + Ok(Self { name: name.as_ref().map(SmolStr::new), filter }) })(); if let Some(name) = name { diff --git a/orion-configuration/src/config/listener_filters.rs b/orion-configuration/src/config/listener_filters.rs index 6d60b297..b1966e57 100644 --- a/orion-configuration/src/config/listener_filters.rs +++ b/orion-configuration/src/config/listener_filters.rs @@ -16,11 +16,11 @@ // use crate::config::{common::ProxyProtocolVersion, transport::ProxyProtocolPassThroughTlvs}; -use compact_str::CompactString; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; pub struct ListenerFilter { - pub name: CompactString, + pub name: SmolStr, pub config: ListenerFilterConfig, } @@ -49,7 +49,6 @@ mod envoy_conversions { common::{ProxyProtocolVersion, *}, transport::ProxyProtocolPassThroughTlvs, }; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::{ envoy::{ config::listener::v3::{ @@ -63,6 +62,7 @@ mod envoy_conversions { google::protobuf::Any, prost::Message, }; + use smol_str::SmolStr; #[derive(Debug, Clone)] enum SupportedEnvoyListenerFilter { TlsInspector(EnvoyTlsInspector), @@ -103,7 +103,7 @@ mod envoy_conversions { fn try_from(envoy: EnvoyListenerFilter) -> Result { let EnvoyListenerFilter { name, filter_disabled, config_type } = envoy; unsupported_field!(filter_disabled)?; - let name: CompactString = required!(name)?.into(); + let name: String = required!(name)?; (|| -> Result<_, GenericError> { let config = match required!(config_type) { Ok(EnvoyListenerFilterConfigType::ConfigDiscovery(_)) => { @@ -114,7 +114,7 @@ mod envoy_conversions { }, Err(e) => Err(e), }?; - Ok(Self { name: name.clone(), config }) + Ok(Self { name: SmolStr::new(&name), config }) })() .with_node("config_type") .with_name(name) diff --git a/orion-configuration/src/config/network_filters/http_connection_manager.rs b/orion-configuration/src/config/network_filters/http_connection_manager.rs index d33fea78..e7579677 100644 --- a/orion-configuration/src/config/network_filters/http_connection_manager.rs +++ b/orion-configuration/src/config/network_filters/http_connection_manager.rs @@ -20,7 +20,6 @@ pub mod header_modifer; pub mod http_filters; pub mod route; -use compact_str::CompactString; use exponential_backoff::Backoff; use header_matcher::HeaderMatcher; use header_modifer::{HeaderModifier, HeaderValueOption}; @@ -28,6 +27,7 @@ use http::{HeaderName, HeaderValue, StatusCode}; use http_filters::{FilterOverride, HttpFilter}; use route::{Action, RouteMatch}; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use std::{collections::HashMap, str::FromStr, time::Duration}; use crate::config::{ @@ -96,7 +96,7 @@ pub enum RouteSpecifier { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct RouteConfiguration { - pub name: CompactString, + pub name: SmolStr, #[serde(skip_serializing_if = "std::ops::Not::not", default = "Default::default")] pub most_specific_header_mutations_wins: bool, #[serde(skip_serializing_if = "is_default", default)] @@ -112,9 +112,9 @@ pub struct RouteConfiguration { #[derive(Clone, Debug, PartialEq, Eq)] pub enum MatchHost { Wildcard, - Prefix(CompactString), - Suffix(CompactString), - Exact(CompactString), + Prefix(SmolStr), + Suffix(SmolStr), + Exact(SmolStr), } impl Serialize for MatchHost { @@ -136,13 +136,13 @@ impl<'de> Deserialize<'de> for MatchHost { where D: serde::Deserializer<'de>, { - let cs = CompactString::deserialize(deserializer)?; - Self::try_from_compact_str(cs).map_err(|e| serde::de::Error::custom(format!("{e}"))) + let cs = SmolStr::deserialize(deserializer)?; + Self::try_from_smol_str(cs).map_err(|e| serde::de::Error::custom(format!("{e}"))) } } impl MatchHost { - pub fn try_from_compact_str(value: CompactString) -> Result { + pub fn try_from_smol_str(value: SmolStr) -> Result { let _ = HeaderValue::from_str(&value) .map_err(|_| GenericError::from_msg(format!("failed to parse \"{value}\" as a headervalue")))?; @@ -173,21 +173,21 @@ impl MatchHost { impl TryFrom for MatchHost { type Error = GenericError; fn try_from(value: String) -> Result { - Self::try_from_compact_str(value.into()) + Self::try_from_smol_str(value.into()) } } impl TryFrom<&str> for MatchHost { type Error = GenericError; fn try_from(value: &str) -> Result { - Self::try_from_compact_str(value.into()) + Self::try_from_smol_str(value.into()) } } -impl TryFrom for MatchHost { +impl TryFrom for MatchHost { type Error = GenericError; - fn try_from(value: CompactString) -> Result { - Self::try_from_compact_str(value) + fn try_from(value: SmolStr) -> Result { + Self::try_from_smol_str(value) } } @@ -248,7 +248,7 @@ impl MatchHost { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Default)] pub struct VirtualHost { - pub name: CompactString, + pub name: SmolStr, pub domains: Vec, #[serde(skip_serializing_if = "Vec::is_empty", default = "Default::default")] pub routes: Vec, @@ -373,7 +373,7 @@ pub struct Route { #[serde(rename = "match")] pub route_match: RouteMatch, #[serde(skip_serializing_if = "HashMap::is_empty", default = "Default::default")] - pub typed_per_filter_config: std::collections::HashMap, + pub typed_per_filter_config: std::collections::HashMap, #[serde(flatten)] pub action: Action, } @@ -386,7 +386,7 @@ pub struct UpgradeConfig { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct RdsSpecifier { - pub route_config_name: CompactString, + pub route_config_name: SmolStr, pub config_source: ConfigSource, } @@ -583,7 +583,6 @@ mod envoy_conversions { network_filters::access_log::AccessLog, util::{duration_from_envoy, http_status_from}, }; - use compact_str::CompactString; use http::HeaderName; use orion_data_plane_api::envoy_data_plane_api::envoy::{ config::{ @@ -601,15 +600,16 @@ mod envoy_conversions { HttpConnectionManager as EnvoyHttpConnectionManager, Rds as EnvoyRds, }, }; + use smol_str::SmolStr; use std::{collections::HashMap, str::FromStr, time::Duration}; impl HttpConnectionManager { pub(crate) fn ensure_corresponding_filter_exists( - filter_override: (&CompactString, &FilterOverride), + filter_override: (&SmolStr, &FilterOverride), http_filters: &[HttpFilter], ) -> Result<(), GenericError> { let (name, config) = filter_override; - match http_filters.iter().find(|filter| filter.name == name) { + match http_filters.iter().find(|filter| &filter.name == name) { None => Err(GenericError::from_msg(format!("http filter \"{name}\" does not exist"))), Some(matching_filter) => match &config.filter_settings { None => Ok(()), @@ -761,10 +761,10 @@ mod envoy_conversions { let mut http_filters: Vec = convert_non_empty_vec!(http_filters)?; match http_filters.pop() { Some(SupportedEnvoyHttpFilter { filter: SupportedEnvoyFilter::Router(rtr), name, disabled: false }) => { - Router::try_from(rtr).with_node(name) + Router::try_from(rtr).with_node(name.to_string()) }, Some(SupportedEnvoyHttpFilter { filter: SupportedEnvoyFilter::Router(_), name, disabled: true }) => { - Err(GenericError::from_msg("router cannot be disabled").with_node(name)) + Err(GenericError::from_msg("router cannot be disabled").with_node(name.to_string())) }, _ => Err(GenericError::from_msg("final filter of the chain has to be a router")), } @@ -792,7 +792,7 @@ mod envoy_conversions { return Err(e .with_node("typed_per_filter_config") .with_node("route") - .with_node(vh.name.clone()) + .with_node(vh.name.to_string()) .with_node("virtual_hosts") .with_node("route_specifier")); } @@ -919,7 +919,7 @@ mod envoy_conversions { typed_per_filter_config, metadata )?; - let name: CompactString = required!(name)?.into(); + let name: String = required!(name)?; (|| -> Result<_, GenericError> { let response_headers_to_add = convert_vec!(response_headers_to_add)?; let request_headers_to_add = convert_vec!(request_headers_to_add)?; @@ -944,7 +944,7 @@ mod envoy_conversions { let virtual_hosts = convert_non_empty_vec!(virtual_hosts)?; let response_header_modifier = HeaderModifier::new(response_headers_to_remove, response_headers_to_add); Ok(Self { - name: name.clone(), + name: SmolStr::from(&name), virtual_hosts, most_specific_header_mutations_wins, response_header_modifier, @@ -1008,7 +1008,7 @@ mod envoy_conversions { request_mirror_policies, metadata )?; - let name: CompactString = required!(name)?.into(); + let name: String = required!(name)?; (|| -> Result<_, GenericError> { let response_headers_to_add = convert_vec!(response_headers_to_add)?; let request_headers_to_add = convert_vec!(request_headers_to_add)?; @@ -1036,7 +1036,7 @@ mod envoy_conversions { let retry_policy = retry_policy.map(RetryPolicy::try_from).transpose().with_node("retry_policy")?; let response_header_modifier = HeaderModifier::new(response_headers_to_remove, response_headers_to_add); Ok(Self { - name: name.clone(), + name: SmolStr::from(&name), routes, domains, request_headers_to_add, @@ -1200,7 +1200,7 @@ mod envoy_conversions { typed_per_filter_config .into_iter() .map(|(name, typed_config)| { - FilterOverride::try_from(typed_config).map(|x| (CompactString::new(&name), x)).with_node(name) + FilterOverride::try_from(typed_config).map(|x| (SmolStr::new(&name), x)).with_node(name) }) .collect::, GenericError>>() } diff --git a/orion-configuration/src/config/network_filters/http_connection_manager/http_filters.rs b/orion-configuration/src/config/network_filters/http_connection_manager/http_filters.rs index 2f4cbc54..7766701d 100644 --- a/orion-configuration/src/config/network_filters/http_connection_manager/http_filters.rs +++ b/orion-configuration/src/config/network_filters/http_connection_manager/http_filters.rs @@ -16,8 +16,8 @@ // pub mod http_rbac; -use compact_str::CompactString; use http_rbac::HttpRbac; +use smol_str::SmolStr; pub mod local_rate_limit; use local_rate_limit::LocalRateLimit; pub mod router; @@ -48,7 +48,7 @@ impl From for FilterOverride { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct HttpFilter { - pub name: CompactString, + pub name: SmolStr, #[serde(skip_serializing_if = "is_default", default)] pub disabled: bool, #[serde(flatten)] @@ -72,7 +72,6 @@ mod envoy_conversions { #![allow(deprecated)] use super::{FilterConfigOverride, FilterOverride, HttpFilter, HttpFilterType, HttpRbac}; use crate::config::common::*; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::{ envoy::{ config::route::v3::FilterConfig as EnvoyFilterConfig, @@ -90,10 +89,11 @@ mod envoy_conversions { google::protobuf::Any, prost::Message, }; + use smol_str::SmolStr; #[derive(Debug, Clone)] pub(crate) struct SupportedEnvoyHttpFilter { - pub name: CompactString, + pub name: SmolStr, pub disabled: bool, pub filter: SupportedEnvoyFilter, } @@ -103,14 +103,14 @@ mod envoy_conversions { fn try_from(envoy: EnvoyHttpFilter) -> Result { let EnvoyHttpFilter { name, is_optional, disabled, config_type } = envoy; unsupported_field!(is_optional)?; - let name: CompactString = required!(name)?.into(); + let name = required!(name)?; match required!(config_type).map(|x| match x { EnvoyConfigType::ConfigDiscovery(_) => { Err(GenericError::unsupported_variant("ConfigDiscovery")).with_node(name.clone()) }, EnvoyConfigType::TypedConfig(typed_config) => SupportedEnvoyFilter::try_from(typed_config), }) { - Ok(Ok(filter)) => Ok(Self { name, filter, disabled }), + Ok(Ok(filter)) => Ok(Self { name: SmolStr::from(name), filter, disabled }), Err(e) | Ok(Err(e)) => Err(e.with_name(name)), } } diff --git a/orion-configuration/src/config/network_filters/http_connection_manager/route.rs b/orion-configuration/src/config/network_filters/http_connection_manager/route.rs index 16207461..5c54804d 100644 --- a/orion-configuration/src/config/network_filters/http_connection_manager/route.rs +++ b/orion-configuration/src/config/network_filters/http_connection_manager/route.rs @@ -22,13 +22,13 @@ use crate::config::{ core::{CaseSensitive, DataSource, StringMatcher}, }; use bytes::Bytes; -use compact_str::CompactString; use http::{ uri::{Authority, InvalidUri, PathAndQuery, Scheme}, HeaderName, Request, StatusCode, }; use regex::Regex; use serde::{de::Error, Deserialize, Serialize}; +use smol_str::SmolStr; use std::{ borrow::Cow, hash::{Hash, Hasher}, @@ -63,7 +63,7 @@ pub enum AuthorityRedirect { pub struct RegexMatchAndSubstitute { #[serde(with = "serde_regex")] pub pattern: Regex, - pub substitution: CompactString, + pub substitution: SmolStr, } impl PartialEq for RegexMatchAndSubstitute { @@ -78,7 +78,7 @@ impl Eq for RegexMatchAndSubstitute {} #[serde(rename_all = "snake_case")] pub enum PathRewriteSpecifier { Path(#[serde(with = "http_serde_ext::path_and_query")] PathAndQuery), - Prefix(CompactString), + Prefix(SmolStr), Regex(RegexMatchAndSubstitute), } @@ -317,7 +317,7 @@ impl HashPolicy { // Hash the value of the first query key that matches (case-sensitive) //note(hayley): we might slightly improve performance here by urlencoding the name parameter // instead of decoding the query - url::form_urlencoded::parse(query.as_bytes()).find(|(key, _value)| key == name) + url::form_urlencoded::parse(query.as_bytes()).find(|(key, _value)| key.as_ref() == name) }) .inspect(|(_key, value)| value.hash(hasher)) .is_some(), @@ -336,7 +336,7 @@ impl HashPolicy { pub enum PolicySpecifier { SourceIp(bool), Header(#[serde(with = "http_serde_ext::header_name")] HeaderName), - QueryParameter(CompactString), + QueryParameter(SmolStr), } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] @@ -348,7 +348,7 @@ pub enum QueryParameterMatchSpecifier { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] pub struct QueryParameterMatcher { - pub name: CompactString, + pub name: SmolStr, #[serde(flatten)] pub match_specifier: QueryParameterMatchSpecifier, } @@ -402,7 +402,7 @@ impl RouteMatchResult { impl QueryParameterMatcher { pub fn matches(&self, query: Option<&str>) -> bool { let param_value = query.and_then(|q| { - url::form_urlencoded::parse(q.as_bytes()).find(|(key, _)| key == self.name).map(|(_, value)| value) + url::form_urlencoded::parse(q.as_bytes()).find(|(key, _)| key.as_ref() == self.name).map(|(_, value)| value) }); match &self.match_specifier { @@ -485,10 +485,10 @@ impl PathMatcher { #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum PathSpecifier { - Prefix(CompactString), - Exact(CompactString), + Prefix(SmolStr), + Exact(SmolStr), Regex(#[serde(with = "serde_regex")] Regex), - PathSeparatedPrefix(CompactString), + PathSeparatedPrefix(SmolStr), } impl PartialEq for PathSpecifier { diff --git a/orion-configuration/src/config/network_filters/tracing.rs b/orion-configuration/src/config/network_filters/tracing.rs index ee080105..4353ae92 100644 --- a/orion-configuration/src/config/network_filters/tracing.rs +++ b/orion-configuration/src/config/network_filters/tracing.rs @@ -16,8 +16,8 @@ // use ::bounded_integer::BoundedU16; -use compact_str::CompactString; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use orion_data_plane_api::envoy_data_plane_api::envoy::{ extensions::filters::network::http_connection_manager::v3::http_connection_manager::Tracing as EnvoyTracing, @@ -39,7 +39,7 @@ pub enum SupportedTracingProvider { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] pub struct OpenTelemetryConfig { pub grpc_service: Option, - pub service_name: CompactString, + pub service_name: SmolStr, } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] @@ -69,8 +69,8 @@ pub struct TracingKey(pub ListenerName, pub FilterChainMatchHash); #[cfg(feature = "envoy-conversions")] mod envoy_conversions { use crate::config::{common::envoy_conversions::IsUsed, unsupported_field, GenericError}; - use compact_str::ToCompactString; use orion_data_plane_api::envoy_data_plane_api::prost::Message; + use smol_str::ToSmolStr; use super::*; @@ -158,7 +158,7 @@ mod envoy_conversions { Ok(SupportedTracingProvider::OpenTelemetry(OpenTelemetryConfig { grpc_service, - service_name: service_name.to_compact_string(), + service_name: service_name.to_smolstr(), })) } } diff --git a/orion-configuration/src/config/runtime.rs b/orion-configuration/src/config/runtime.rs index 0442d07a..f8429c92 100644 --- a/orion-configuration/src/config/runtime.rs +++ b/orion-configuration/src/config/runtime.rs @@ -22,7 +22,6 @@ use std::{ num::{NonZeroU32, NonZeroUsize}, ops::Deref, }; -use tracing; use crate::options::Options; @@ -144,7 +143,7 @@ fn get_cgroup_v2_cpu_limit() -> crate::Result { } fn parse_cgroup_v2_cpu_max(content: &str) -> crate::Result { - let parts: Vec<&str> = content.trim().split_whitespace().collect(); + let parts: Vec<&str> = content.split_whitespace().collect(); if parts.len() == 2 && parts[0] != "max" { let quota: i64 = parts[0].parse()?; let period: i64 = parts[1].parse()?; @@ -160,7 +159,7 @@ fn parse_cgroup_v2_cpu_max(content: &str) -> crate::Result { fn get_cgroup_v1_cpu_limit() -> crate::Result { let cgroup_path = get_cgroup_v1_cpu_path()?; - let quota_path = format!("{}/cpu.cfs_quota_us", cgroup_path); + let quota_path = format!("{cgroup_path}/cpu.cfs_quota_us"); let period_path = format!("{}/cpu.cfs_period_us", cgroup_path); let quota_content = std::fs::read_to_string("a_path)?; diff --git a/orion-configuration/src/config/secret.rs b/orion-configuration/src/config/secret.rs index 9f26609b..b6c6fe94 100644 --- a/orion-configuration/src/config/secret.rs +++ b/orion-configuration/src/config/secret.rs @@ -16,13 +16,13 @@ // use crate::config::core::DataSource; -use compact_str::CompactString; use serde::{Deserialize, Serialize}; +use smol_str::SmolStr; use std::fmt::Debug; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Secret { - pub name: CompactString, + pub name: SmolStr, #[serde(flatten)] pub kind: Type, } @@ -100,19 +100,19 @@ mod envoy_conversions { #![allow(deprecated)] use super::{Secret, TlsCertificate, Type, ValidationContext}; use crate::config::common::*; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::envoy::extensions::transport_sockets::tls::v3::{ secret::Type as EnvoyType, CertificateValidationContext as EnvoyCertificateValidationContext, Secret as EnvoySecret, TlsCertificate as EnvoyTlsCertificate, }; + use smol_str::SmolStr; impl TryFrom for Secret { type Error = GenericError; fn try_from(envoy: EnvoySecret) -> Result { let EnvoySecret { name, r#type } = envoy; - let name: CompactString = required!(name)?.into(); + let name = required!(name)?; let kind = convert_opt!(r#type, "type").with_name(name.clone())?; - Ok(Self { name, kind }) + Ok(Self { name: SmolStr::from(name), kind }) } } impl TryFrom for Type { diff --git a/orion-configuration/src/config/transport.rs b/orion-configuration/src/config/transport.rs index 64e3dd6c..6dab2882 100644 --- a/orion-configuration/src/config/transport.rs +++ b/orion-configuration/src/config/transport.rs @@ -18,12 +18,12 @@ use super::secret::{TlsCertificate, ValidationContext}; use crate::config::{cluster, common::*}; use base64::Engine as _; -use compact_str::CompactString; use serde::{ de::{self, MapAccess, Visitor}, ser::SerializeStruct, Deserialize, Serialize, }; +use smol_str::SmolStr; use std::{ ffi::{CStr, CString}, str::FromStr, @@ -202,14 +202,14 @@ impl Default for TlsParameters { } pub struct SdsConfig { - pub name: CompactString, + pub name: SmolStr, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum Secrets { #[serde(rename = "tls_certificates_sds")] - SdsConfig(Vec), + SdsConfig(Vec), #[serde(rename = "tls_certificates")] Certificates(Vec), } @@ -243,7 +243,7 @@ impl From> for Secrets { #[serde(rename_all = "snake_case")] pub enum CommonTlsValidationContext { #[serde(rename = "validation_context_sds")] - SdsConfig(CompactString), + SdsConfig(SmolStr), ValidationContext(ValidationContext), } @@ -292,7 +292,6 @@ mod envoy_conversions { SdsConfig, Secrets, TlsCertificate, TlsParameters, TlsVersion, TlvEntry, UpstreamProxyProtocolConfig, }; use crate::config::{cluster, common::*}; - use compact_str::CompactString; use orion_data_plane_api::envoy_data_plane_api::{ envoy::{ config::core::v3::{ @@ -314,6 +313,7 @@ mod envoy_conversions { google::protobuf::Any, prost::Message, }; + use smol_str::SmolStr; impl BindDevice { const fn socket_option() -> (i64, i64) { @@ -459,9 +459,9 @@ mod envoy_conversions { type Error = GenericError; fn try_from(value: EnvoySdsSecretConfig) -> Result { let EnvoySdsSecretConfig { name, sds_config } = value; - let name: CompactString = required!(name)?.into(); + let name: String = required!(name)?; unsupported_field!(sds_config).with_name(name.clone())?; - Ok(Self { name }) + Ok(Self { name: SmolStr::from(name) }) } } diff --git a/orion-format/Cargo.toml b/orion-format/Cargo.toml index 47342e0f..51139070 100644 --- a/orion-format/Cargo.toml +++ b/orion-format/Cargo.toml @@ -12,12 +12,12 @@ workspace = true http.workspace = true orion-http-header.workspace = true orion-interner.workspace = true -thiserror.workspace = true +thiserror.workspace = true +smol_str.workspace = true ahash = "0.8.11" bitflags = { version = "2.9.0", features = ["serde"] } chrono = "0.4.40" -compact_str = "0.8.0" criterion = "0.5.1" dhat = "0.3.3" http-serde-ext = "1.0.2" @@ -25,7 +25,6 @@ hyper = { version = "1" } itoa = "1.0.15" ptrie = "0.7.2" serde = { workspace = true, features = ["rc"] } -smol_str = { version = "0.3.2", features = ["serde"] } thread_local = "1.1.8" traceparent = "0.0.3" uuid = { version = "1.16.0", features = ["v4"] } diff --git a/orion-format/src/context.rs b/orion-format/src/context.rs index 7bd33f4a..332754c4 100644 --- a/orion-format/src/context.rs +++ b/orion-format/src/context.rs @@ -30,7 +30,8 @@ use chrono::{DateTime, Datelike, Timelike, Utc}; use http::{uri::Authority, Request, Response}; use orion_http_header::{X_ENVOY_ORIGINAL_PATH, X_REQUEST_ID}; use orion_interner::StringInterner; -use smol_str::{format_smolstr, SmolStr, SmolStrBuilder, ToSmolStr}; +use smol_str::ToSmolStr; +use smol_str::{format_smolstr, SmolStr, SmolStrBuilder}; use uuid::Uuid; pub trait Context { @@ -473,10 +474,10 @@ pub fn format_system_time_heapless(time: SystemTime) -> heapless::String<24> { } #[cfg(any())] -pub fn format_system_time_compact(time: SystemTime) -> CompactString { +pub fn format_system_time_compact(time: SystemTime) -> SmolStr { let datetime: DateTime = time.into(); let mut buffer = itoa::Buffer::new(); - let mut rfc3999 = CompactString::default(); + let mut rfc3999 = SmolStr::default(); _ = rfc3999.push_str(buffer.format(datetime.year())); _ = rfc3999.push('-'); diff --git a/orion-interner/Cargo.toml b/orion-interner/Cargo.toml index a6015469..8d31db6f 100644 --- a/orion-interner/Cargo.toml +++ b/orion-interner/Cargo.toml @@ -9,7 +9,7 @@ version.workspace = true workspace = true [dependencies] -compact_str.workspace = true +smol_str.workspace = true http.workspace = true lasso = { version = "0.7.3", features = [ "ahash", diff --git a/orion-interner/src/lib.rs b/orion-interner/src/lib.rs index 6131e51b..0fdf1ea6 100644 --- a/orion-interner/src/lib.rs +++ b/orion-interner/src/lib.rs @@ -17,9 +17,9 @@ use std::sync::OnceLock; -use compact_str::CompactString; use http::Version; use lasso::ThreadedRodeo; +use smol_str::SmolStr; static GLOBAL_INTERNER: OnceLock = OnceLock::new(); @@ -52,7 +52,7 @@ impl StringInterner for String { } } -impl StringInterner for CompactString { +impl StringInterner for SmolStr { fn to_static_str(&self) -> &'static str { intern_str(self) } diff --git a/orion-lib/Cargo.toml b/orion-lib/Cargo.toml index 7dcbea61..885db7df 100644 --- a/orion-lib/Cargo.toml +++ b/orion-lib/Cargo.toml @@ -13,7 +13,7 @@ arrayvec = "0.7.6" async-stream = "0.3" atomic-time = "0.1.4" bytes.workspace = true -compact_str.workspace = true +smol_str.workspace = true enum_dispatch = "0.3.13" exponential-backoff.workspace = true futures.workspace = true @@ -54,7 +54,6 @@ rustls-platform-verifier = { version = "0.3" } rustls-webpki = "0.102" scopeguard = "1.2.0" serde.workspace = true -smol_str = "0.3.2" thiserror.workspace = true thread-id = "5.0.0" thread_local = "1.1.8" diff --git a/orion-lib/src/access_log.rs b/orion-lib/src/access_log.rs index b48a25cb..c0191fa4 100644 --- a/orion-lib/src/access_log.rs +++ b/orion-lib/src/access_log.rs @@ -22,13 +22,13 @@ mod log_writer; pub mod logger; mod pool; -use compact_str::CompactString; use logger::AccessLogger; use once_cell::sync::OnceCell; use orion_configuration::config::network_filters::access_log::AccessLogConf; use orion_format::FormattedMessage; use parking_lot::Mutex; use pool::LoggerPool; +use smol_str::SmolStr; use tracing_appender::rolling::Rotation; use std::{fmt::Display, hash::Hash, sync::Arc}; @@ -44,7 +44,7 @@ use tracing::{error, info}; /// - `Admin`: Refers to the Envoy admin interface. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Target { - Listener(CompactString), + Listener(SmolStr), Admin, } diff --git a/orion-lib/src/listeners/filterchain.rs b/orion-lib/src/listeners/filterchain.rs index d33c78bb..1b0482b3 100644 --- a/orion-lib/src/listeners/filterchain.rs +++ b/orion-lib/src/listeners/filterchain.rs @@ -25,7 +25,6 @@ use crate::{ transport::AsyncReadWrite, AsyncStream, ConversionContext, Error, Result, }; -use compact_str::CompactString; use futures::TryFutureExt; use hyper::{service::Service, Request}; use hyper_util::rt::{TokioExecutor, TokioIo}; @@ -44,6 +43,7 @@ use orion_metrics::{ }; use rustls::{server::Acceptor, ServerConfig}; use scopeguard::defer; +use smol_str::SmolStr; use std::{sync::Arc, thread::ThreadId}; use tracing::{debug, warn}; @@ -61,7 +61,7 @@ pub enum ConnectionHandler { #[derive(Debug, Clone)] pub struct Filterchain { - pub name: CompactString, + pub name: SmolStr, pub rbac_filters: Vec, pub tls_configurator: Option>, } @@ -87,7 +87,7 @@ impl TryFrom> for MainFilterBuilder { #[derive(Debug, Clone)] pub struct FilterchainBuilder { - name: CompactString, + name: SmolStr, listener_name: Option<&'static str>, filter_chain_match_hash: u64, main_filter: MainFilterBuilder, diff --git a/orion-lib/src/listeners/http_connection_manager.rs b/orion-lib/src/listeners/http_connection_manager.rs index 1153ce5f..3968dacb 100644 --- a/orion-lib/src/listeners/http_connection_manager.rs +++ b/orion-lib/src/listeners/http_connection_manager.rs @@ -31,7 +31,6 @@ mod upgrades; use ::http::HeaderValue; use arc_swap::ArcSwap; -use compact_str::{CompactString, ToCompactString}; use core::time::Duration; use futures::future::BoxFuture; use hyper::{body::Incoming, service::Service, Request, Response}; @@ -41,6 +40,7 @@ use opentelemetry::KeyValue; use orion_configuration::config::GenericError; use orion_tracing::span_state::SpanState; use orion_tracing::{attributes::HTTP_RESPONSE_STATUS_CODE, with_client_span, with_server_span}; +use smol_str::{SmolStr, ToSmolStr}; use orion_configuration::config::network_filters::http_connection_manager::http_filters::{ FilterConfigOverride, FilterOverride, @@ -156,7 +156,7 @@ impl HttpConnectionManagerBuilder { pub struct PartialHttpConnectionManager { router: Option, codec_type: CodecType, - dynamic_route_name: Option, + dynamic_route_name: Option, http_filters_hcm: Vec>, http_filters_per_route: HashMap>>, enabled_upgrades: Vec, @@ -171,7 +171,7 @@ pub struct PartialHttpConnectionManager { #[derive(Debug, Clone)] pub struct HttpFilter { - pub name: CompactString, + pub name: SmolStr, pub disabled: bool, pub filter: Option, } @@ -267,7 +267,7 @@ impl TryFrom> for PartialHttp route_config_name, config_source: ConfigSource { config_source_specifier }, }) => match config_source_specifier { - ConfigSourceSpecifier::ADS => (Some(route_config_name.to_compact_string()), None), + ConfigSourceSpecifier::ADS => (Some(route_config_name.to_smolstr()), None), }, RouteSpecifier::RouteConfig(config) => { http_filters_per_route = per_route_http_filters(&config, &http_filters_hcm); @@ -324,7 +324,7 @@ pub struct HttpConnectionManager { pub filter_chain_match_hash: u64, router_sender: watch::Sender>>, pub codec_type: CodecType, - dynamic_route_name: Option, + dynamic_route_name: Option, http_filters_hcm: Vec>, http_filters_per_route: ArcSwap>>>, enabled_upgrades: Vec, @@ -348,7 +348,7 @@ impl HttpConnectionManager { } #[inline] - pub fn get_route_id(&self) -> Option<&CompactString> { + pub fn get_route_id(&self) -> Option<&SmolStr> { self.dynamic_route_name.as_ref() } @@ -1049,7 +1049,7 @@ fn eval_http_finish_context( let loggers: Vec = std::mem::take(access_loggers); let messages = loggers.into_iter().map(LogFormatterLocal::into_message).collect::>(); - log_access(permit, Target::Listener(listener_name.to_compact_string()), messages); + log_access(permit, Target::Listener(listener_name.to_smolstr()), messages); } fn apply_authorization_rules(rbac: &HttpRbac, req: &Request) -> FilterDecision { diff --git a/orion-lib/src/listeners/listener.rs b/orion-lib/src/listeners/listener.rs index ff7eb5a7..861c9261 100644 --- a/orion-lib/src/listeners/listener.rs +++ b/orion-lib/src/listeners/listener.rs @@ -498,7 +498,7 @@ impl Listener { if let ConnectionHandler::Http(http_manager) = &chain.handler { let route_id = http_manager.get_route_id(); if let Some(route_id) = route_id { - if route_id == id { + if route_id == &id { debug!("{listener_name} Route updated {id} {route:?}"); http_manager.update_route(route.clone()); } @@ -512,7 +512,7 @@ impl Listener { for chain in filter_chains.values() { if let ConnectionHandler::Http(http_manager) = &chain.handler { if let Some(route_id) = http_manager.get_route_id() { - if route_id == id { + if route_id == &id { http_manager.remove_route(); } } diff --git a/orion-lib/src/listeners/tcp_proxy.rs b/orion-lib/src/listeners/tcp_proxy.rs index 28b60c4c..0cddeaa8 100644 --- a/orion-lib/src/listeners/tcp_proxy.rs +++ b/orion-lib/src/listeners/tcp_proxy.rs @@ -22,7 +22,6 @@ use crate::{ transport::connector::TcpErrorContext, AsyncStream, Result, }; -use compact_str::ToCompactString; use orion_configuration::config::{ cluster::ClusterSpecifier as ClusterSpecifierConfig, network_filters::{access_log::AccessLog, tcp_proxy::TcpProxy as TcpProxyConfig}, @@ -32,6 +31,7 @@ use orion_format::{ types::ResponseFlags, LogFormatterLocal, }; +use smol_str::ToSmolStr; use std::{fmt, net::SocketAddr, sync::Arc, time::Instant}; use tracing::{debug, error}; @@ -175,7 +175,7 @@ impl TcpProxy { }); let permit = log_access_reserve_balanced().await; let messages = access_loggers.into_iter().map(LogFormatterLocal::into_message).collect::>(); - log_access(permit, Target::Listener(self.listener_name.to_compact_string()), messages); + log_access(permit, Target::Listener(self.listener_name.to_smolstr()), messages); res } } diff --git a/orion-lib/src/secrets/secrets_manager.rs b/orion-lib/src/secrets/secrets_manager.rs index 32179f4e..06f9ae5c 100644 --- a/orion-lib/src/secrets/secrets_manager.rs +++ b/orion-lib/src/secrets/secrets_manager.rs @@ -16,7 +16,6 @@ // use crate::Result; -use compact_str::{CompactString, ToCompactString}; use orion_configuration::{ config::secret::{Secret, TlsCertificate, Type, ValidationContext}, VerifySingleIter, @@ -27,6 +26,7 @@ use rustls::{ RootCertStore, }; use rustls_pemfile::{certs, pkcs8_private_keys}; +use smol_str::{SmolStr, ToSmolStr}; use std::sync::Arc; use tracing::{debug, warn}; use webpki::types::ServerName; @@ -76,7 +76,7 @@ pub struct SecretManager { #[derive(Debug, Clone)] pub struct CertificateSecret { - pub name: Option, + pub name: Option, pub key: Arc>, pub certs: Arc>>, pub config: TlsCertificate, @@ -120,7 +120,7 @@ impl TryFrom<&TlsCertificate> for CertificateSecret { let is_server_name = ServerName::try_from(name.clone()).is_ok(); debug!("Certificate SAN name {san_name} {name } is server name {is_server_name}"); if is_server_name { - server_name = Some(name.to_compact_string()); + server_name = Some(name.to_smolstr()); } } } diff --git a/orion-lib/src/secrets/tls_configurator/configurator.rs b/orion-lib/src/secrets/tls_configurator/configurator.rs index 47cd5fe5..b241a4f0 100644 --- a/orion-lib/src/secrets/tls_configurator/configurator.rs +++ b/orion-lib/src/secrets/tls_configurator/configurator.rs @@ -24,7 +24,6 @@ use crate::{ }, Result, SecretManager, }; -use compact_str::CompactString; use orion_configuration::config::{ cluster::{TlsConfig as TlsClientConfig, TlsSecret}, listener::TlsConfig as TlsServerConfig, @@ -39,6 +38,7 @@ use rustls::{ ClientConfig, RootCertStore, ServerConfig, }; use rustls_platform_verifier::Verifier; +use smol_str::SmolStr; use std::{collections::HashMap, result::Result as StdResult, sync::Arc}; use tracing::{debug, warn}; use webpki::types::ServerName; @@ -181,7 +181,7 @@ impl TryFrom for ClientCert { #[derive(Clone)] pub struct ServerCert { - pub name: CompactString, + pub name: SmolStr, pub key: Arc>, pub certs: Arc>>, } @@ -325,7 +325,7 @@ impl TryFrom<(TlsServerConfig, &SecretManager)> for TlsConfigurator for TlsConfigurator for TlsConfigurator { fn create_certificate_store( secret_manager: &SecretManager, validation_options: Option, - ) -> Result<(Option, Option>)> { + ) -> Result<(Option, Option>)> { match validation_options { Some(CommonTlsValidationContext::ValidationContext(validation_context)) => { Ok((None, Some(CertStore::try_from(&validation_context)?.into()))) diff --git a/orion-lib/src/secrets/tls_configurator/tls_configurator_builder.rs b/orion-lib/src/secrets/tls_configurator/tls_configurator_builder.rs index 689e08cf..048a7fef 100644 --- a/orion-lib/src/secrets/tls_configurator/tls_configurator_builder.rs +++ b/orion-lib/src/secrets/tls_configurator/tls_configurator_builder.rs @@ -17,11 +17,11 @@ use std::sync::Arc; -use compact_str::CompactString; use rustls::{ client::WebPkiServerVerifier, server::WebPkiClientVerifier, sign::CertifiedKey, ClientConfig, RootCertStore, ServerConfig, SupportedProtocolVersion, }; +use smol_str::SmolStr; use tracing::{debug, warn}; use super::configurator::{get_crypto_key_provider, ClientCert, RelaxedResolvesServerCertUsingSni, ServerCert}; @@ -47,7 +47,7 @@ pub struct WantsClientCert { #[derive(Debug, Clone)] pub struct SecretHolder { - pub name: CompactString, + pub name: SmolStr, pub server_cert: ServerCert, } @@ -71,7 +71,7 @@ impl Ord for SecretHolder { } } impl SecretHolder { - pub fn new(name: CompactString, server_cert: ServerCert) -> Self { + pub fn new(name: SmolStr, server_cert: ServerCert) -> Self { Self { name, server_cert } } } diff --git a/orion-lib/src/transport/http_channel.rs b/orion-lib/src/transport/http_channel.rs index cf369b1b..21684738 100644 --- a/orion-lib/src/transport/http_channel.rs +++ b/orion-lib/src/transport/http_channel.rs @@ -67,7 +67,7 @@ use webpki::types::ServerName; #[cfg(feature = "metrics")] use { - hyper_util::client::legacy::pool::{ConnectionEvent, EventHandler, Tag}, + hyper_util::client::legacy::pool::{ConnectionEvent, Tag}, hyper_util::client::legacy::PoolKey, std::any::Any, }; diff --git a/orion-proxy/Cargo.toml b/orion-proxy/Cargo.toml index 4d40b589..a85f863b 100644 --- a/orion-proxy/Cargo.toml +++ b/orion-proxy/Cargo.toml @@ -36,7 +36,7 @@ tower.workspace = true tracing.workspace = true axum = "0.8.1" -compact_str.workspace = true +smol_str.workspace = true http.workspace = true opentelemetry = "0.29.0" prometheus = { version = "0.14.0", features = ["process"] } diff --git a/orion-proxy/src/admin/config_dump.rs b/orion-proxy/src/admin/config_dump.rs index 5fb8aecd..baa3fdc6 100644 --- a/orion-proxy/src/admin/config_dump.rs +++ b/orion-proxy/src/admin/config_dump.rs @@ -104,7 +104,6 @@ pub async fn get_config_dump(State(admin_state): State) -> Json Result<()> { listeners.iter().map(|l| (l.name.clone(), l.get_access_log_configurations())).collect::>(); for (listener_name, access_log_configurations) in listener_configurations { - _ = update_configuration( - Target::Listener(listener_name.to_compact_string()), - access_log_configurations, - ) - .await; + _ = update_configuration(Target::Listener(listener_name.to_smolstr()), access_log_configurations).await; } handles.join_all().await; diff --git a/orion-proxy/src/xds_configurator.rs b/orion-proxy/src/xds_configurator.rs index 28046ae2..9a62bc32 100644 --- a/orion-proxy/src/xds_configurator.rs +++ b/orion-proxy/src/xds_configurator.rs @@ -16,8 +16,6 @@ // use abort_on_drop::ChildTask; -#[cfg(feature = "tracing")] -use compact_str::ToCompactString; use futures::future::join_all; use orion_configuration::config::{bootstrap::Node, cluster::ClusterSpecifier, Listener}; use orion_lib::{ @@ -36,6 +34,8 @@ use orion_xds::{ }, }; use parking_lot::RwLock; +#[cfg(feature = "tracing")] +use smol_str::ToSmolStr; use std::{sync::Arc, time::Duration}; use tokio::{ select, @@ -322,7 +322,7 @@ impl XdsConfigurationHandler { #[cfg(feature = "tracing")] fn tracer_listener_remove(&self, id: &str) { - orion_tracing::otel_remove_tracers_by_listeners(&[id.to_compact_string()]) + orion_tracing::otel_remove_tracers_by_listeners(&[id.to_smolstr()]) .unwrap_or_else(|err| warn!("Failed to remove tracer for listener {id}: {err}")); } diff --git a/orion-tracing/Cargo.toml b/orion-tracing/Cargo.toml index d76bdee5..00e6af01 100644 --- a/orion-tracing/Cargo.toml +++ b/orion-tracing/Cargo.toml @@ -16,7 +16,7 @@ bounded-integer.workspace = true tracing.workspace = true tracing-subscriber.workspace = true serde.workspace = true -compact_str.workspace = true +smol_str.workspace = true thiserror.workspace = true http.workspace = true @@ -36,7 +36,6 @@ opentelemetry_sdk = "0.29.0" parking_lot = "0.12.3" thread-id = "5.0.0" arc-swap = "1.7.1" -smol_str = "0.3.2" uuid = { version = "1.18.0", features = ["v4"] } rand = "0.9.2" arrayvec = "0.7.6" diff --git a/orion-tracing/src/lib.rs b/orion-tracing/src/lib.rs index 226818cb..29c282c7 100644 --- a/orion-tracing/src/lib.rs +++ b/orion-tracing/src/lib.rs @@ -35,18 +35,18 @@ use { use std::{collections::HashMap, sync::Arc}; use arc_swap::ArcSwap; -use compact_str::CompactString; use opentelemetry::global::BoxedTracer; use orion_configuration::config::network_filters::tracing::{SupportedTracingProvider, TracingConfig, TracingKey}; use parking_lot::Mutex; +use smol_str::SmolStr; use std::result::Result as StdResult; use thiserror::Error; #[cfg(feature = "tracing")] -use {compact_str::ToCompactString, orion_error::Result}; +use {orion_error::Result, smol_str::ToSmolStr}; #[allow(dead_code)] struct OtelConfig { - service_name: CompactString, + service_name: SmolStr, target_uri: String, } @@ -102,14 +102,14 @@ impl TryFrom<&TracingConfig> for OtelConfig { } #[cfg(feature = "tracing")] -pub fn otel_remove_tracers_by_listeners(listeners: &[CompactString]) -> Result<()> { +pub fn otel_remove_tracers_by_listeners(listeners: &[SmolStr]) -> Result<()> { if !listeners.is_empty() { info!("OTEL Tracers: removing listeners configuration..."); let _lock = GLOBAL_TRACERS.write_lock.lock(); let map_arc = GLOBAL_TRACERS.tracers.load_full(); let mut cur_map = (*map_arc).clone(); info!("Removing tracer for listeners: {listeners:?}"); - cur_map.retain(|&TracingKey(name, _), _| !listeners.contains(&name.to_compact_string())); + cur_map.retain(|&TracingKey(name, _), _| !listeners.contains(&name.to_smolstr())); GLOBAL_TRACERS.tracers.store(Arc::new(cur_map)); info!("OTEL Tracers: removal done."); }