Skip to content

Commit

Permalink
Update to Rust 1.81.0 (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Oct 11, 2024
1 parent ad5cf87 commit a17f38f
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 83 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 15 additions & 16 deletions benches/cluster_map.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,21 +16,20 @@ mod serde {

fn serialize_to_protobuf(cm: &ClusterMap) -> Vec<Any> {
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::<Result<_, _>>()
.unwrap(),
})
.unwrap(),
Resource::Cluster(Cluster {
locality: cluster.key().clone().map(From::from),
endpoints: cluster
.endpoints
.iter()
.map(TryFrom::try_from)
.collect::<Result<_, _>>()
.unwrap(),
})
.try_encode()
.unwrap(),
);
}

Expand All @@ -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(
Expand Down
73 changes: 27 additions & 46 deletions benches/misc.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Result<_, quilkin::filters::CreationError>>()
.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()
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.

[toolchain]
channel = "1.77.1"
channel = "1.81.0"
components = ["rustfmt", "clippy"]
6 changes: 1 addition & 5 deletions src/config/providers/k8s/agones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = ::serde_json::from_str("[]").expect("valid categories");
let shorts: Vec<String> = ::serde_json::from_str("[]").expect("valid shortnames");
let subres = if true {
Expand Down
1 change: 1 addition & 0 deletions src/filters/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/filters/local_rate_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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(
Expand All @@ -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.
Expand Down

0 comments on commit a17f38f

Please sign in to comment.