|
|
|
@ -64,12 +64,8 @@ pub struct ProxyEntry { |
|
|
|
|
/// Is the target serving HTTPS instead of HTTP?
|
|
|
|
|
pub https_target: bool, |
|
|
|
|
|
|
|
|
|
/// Is the target the same node as we are running on?
|
|
|
|
|
/// (if yes priorize it over other matching targets)
|
|
|
|
|
pub same_node: bool, |
|
|
|
|
/// Is the target the same site as this node?
|
|
|
|
|
/// (if yes priorize it over other matching targets)
|
|
|
|
|
pub same_site: bool, |
|
|
|
|
/// Flags for target selection
|
|
|
|
|
pub flags: ProxyEntryFlags, |
|
|
|
|
|
|
|
|
|
/// Add the following headers to all responses returned
|
|
|
|
|
/// when matching this rule
|
|
|
|
@ -81,6 +77,21 @@ pub struct ProxyEntry { |
|
|
|
|
pub last_call: atomic::AtomicI64, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
|
pub struct ProxyEntryFlags { |
|
|
|
|
/// Is the target the same node as we are running on?
|
|
|
|
|
/// (if yes priorize it over other matching targets)
|
|
|
|
|
pub same_node: bool, |
|
|
|
|
/// Is the target the same site as this node?
|
|
|
|
|
/// (if yes priorize it over other matching targets)
|
|
|
|
|
pub same_site: bool, |
|
|
|
|
|
|
|
|
|
/// Is site-wide load balancing enabled for this service?
|
|
|
|
|
pub site_lb: bool, |
|
|
|
|
/// Is global load balancing enabled for this service?
|
|
|
|
|
pub global_lb: bool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl std::fmt::Display for ProxyEntry { |
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
|
|
|
|
if self.https_target { |
|
|
|
@ -94,11 +105,16 @@ impl std::fmt::Display for ProxyEntry { |
|
|
|
|
self.path_prefix.as_deref().unwrap_or_default(), |
|
|
|
|
self.priority |
|
|
|
|
)?; |
|
|
|
|
if self.same_node { |
|
|
|
|
if self.flags.same_node { |
|
|
|
|
write!(f, " OURSELF")?; |
|
|
|
|
} else if self.same_site { |
|
|
|
|
} else if self.flags.same_site { |
|
|
|
|
write!(f, " SAME_SITE")?; |
|
|
|
|
} |
|
|
|
|
if self.flags.global_lb { |
|
|
|
|
write!(f, " GLOBAL-LB")?; |
|
|
|
|
} else if self.flags.site_lb { |
|
|
|
|
write!(f, " SITE-LB")?; |
|
|
|
|
} |
|
|
|
|
if !self.add_headers.is_empty() { |
|
|
|
|
write!(f, " +Headers: {:?}", self.add_headers)?; |
|
|
|
|
} |
|
|
|
@ -126,8 +142,7 @@ fn parse_tricot_tag( |
|
|
|
|
tag: &str, |
|
|
|
|
target_addr: SocketAddr, |
|
|
|
|
add_headers: &[(String, String)], |
|
|
|
|
same_node: bool, |
|
|
|
|
same_site: bool, |
|
|
|
|
flags: ProxyEntryFlags, |
|
|
|
|
) -> Option<ProxyEntry> { |
|
|
|
|
let splits = tag.split(' ').collect::<Vec<_>>(); |
|
|
|
|
if (splits.len() != 2 && splits.len() != 3) |
|
|
|
@ -162,8 +177,7 @@ fn parse_tricot_tag( |
|
|
|
|
target_addr, |
|
|
|
|
https_target: (splits[0] == "tricot-https"), |
|
|
|
|
host, |
|
|
|
|
same_node, |
|
|
|
|
same_site, |
|
|
|
|
flags, |
|
|
|
|
path_prefix, |
|
|
|
|
priority, |
|
|
|
|
add_headers: add_headers.to_vec(), |
|
|
|
@ -206,12 +220,19 @@ fn parse_consul_catalog( |
|
|
|
|
}; |
|
|
|
|
let addr = SocketAddr::new(ip_addr, svc.port); |
|
|
|
|
|
|
|
|
|
let (same_node, same_site) = if svc.tags.contains(&"tricot-global-lb".into()) { |
|
|
|
|
(false, false) |
|
|
|
|
let (site_lb, global_lb) = if svc.tags.contains(&"tricot-global-lb".into()) { |
|
|
|
|
(false, true) |
|
|
|
|
} else if svc.tags.contains(&"tricot-site-lb".into()) { |
|
|
|
|
(false, same_site) |
|
|
|
|
(true, false) |
|
|
|
|
} else { |
|
|
|
|
(same_node, same_site) |
|
|
|
|
(false, false) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let flags = ProxyEntryFlags { |
|
|
|
|
same_node, |
|
|
|
|
same_site, |
|
|
|
|
site_lb, |
|
|
|
|
global_lb, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let mut add_headers = vec![]; |
|
|
|
@ -227,8 +248,7 @@ fn parse_consul_catalog( |
|
|
|
|
tag, |
|
|
|
|
addr, |
|
|
|
|
&add_headers[..], |
|
|
|
|
same_node, |
|
|
|
|
same_site, |
|
|
|
|
flags, |
|
|
|
|
) { |
|
|
|
|
entries.push(ent); |
|
|
|
|
} |
|
|
|
|