Skip to content

Commit

Permalink
rename "application" to "cluster" for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Aug 8, 2022
1 parent c5ad6db commit 4ccd277
Show file tree
Hide file tree
Showing 45 changed files with 500 additions and 501 deletions.
2 changes: 1 addition & 1 deletion bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ receives configuration commands through anonymous unix sockets.

This executable requires a configuration file in the TOML format, that describes
the worker types and numbers, along with global information. This file can
describe the applications handled by the proxy, but it is more recommended to
describe the clusters handled by the proxy, but it is more recommended to
use the command unix socket, through which the proxy listens for orders or
configuration changes. The path of that unix socket is set in the configuration
file.
Expand Down
29 changes: 15 additions & 14 deletions bin/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ address = "0.0.0.0:8080"
#answer_503 = "../lib/assets/503.html"

# defines the sticky session cookie's name, if `sticky_session` is activated for
# an application. Defaults to "SOZUBALANCEID"
# a cluster. Defaults to "SOZUBALANCEID"
# sticky_name = "SOZUBALANCEID"
#
# Configures the client socket to receive a PROXY protocol header
Expand Down Expand Up @@ -219,34 +219,35 @@ tls_versions = ["TLSv1.3"]
# this option is incompatible with public_address
# expect_proxy = false

# static configuration for applications
# static configuration for cluster
#
# those applications will be routed by sozu directly from start
[applications]
# A cluster is a set of frontends, routing rules, and backends.
# These clusters will be routed by sozu directly from start
[clusters]

# every application has an "application id", here it is "MyApp"
# every cluster has a "cluster id", here it is "MyCluster"
# this is an example of a routing configuration for the HTTP and HTTPS proxies
[applications.MyApp]
[clusters.MyCluster]

# the protocol option indicates if we will use HTTP or TCP proxying
# possible options are "http" or "tcp"
protocol = "http"

# per application load balancing algorithm. The possible values are
# per cluster load balancing algorithm. The possible values are
# "round_robin", "random", "least_loaded" and "power_of_two". Defaults to "round_robin"
load_balancing = "round_robin"
# metric evaluating the load on the backend. available options: connections, requests, connection_time
# load_metric = "connections"

# frontends configuration
# this specifies which listeners; domains, certificates that will be configured for an application
# this specifies which listeners; domains, certificates that will be configured for a cluster
# each element of the array must be specified on one line (toml format limitation)
# possible frontend options:
# - address: TCP listener
# - hostname: host name of the application
# - path_begin = "/api" # optional. an application can receive requests going to a hostname and path prefix
# - sticky_session = false # activates sticky sessions for this application
# - https_redirect = false # activates automatic redirection to HTTPS for this application
# - hostname: host name of the cluster
# - path_begin = "/api" # optional. a cluster can receive requests going to a hostname and path prefix
# - sticky_session = false # activates sticky sessions for this cluster
# - https_redirect = false # activates automatic redirection to HTTPS for this cluster
# - custom_tag: a tag to retrieve a frontend with the CLI or in the logs
frontends = [
{ address = "0.0.0.0:8080", hostname = "lolcatho.st", tags = { key = "value" } },
Expand All @@ -255,7 +256,7 @@ frontends = [
]

# backends configuration
# this indicates the backend servers used by the application
# this indicates the backend servers used by the cluster
# possible options:
# - address: IP and port of the backend server
# - weight: weight used by the load balancing algorithm
Expand All @@ -265,7 +266,7 @@ backends = [
]

# this is an example of a routing configuration for the TCP proxy
[applications.TcpTest]
[clusters.TcpTest]
protocol = "tcp"

frontends = [
Expand Down
49 changes: 24 additions & 25 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub enum SubCmd {
},
#[clap(
name = "reload",
about = "Reloads routing configuration (applications, frontends and backends)"
about = "Reloads routing configuration (clusters, frontends and backends)"
)]
Reload {
#[clap(
Expand All @@ -148,10 +148,10 @@ pub enum SubCmd {
)]
json: bool,
},
#[clap(name = "application", about = "application management")]
Application {
#[clap(name = "cluster", about = "cluster management")]
Cluster {
#[clap(subcommand)]
cmd: ApplicationCmd,
cmd: ClusterCmd,
},
#[clap(name = "backend", about = "backend management")]
Backend {
Expand Down Expand Up @@ -255,15 +255,15 @@ pub enum StateCmd {
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
pub enum ApplicationCmd {
#[clap(name = "remove", about = "Remove an application")]
pub enum ClusterCmd {
#[clap(name = "remove", about = "Remove a cluster")]
Remove {
#[clap(short = 'i', long = "id")]
#[clap(short = 'i', long = "id", help = "cluster id")]
id: String,
},
#[clap(name = "add", about = "Add an application")]
#[clap(name = "add", about = "Add a cluster")]
Add {
#[clap(short = 'i', long = "id")]
#[clap(short = 'i', long = "id", help = "cluster id")]
id: String,
#[clap(short = 's', long = "sticky-session")]
sticky_session: bool,
Expand Down Expand Up @@ -361,9 +361,9 @@ pub enum FrontendCmd {

#[derive(Subcommand, PartialEq, Clone, Debug)]
pub enum Route {
/// traffic will go to the backend servers with this application id
/// traffic will go to the backend servers with this cluster id
Id {
/// traffic will go to the backend servers with this application id
/// traffic will go to the backend servers with this cluster id
id: String,
},
/// traffic to this frontend will be rejected with HTTP 401
Expand Down Expand Up @@ -423,20 +423,24 @@ pub enum HttpFrontendCmd {
pub enum TcpFrontendCmd {
#[clap(name = "add")]
Add {
#[clap(short = 'i', long = "id", help = "app id of the frontend")]
#[clap(short = 'i', long = "id", help = "the id of the cluster to which the frontend belongs")]
id: String,
#[clap(
short = 'a',
long = "address",
help = "frontend address, format: IP:port"
)]
address: SocketAddr,
#[clap(long = "tags", help = "Specify tag (key-value pair) to apply on front-end (example: 'key=value, other-key=other-value')", parse(try_from_str = parse_tags))]
#[clap(
long = "tags",
help = "Specify tag (key-value pair) to apply on front-end (example: 'key=value, other-key=other-value')",
parse(try_from_str = parse_tags)
)]
tags: Option<BTreeMap<String, String>>,
},
#[clap(name = "remove")]
Remove {
#[clap(short = 'i', long = "id", help = "app id of the frontend")]
#[clap(short = 'i', long = "id", help = "the id of the cluster to which the frontend belongs")]
id: String,
#[clap(
short = 'a',
Expand Down Expand Up @@ -484,7 +488,7 @@ pub enum HttpListenerCmd {
answer_404: Option<String>,
#[clap(
long = "answer-503",
help = "path to file of the 503 answer sent to the client when an application has no backends available"
help = "path to file of the 503 answer sent to the client when a cluster has no backends available"
)]
answer_503: Option<String>,
#[clap(
Expand Down Expand Up @@ -542,7 +546,7 @@ pub enum HttpsListenerCmd {
answer_404: Option<String>,
#[clap(
long = "answer-503",
help = "path to file of the 503 answer sent to the client when an application has no backends available"
help = "path to file of the 503 answer sent to the client when a cluster has no backends available"
)]
answer_503: Option<String>,
#[clap(long = "tls-versions", help = "list of TLS versions to use")]
Expand Down Expand Up @@ -708,17 +712,13 @@ pub enum CertificateCmd {

#[derive(Subcommand, PartialEq, Clone, Debug)]
pub enum QueryCmd {
#[clap(
name = "applications",
about = "Query applications matching a specific filter"
)]
Applications {
#[clap(short = 'i', long = "id", help = "application identifier")]
#[clap(name = "clusters", about = "Query clusters matching a specific filter")]
Clusters {
#[clap(short = 'i', long = "id", help = "cluster identifier")]
id: Option<String>,
#[clap(short = 'd', long = "domain", help = "application domain name")]
#[clap(short = 'd', long = "domain", help = "cluster domain name")]
domain: Option<String>,
},

#[clap(
name = "certificates",
about = "Query certificates matching a specific filter"
Expand All @@ -729,7 +729,6 @@ pub enum QueryCmd {
#[clap(short = 'd', long = "domain", help = "domain name")]
domain: Option<String>,
},

#[clap(name = "metrics", about = "Query metrics matching a specific filter")]
Metrics {
#[clap(short, long, help = "list available metrics")]
Expand Down
4 changes: 2 additions & 2 deletions bin/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl CommandServer {
Ok(())
}

pub async fn load_static_application_configuration(&mut self) {
pub async fn load_static_cluster_configuration(&mut self) {
let (tx, mut rx) = futures::channel::mpsc::channel(self.workers.len() * 2);

let mut total_message_count = 0usize;
Expand Down Expand Up @@ -890,7 +890,7 @@ pub fn start_server(
let saved_state_path = config.saved_state.clone();

let mut server = CommandServer::new(fd, config, tx, command_rx, workers, accept_cancel_tx)?;
server.load_static_application_configuration().await;
server.load_static_cluster_configuration().await;

if let Some(path) = saved_state_path {
server
Expand Down
24 changes: 12 additions & 12 deletions bin/src/command/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use sozu_command_lib::{
parser::parse_several_commands,
proxy::{
MetricsConfiguration, ProxyRequest, ProxyRequestData, ProxyResponseData,
ProxyResponseStatus, Query, QueryAnswer, QueryApplicationType, Route, TcpFrontend,
ProxyResponseStatus, Query, QueryAnswer, QueryClusterType, Route, TcpFrontend,
},
scm_socket::Listeners,
state::get_application_ids_by_domain,
state::get_cluster_ids_by_domain,
};

use crate::{
Expand Down Expand Up @@ -942,23 +942,23 @@ impl CommandServer {

let mut main_query_answer = None;
match &query {
&Query::ApplicationsHashes => {
main_query_answer = Some(QueryAnswer::ApplicationsHashes(self.state.hash_state()));
&Query::ClustersHashes => {
main_query_answer = Some(QueryAnswer::ClustersHashes(self.state.hash_state()));
}
&Query::Applications(ref query_type) => {
main_query_answer = Some(QueryAnswer::Applications(match query_type {
QueryApplicationType::ClusterId(ref cluster_id) => {
vec![self.state.application_state(cluster_id)]
&Query::Clusters(ref query_type) => {
main_query_answer = Some(QueryAnswer::Clusters(match query_type {
QueryClusterType::ClusterId(ref cluster_id) => {
vec![self.state.cluster_state(cluster_id)]
}
QueryApplicationType::Domain(ref domain) => {
let cluster_ids = get_application_ids_by_domain(
QueryClusterType::Domain(ref domain) => {
let cluster_ids = get_cluster_ids_by_domain(
&self.state,
domain.hostname.clone(),
domain.path.clone(),
);
cluster_ids
.iter()
.map(|ref cluster_id| self.state.application_state(cluster_id))
.map(|ref cluster_id| self.state.cluster_state(cluster_id))
.collect()
}
}));
Expand Down Expand Up @@ -1008,7 +1008,7 @@ impl CommandServer {
.collect();

let success = match &query {
&Query::ApplicationsHashes | &Query::Applications(_) => {
&Query::ClustersHashes | &Query::Clusters(_) => {
let main = main_query_answer.unwrap();
query_answers_map.insert(String::from("main"), main);
Success::Query(CommandResponseData::Query(query_answers_map))
Expand Down
42 changes: 21 additions & 21 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use sozu_command_lib::{
FrontendFilters, RunState, WorkerInfo,
},
proxy::{
MetricsConfiguration, ProxyRequestData, Query, QueryApplicationDomain,
QueryApplicationType, QueryCertificateType, QueryMetricsType,
MetricsConfiguration, ProxyRequestData, Query, QueryClusterDomain,
QueryClusterType, QueryCertificateType, QueryMetricsType,
},
};

Expand Down Expand Up @@ -658,19 +658,19 @@ impl CommandManager {
Ok(())
}

pub fn query_application(
pub fn query_cluster(
&mut self,
json: bool,
application_id: Option<String>,
cluster_id: Option<String>,
domain: Option<String>,
) -> Result<(), anyhow::Error> {
if application_id.is_some() && domain.is_some() {
bail!("Error: Either request an application ID or a domain name");
if cluster_id.is_some() && domain.is_some() {
bail!("Error: Either request an cluster ID or a domain name");
}

let command = if let Some(ref cluster_id) = application_id {
CommandRequestData::Proxy(ProxyRequestData::Query(Query::Applications(
QueryApplicationType::ClusterId(cluster_id.to_string()),
let command = if let Some(ref cluster_id) = cluster_id {
CommandRequestData::Proxy(ProxyRequestData::Query(Query::Clusters(
QueryClusterType::ClusterId(cluster_id.to_string()),
)))
} else if let Some(ref domain) = domain {
let splitted: Vec<String> =
Expand All @@ -680,19 +680,19 @@ impl CommandManager {
bail!("Domain can't be empty");
}

let query_domain = QueryApplicationDomain {
let query_domain = QueryClusterDomain {
hostname: splitted
.get(0)
.with_context(|| "Domain can't be empty")?
.clone(),
path: splitted.get(1).cloned().map(|path| format!("/{}", path)), // We add the / again because of the splitn removing it
};

CommandRequestData::Proxy(ProxyRequestData::Query(Query::Applications(
QueryApplicationType::Domain(query_domain),
CommandRequestData::Proxy(ProxyRequestData::Query(Query::Clusters(
QueryClusterType::Domain(query_domain),
)))
} else {
CommandRequestData::Proxy(ProxyRequestData::Query(Query::ApplicationsHashes))
CommandRequestData::Proxy(ProxyRequestData::Query(Query::ClustersHashes))
};

let id = generate_id();
Expand Down Expand Up @@ -720,7 +720,7 @@ impl CommandManager {
bail!("could not query proxy state: {}", message.message);
}
CommandStatus::Ok => {
print_query_response_data(application_id, domain, message.data, json)?;
print_query_response_data(cluster_id, domain, message.data, json)?;
}
}

Expand Down Expand Up @@ -790,18 +790,18 @@ impl CommandManager {
list: bool,
refresh: Option<u32>,
names: Vec<String>,
clusters: Vec<String>,
backends: Vec<(String, String)>,
cluster_ids: Vec<String>,
backends: Vec<(String, String)>, // (cluster_id, backend_id)
) -> Result<(), anyhow::Error> {
let query = if list {
QueryMetricsType::List
} else if !clusters.is_empty() && !backends.is_empty() {
} else if !cluster_ids.is_empty() && !backends.is_empty() {
bail!("Error: Either request a list of clusters or a list of backends");
} else {
if !clusters.is_empty() {
if !cluster_ids.is_empty() {
QueryMetricsType::Cluster {
metrics: names,
clusters,
cluster_ids,
date: None,
}
} else {
Expand Down Expand Up @@ -913,8 +913,8 @@ impl CommandManager {
//deactivate success messages for now
/*
match order {
ProxyRequestData::AddCluster(_) => println!("application added : {}", message.message),
ProxyRequestData::RemoveCluster(_) => println!("application removed : {} ", message.message),
ProxyRequestData::AddCluster(_) => println!("cluster added : {}", message.message),
ProxyRequestData::RemoveCluster(_) => println!("cluster removed : {} ", message.message),
ProxyRequestData::AddBackend(_) => println!("backend added : {}", message.message),
ProxyRequestData::RemoveBackend(_) => println!("backend removed : {} ", message.message),
ProxyRequestData::AddCertificate(_) => println!("certificate added: {}", message.message),
Expand Down

0 comments on commit 4ccd277

Please sign in to comment.