Skip to content

Commit

Permalink
Reorganise modules (#824)
Browse files Browse the repository at this point in the history
While working on adding delta xDS I was finding a lot of our module
organisation to be quite messy and there was clear groupings of
functionality.

This commit doesn't make any functional changes it only changes the
layout of the following modules.

* proxy -> cli::proxy
* utils -> codec::base64 (Loggable trait moved to lib.rs)
* prost -> codec::prost
* protocol -> codec::qcmp
* ttl_map -> collections::ttl
* endpoint -> net::endpoint
* metadata -> net::endpoint::metadata
* xds -> net::xds
* test_utils -> test
  • Loading branch information
XAMPPRocky authored Oct 18, 2023
1 parent 2bc41a5 commit 6e0adc9
Show file tree
Hide file tree
Showing 77 changed files with 487 additions and 491 deletions.
2 changes: 1 addition & 1 deletion agones/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ pub fn gameserver_address(gs: &GameServer) -> String {

// Output the events and logs for each pod that matches this label selector.
// Useful for determining why something is failing in CI without having to run a cluster.
// Requires quilkin::test_utils::enable_log("agones=debug"); to enable debug logging within
// Requires quilkin::test::enable_log("agones=debug"); to enable debug logging within
// the test
pub async fn debug_pods(client: &Client, labels: String) {
debug!(labels, "🪓 Debug output for Selector");
Expand Down
2 changes: 1 addition & 1 deletion agones/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {

use quilkin::{
config::providers::k8s::agones::{Fleet, GameServer},
test_utils::TestHelper,
test::TestHelper,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion agones/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {

use quilkin::{
config::providers::k8s::agones::{Fleet, GameServer},
test_utils::TestHelper,
test::TestHelper,
};

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion agones/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod tests {
use crate::{game_server, is_gameserver_ready, quilkin_config_map, quilkin_container, Client};
use k8s_openapi::api::core::v1::{ConfigMap, ConfigMapVolumeSource, Volume};
use kube::{api::PostParams, runtime::wait::await_condition, Api, ResourceExt};
use quilkin::{config::providers::k8s::agones::GameServer, test_utils::TestHelper};
use quilkin::{config::providers::k8s::agones::GameServer, test::TestHelper};
use std::time::Duration;
use tokio::time::timeout;

Expand Down
6 changes: 3 additions & 3 deletions benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use once_cell::sync::Lazy;
use quilkin::test_utils::AddressType;
use quilkin::test::AddressType;

const MESSAGE_SIZE: usize = 0xffff;
const DEFAULT_MESSAGE: [u8; 0xffff] = [0xff; 0xffff];
Expand All @@ -30,13 +30,13 @@ fn run_quilkin(port: u16, endpoint: SocketAddr) {
let runtime = tokio::runtime::Runtime::new().unwrap();
let config = Arc::new(quilkin::Config::default());
config.clusters.modify(|clusters| {
clusters.insert_default([quilkin::endpoint::Endpoint::new(endpoint.into())].into())
clusters.insert_default([quilkin::net::endpoint::Endpoint::new(endpoint.into())].into())
});

let proxy = quilkin::cli::Proxy {
port,
qcmp_port: runtime
.block_on(quilkin::test_utils::available_addr(&AddressType::Random))
.block_on(quilkin::test::available_addr(&AddressType::Random))
.port(),
..<_>::default()
};
Expand Down
2 changes: 1 addition & 1 deletion docs/src/services/proxy/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ required: [ 'name' ]
[TokenRouter]: ./filters/token_router.md
[Debug]: ./filters/debug.md
[LocalRateLimit]: ./filters/local_rate_limit.md
[`quilkin::metadata::Value`]: ../../../api/quilkin/metadata/enum.Value.html
[`quilkin::metadata::Value`]: ../../../api/quilkin/net/endpoint/metadata/enum.Value.html
2 changes: 1 addition & 1 deletion examples/quilkin-filter-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn main() -> quilkin::Result<()> {
));
config.clusters.modify(|map| {
map.insert_default(
[quilkin::endpoint::Endpoint::new(
[quilkin::net::endpoint::Endpoint::new(
(std::net::Ipv4Addr::LOCALHOST, 4321).into(),
)]
.into(),
Expand Down
18 changes: 9 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Cli {

tracing::info!(
version = crate_version!(),
commit = crate::metadata::build::GIT_COMMIT_HASH,
commit = crate::net::endpoint::metadata::build::GIT_COMMIT_HASH,
"Starting Quilkin"
);

Expand Down Expand Up @@ -289,9 +289,9 @@ mod tests {

use crate::{
config::{Filter, Providers},
endpoint::Endpoint,
filters::{Capture, StaticFilter, TokenRouter},
test_utils::{create_socket, AddressType, TestHelper},
net::endpoint::Endpoint,
test::{create_socket, AddressType, TestHelper},
};

#[tokio::test]
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
config.clusters.write().insert_default(
[Endpoint::with_metadata(
(std::net::Ipv4Addr::LOCALHOST, server_port).into(),
crate::endpoint::Metadata {
crate::net::endpoint::Metadata {
tokens: vec!["abc".into()].into_iter().collect(),
},
)]
Expand All @@ -345,7 +345,7 @@ mod tests {
})
.unwrap();

let relay_admin_port = crate::test_utils::available_addr(&AddressType::Random)
let relay_admin_port = crate::test::available_addr(&AddressType::Random)
.await
.port();
let relay = Cli {
Expand All @@ -362,7 +362,7 @@ mod tests {
log_format: LogFormats::default(),
};

let control_plane_admin_port = crate::test_utils::available_addr(&AddressType::Random)
let control_plane_admin_port = crate::test::available_addr(&AddressType::Random)
.await
.port();
let control_plane = Cli {
Expand All @@ -376,7 +376,7 @@ mod tests {
sub_zone: None,
zone: None,
idle_request_interval_secs: admin::IDLE_REQUEST_INTERVAL_SECS,
qcmp_port: crate::test_utils::available_addr(&AddressType::Random)
qcmp_port: crate::test::available_addr(&AddressType::Random)
.await
.port(),
provider: Some(Providers::File {
Expand All @@ -386,7 +386,7 @@ mod tests {
log_format: LogFormats::default(),
};

let proxy_admin_port = crate::test_utils::available_addr(&AddressType::Random)
let proxy_admin_port = crate::test::available_addr(&AddressType::Random)
.await
.port();
let proxy = Cli {
Expand Down Expand Up @@ -419,7 +419,7 @@ mod tests {
config.clusters.write().insert_default(
[Endpoint::with_metadata(
(std::net::Ipv6Addr::LOCALHOST, server_port).into(),
crate::endpoint::Metadata {
crate::net::endpoint::Metadata {
tokens: vec![token.clone()].into_iter().collect(),
},
)]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn collect_metrics() -> Response<Body> {
#[cfg(test)]
mod tests {
use super::*;
use crate::endpoint::Endpoint;
use crate::net::endpoint::Endpoint;

#[tokio::test]
async fn collect_metrics() {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Agent {
mut shutdown_rx: tokio::sync::watch::Receiver<()>,
) -> crate::Result<()> {
let locality = (self.region.is_some() || self.zone.is_some() || self.sub_zone.is_some())
.then(|| crate::endpoint::Locality {
.then(|| crate::net::endpoint::Locality {
region: self.region.clone().unwrap_or_default(),
zone: self.zone.clone().unwrap_or_default(),
sub_zone: self.sub_zone.clone().unwrap_or_default(),
Expand All @@ -97,7 +97,7 @@ impl Agent {
None => return Err(eyre::eyre!("no configuration provider given")),
};

let task = crate::xds::client::MdsClient::connect(
let task = crate::net::xds::client::MdsClient::connect(
String::clone(&config.id.load()),
mode.clone(),
self.relay.clone(),
Expand All @@ -112,7 +112,7 @@ impl Agent {
None
};

crate::protocol::spawn(self.qcmp_port).await?;
crate::codec::qcmp::spawn(self.qcmp_port).await?;
shutdown_rx.changed().await.map_err(From::from)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Manage {
mut shutdown_rx: tokio::sync::watch::Receiver<()>,
) -> crate::Result<()> {
let locality = (self.region.is_some() || self.zone.is_some() || self.sub_zone.is_some())
.then(|| crate::endpoint::Locality {
.then(|| crate::net::endpoint::Locality {
region: self.region.clone().unwrap_or_default(),
zone: self.zone.clone().unwrap_or_default(),
sub_zone: self.sub_zone.clone().unwrap_or_default(),
Expand All @@ -81,7 +81,7 @@ impl Manage {

let _relay_stream = if !self.relay.is_empty() {
tracing::info!("connecting to relay server");
let client = crate::xds::client::MdsClient::connect(
let client = crate::net::xds::client::MdsClient::connect(
String::clone(&config.id.load()),
mode.clone(),
self.relay.clone(),
Expand All @@ -92,7 +92,7 @@ impl Manage {
None
};

let server_task = tokio::spawn(crate::xds::server::spawn(self.port, config))
let server_task = tokio::spawn(crate::net::xds::server::spawn(self.port, config))
.map_err(From::from)
.and_then(std::future::ready);

Expand Down
Loading

0 comments on commit 6e0adc9

Please sign in to comment.