Skip to content

Commit

Permalink
Move cluster into net
Browse files Browse the repository at this point in the history
This commit moves the cluster module inside net to match endpoint. There
are no functional changes.
  • Loading branch information
XAMPPRocky committed Nov 1, 2023
1 parent e99a276 commit 9ca045a
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::{
cluster::ClusterMap,
filters::prelude::*,
net::cluster::ClusterMap,
net::xds::{
config::listener::v3::Listener, service::discovery::v3::DiscoveryResponse, Resource,
ResourceType,
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Config {
if names.is_empty() {
for cluster in self.clusters.read().iter() {
resources.push(resource_type.encode_to_any(
&crate::cluster::proto::Cluster::try_from((
&crate::net::cluster::proto::Cluster::try_from((
cluster.key(),
cluster.value(),
))?,
Expand All @@ -135,7 +135,7 @@ impl Config {
for locality in names.iter().filter_map(|name| name.parse().ok()) {
if let Some(cluster) = self.clusters.read().get(&Some(locality)) {
resources.push(resource_type.encode_to_any(
&crate::cluster::proto::Cluster::try_from((
&crate::net::cluster::proto::Cluster::try_from((
cluster.key(),
cluster.value(),
))?,
Expand Down Expand Up @@ -189,8 +189,8 @@ impl Config {

pub fn apply_metrics(&self) {
let clusters = self.clusters.read();
crate::cluster::active_clusters().set(clusters.len() as i64);
crate::cluster::active_endpoints().set(clusters.endpoints().count() as i64);
crate::net::cluster::active_clusters().set(clusters.len() as i64);
crate::net::cluster::active_endpoints().set(clusters.endpoints().count() as i64);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub(crate) mod collections;
pub(crate) mod metrics;

pub mod cli;
pub mod cluster;
pub mod codec;
pub mod config;
pub mod filters;
Expand Down
6 changes: 5 additions & 1 deletion src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

pub mod cluster;
pub mod endpoint;
pub(crate) mod maxmind_db;
pub(crate) mod xds;
Expand All @@ -26,7 +27,10 @@ use std::{
use socket2::{Protocol, Socket, Type};
use tokio::{net::ToSocketAddrs, net::UdpSocket};

pub use endpoint::{Endpoint, EndpointAddress};
pub use self::{
cluster::ClusterMap,
endpoint::{Endpoint, EndpointAddress},
};

/// returns a UdpSocket with address and port reuse, on Ipv6Addr::UNSPECIFIED
fn socket_with_reuse(port: u16) -> std::io::Result<UdpSocket> {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/net/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl std::str::FromStr for Endpoint {
}
}

impl From<Endpoint> for crate::cluster::proto::Endpoint {
impl From<Endpoint> for crate::net::cluster::proto::Endpoint {
fn from(endpoint: Endpoint) -> Self {
Self {
host: endpoint.address.host.to_string(),
Expand All @@ -86,10 +86,10 @@ impl From<Endpoint> for crate::cluster::proto::Endpoint {
}
}

impl TryFrom<crate::cluster::proto::Endpoint> for Endpoint {
impl TryFrom<crate::net::cluster::proto::Endpoint> for Endpoint {
type Error = eyre::Error;

fn try_from(endpoint: crate::cluster::proto::Endpoint) -> Result<Self, Self::Error> {
fn try_from(endpoint: crate::net::cluster::proto::Endpoint) -> Result<Self, Self::Error> {
let host: address::AddressKind = endpoint.host.parse()?;
if endpoint.port > u16::MAX as u32 {
return Err(eyre::eyre!("invalid endpoint port"));
Expand Down
6 changes: 3 additions & 3 deletions src/net/endpoint/locality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl std::str::FromStr for Locality {
}
}

impl From<crate::cluster::proto::Locality> for Locality {
fn from(value: crate::cluster::proto::Locality) -> Self {
impl From<crate::net::cluster::proto::Locality> for Locality {
fn from(value: crate::net::cluster::proto::Locality) -> Self {
Self {
region: value.region,
zone: value.zone,
Expand All @@ -131,7 +131,7 @@ impl From<crate::cluster::proto::Locality> for Locality {
}
}

impl From<Locality> for crate::cluster::proto::Locality {
impl From<Locality> for crate::net::cluster::proto::Locality {
fn from(value: Locality) -> Self {
Self {
region: value.region,
Expand Down
2 changes: 1 addition & 1 deletion src/net/xds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {
crate::test::map_to_localhost(&mut addr.address).await;
addr
};
let clusters = crate::cluster::ClusterMap::default();
let clusters = crate::net::cluster::ClusterMap::default();

tracing::debug!(?address);
clusters.insert_default([address].into());
Expand Down
2 changes: 1 addition & 1 deletion src/net/xds/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type_urls! {

#[derive(Clone, Debug)]
pub enum Resource {
Cluster(Box<crate::cluster::proto::Cluster>),
Cluster(Box<crate::net::cluster::proto::Cluster>),
Listener(Box<Listener>),
}

Expand Down

0 comments on commit 9ca045a

Please sign in to comment.