diff --git a/Cargo.lock b/Cargo.lock index 8226b6a71b..ee5554877a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,9 +1688,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libflate" @@ -2164,10 +2164,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] -name = "pprof" +name = "pprof2" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5c97c51bd34c7e742402e216abdeb44d415fbe6ae41d56b114723e953711cb" +checksum = "3ef2b298bd8930da969971e9a884346161b263ee7530acbe1b1436d5588953fe" dependencies = [ "backtrace", "cfg-if", @@ -2371,7 +2371,7 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot", - "pprof", + "pprof2", "pretty_assertions", "prometheus", "prost", @@ -3067,9 +3067,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "symbolic-common" -version = "12.10.0" +version = "12.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16629323a4ec5268ad23a575110a724ad4544aae623451de600c747bf87b36cf" +checksum = "366f1b4c6baf6cfefc234bbd4899535fca0b06c74443039a73f6dfb2fad88d77" dependencies = [ "debugid", "memmap2", @@ -3079,9 +3079,9 @@ dependencies = [ [[package]] name = "symbolic-demangle" -version = "12.10.0" +version = "12.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c043a45f08f41187414592b3ceb53fb0687da57209cc77401767fb69d5b596" +checksum = "aba05ba5b9962ea5617baf556293720a8b2d0a282aa14ee4bf10e22efc7da8c8" dependencies = [ "cpp_demangle", "rustc-demangle", diff --git a/Cargo.toml b/Cargo.toml index c3b0b35032..532dd400c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,7 +160,7 @@ io-uring = { version = "0.6", default-features = false } libc = "0.2" slab = "0.4" sys-info = "0.9.1" -pprof = { version = "0.13.0", features = ["prost", "prost-codec"] } +pprof = { version = "0.13.0", features = ["prost", "prost-codec"], package = "pprof2" } [dev-dependencies] divan = "0.1.2" diff --git a/benches/cluster_map.rs b/benches/cluster_map.rs index 8234d4373f..6a8b33baed 100644 --- a/benches/cluster_map.rs +++ b/benches/cluster_map.rs @@ -1,7 +1,7 @@ -#![cfg(target_pointer_width = "99")] +#![cfg(target_pointer_width = "64")] use divan::Bencher; -use quilkin::net::cluster::ClusterMap; +use quilkin::{net::cluster::ClusterMap, xds::Resource}; mod shared; @@ -16,21 +16,20 @@ mod serde { fn serialize_to_protobuf(cm: &ClusterMap) -> Vec { let mut resources = Vec::new(); - let resource_type = quilkin::net::xds::ResourceType::Cluster; for cluster in cm.iter() { resources.push( - resource_type - .encode_to_any(&Cluster { - locality: cluster.key().clone().map(From::from), - endpoints: cluster - .endpoints - .iter() - .map(TryFrom::try_from) - .collect::>() - .unwrap(), - }) - .unwrap(), + Resource::Cluster(Cluster { + locality: cluster.key().clone().map(From::from), + endpoints: cluster + .endpoints + .iter() + .map(TryFrom::try_from) + .collect::>() + .unwrap(), + }) + .try_encode() + .unwrap(), ); } @@ -41,9 +40,9 @@ mod serde { let cm = ClusterMap::default(); for any in pv { - let c = quilkin::net::xds::Resource::try_from(any).unwrap(); + let c = quilkin::xds::Resource::try_decode(any).unwrap(); - let quilkin::net::xds::Resource::Cluster(cluster) = c else { + let quilkin::xds::Resource::Cluster(cluster) = c else { unreachable!() }; cm.insert( diff --git a/benches/misc.rs b/benches/misc.rs index 1bcce3bc98..aec839e7f2 100644 --- a/benches/misc.rs +++ b/benches/misc.rs @@ -1,8 +1,10 @@ -#![cfg(target_pointer_width = "99")] +#![cfg(target_pointer_width = "64")] use divan::Bencher; use prost_types::{value::Kind, Value}; -use quilkin::net::cluster::proto::Endpoint as ProtoEndpoint; +use rand::SeedableRng; + +use quilkin::{net::cluster::proto::Endpoint as ProtoEndpoint, xds::Resource}; mod shared; @@ -146,16 +148,13 @@ trait GenResource: Default { fn generate(&mut self, slim: bool) -> prost_types::Any; } -use quilkin::net::xds::{Resource, ResourceType}; -use rand::SeedableRng; - #[derive(Default)] struct Listener { _counter: usize, } impl GenResource for Listener { - fn generate(&mut self, slim: bool) -> prost_types::Any { + fn generate(&mut self, _slim: bool) -> prost_types::Any { use quilkin::filters::{self, StaticFilter}; let filters = [ quilkin::config::Filter { @@ -186,32 +185,17 @@ impl GenResource for Listener { }, ]; - if slim { - ResourceType::FilterChain.encode_to_any(&quilkin::net::cluster::proto::FilterChain { - filters: filters - .into_iter() - .map(|f| quilkin::net::cluster::proto::Filter { - name: f.name, - label: f.label, - config: f.config.map(|c| c.to_string()), - }) - .collect(), - }) - } else { - ResourceType::Listener.encode_to_any(&quilkin::net::xds::listener::Listener { - filter_chains: vec![ - quilkin::generated::envoy::config::listener::v3::FilterChain { - filters: filters - .into_iter() - .map(TryFrom::try_from) - .collect::>() - .unwrap(), - ..Default::default() - }, - ], - ..Default::default() - }) - } + Resource::FilterChain(quilkin::net::cluster::proto::FilterChain { + filters: filters + .into_iter() + .map(|f| quilkin::net::cluster::proto::Filter { + name: f.name, + label: f.label, + config: f.config.map(|c| c.to_string()), + }) + .collect(), + }) + .try_encode() .unwrap() } } @@ -242,28 +226,25 @@ impl GenResource for Cluster { .collect(), }; - ResourceType::Cluster.encode_to_any(&msg).unwrap() + Resource::Cluster(msg).try_encode().unwrap() } } // From Config::apply fn deserialize(a: prost_types::Any) { - match Resource::try_from(a).unwrap() { - Resource::Listener(mut listener) => { - let chain: quilkin::filters::FilterChain = if listener.filter_chains.is_empty() { + match Resource::try_decode(a).unwrap() { + Resource::Listener(_) => { + todo!() + } + Resource::FilterChain(fc) => { + let chain: quilkin::filters::FilterChain = if fc.filters.is_empty() { Default::default() } else { - quilkin::filters::FilterChain::try_create_fallible( - listener.filter_chains.swap_remove(0).filters, - ) - .unwrap() + quilkin::filters::FilterChain::try_create_fallible(fc.filters).unwrap() }; drop(chain); } - Resource::FilterChain(_fc) => { - unimplemented!("should not be used") - } Resource::Datacenter(dc) => { let _host: std::net::IpAddr = dc.host.parse().unwrap(); let _dc = quilkin::config::Datacenter { @@ -285,9 +266,9 @@ fn deserialize(a: prost_types::Any) { } fn deserialize_faster(a: prost_types::Any) { - match Resource::try_from(a).unwrap() { - Resource::Listener(_listener) => { - unimplemented!("should not be used"); + match Resource::try_decode(a).unwrap() { + Resource::Listener(_) => { + unimplemented!() } Resource::FilterChain(fc) => { quilkin::filters::FilterChain::try_create_fallible(fc.filters).unwrap(); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 87e2b06ba8..460612ae6e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -13,5 +13,5 @@ # limitations under the License. [toolchain] -channel = "1.77.1" +channel = "1.81.0" components = ["rustfmt", "clippy"] diff --git a/src/config/providers/k8s/agones.rs b/src/config/providers/k8s/agones.rs index 8c96112e75..6d69af1f23 100644 --- a/src/config/providers/k8s/agones.rs +++ b/src/config/providers/k8s/agones.rs @@ -639,11 +639,7 @@ impl ::kube::core::crd::v1::CustomResourceExt for Fleet { > = ::serde_json::from_str("[ ]").expect("valid printer column json"); let scale: Option< ::k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresourceScale, - > = if "".is_empty() { - None - } else { - ::serde_json::from_str("").expect("valid scale subresource json") - }; + > = None; let categories: Vec = ::serde_json::from_str("[]").expect("valid categories"); let shorts: Vec = ::serde_json::from_str("[]").expect("valid shortnames"); let subres = if true { diff --git a/src/filters/factory.rs b/src/filters/factory.rs index 0f5a3fbca0..f4f8ee6d1f 100644 --- a/src/filters/factory.rs +++ b/src/filters/factory.rs @@ -72,6 +72,7 @@ pub trait FilterFactory: Sync + Send { /// - `module`: The rust module name containing the filter item /// - `version`: The filter's version. /// - `item-name`: The name of the rust item (e.g enum, struct) implementing the filter. + /// /// For example the `v1alpha1` version of the debug filter has the name: /// `quilkin.filters.debug_filter.v1alpha1.Debug` fn name(&self) -> &'static str; diff --git a/src/filters/local_rate_limit.rs b/src/filters/local_rate_limit.rs index e3d596a0dc..05087c70d8 100644 --- a/src/filters/local_rate_limit.rs +++ b/src/filters/local_rate_limit.rs @@ -39,6 +39,7 @@ const SESSION_EXPIRY_POLL_INTERVAL: Duration = Duration::from_secs(60); /// - A counter that tracks how many packets we've processed within a time window. /// - A timestamp that stores the time we last reset the counter. It tracks /// the start of the time window. +/// /// This allows us to have a simpler implementation for calculating token /// exhaustion without needing a write lock in the common case. The downside /// however is that since we're relying on two independent atomics, there is diff --git a/src/metrics.rs b/src/metrics.rs index 66edead875..75019a8a66 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -165,7 +165,7 @@ pub(crate) fn bytes_total(direction: Direction, asn: &AsnInfo) -> IntCounter { .unwrap() }); - BYTES_TOTAL.with_label_values(&[direction.label(), asn.asn_str(), &asn.prefix]) + BYTES_TOTAL.with_label_values(&[direction.label(), asn.asn_str(), asn.prefix]) } pub(crate) fn errors_total(direction: Direction, display: &str, asn: &AsnInfo) -> IntCounter { @@ -181,7 +181,7 @@ pub(crate) fn errors_total(direction: Direction, display: &str, asn: &AsnInfo) - .unwrap() }); - ERRORS_TOTAL.with_label_values(&[direction.label(), display, asn.asn_str(), &asn.prefix]) + ERRORS_TOTAL.with_label_values(&[direction.label(), display, asn.asn_str(), asn.prefix]) } pub(crate) fn packet_jitter(direction: Direction, asn: &AsnInfo) -> IntGauge { @@ -197,7 +197,7 @@ pub(crate) fn packet_jitter(direction: Direction, asn: &AsnInfo) -> IntGauge { .unwrap() }); - PACKET_JITTER.with_label_values(&[direction.label(), asn.asn_str(), &asn.prefix]) + PACKET_JITTER.with_label_values(&[direction.label(), asn.asn_str(), asn.prefix]) } pub(crate) fn packets_total(direction: Direction, asn: &AsnInfo) -> IntCounter { @@ -213,7 +213,7 @@ pub(crate) fn packets_total(direction: Direction, asn: &AsnInfo) -> IntCounter { .unwrap() }); - PACKETS_TOTAL.with_label_values(&[direction.label(), asn.asn_str(), &asn.prefix]) + PACKETS_TOTAL.with_label_values(&[direction.label(), asn.asn_str(), asn.prefix]) } pub(crate) fn packets_dropped_total( @@ -233,7 +233,7 @@ pub(crate) fn packets_dropped_total( .unwrap() }); - PACKETS_DROPPED.with_label_values(&[direction.label(), source, asn.asn_str(), &asn.prefix]) + PACKETS_DROPPED.with_label_values(&[direction.label(), source, asn.asn_str(), asn.prefix]) } /// Create a generic metrics options.