From 85e1e7d8a4669ff46bbb75353f544605ebd603ea Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 13 Jan 2022 12:24:25 +0100 Subject: [PATCH] Add support for tricot-site-lb and tricot-global-lb tags --- README.md | 6 ++++-- src/proxy_config.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b18d57f..22afc99 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ Backends are configured by adding tags of the following form to the services in - `tricot myapp.example.com/path/to_subresource 10`: combining the previous two examples - `tricot-https myapp.example.com`: same, but indicates that the backend service handling the request expects an HTTPS request and not an HTTP request. In this case, Tricot will do everything in its power to NOT verify the backend's TLS certificate (ignore self-signed certificate, ignore TLS hostname, etc). - `tricot-add-header Access-Control-Allow-Origin *`: add the `Access-Control-Allow-Origin: *` header to all of the HTTP responses when they are proxied back to the client +- `tricot-global-lb`: load-balance incoming requests to all matching backends +- `tricot-site-lb`: load-balance incoming requests to all matching backends that are in the same site (geographical location); when site information about nodes is not available, this is equivalent to `tricot-global-lb` Any number of such rules can be combined freely. @@ -52,6 +54,6 @@ Tricot priorizes backend nodes in the following order: 1. Select rule with the highest explicitly set priority value 2. Select rule with the longest path prefix that matches the incoming request -3. Select rule that redirects request to the same node Tricot is running on -4. Select rule that redirects request to a node that is running in the same site (geographical region, datacenter, whatever) than the node Tricot is running on, based on the metadata key `site` in Consul's node information, if such information is available +3. Select rule that redirects request to the same node Tricot is running on, except `tricot-site-lb` or `tricot-global-lb` is used +4. Select rule that redirects request to a node that is running in the same site (geographical region, datacenter, whatever) than the node Tricot is running on, based on the metadata key `site` in Consul's node information, if such information is available, except if `tricot-global-lb` is used 5. Round-robin selection of backend nodes diff --git a/src/proxy_config.rs b/src/proxy_config.rs index a64e5aa..4add98c 100644 --- a/src/proxy_config.rs +++ b/src/proxy_config.rs @@ -194,6 +194,14 @@ 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) + } else if svc.tags.contains(&"tricot-site-lb".into()) { + (false, same_site) + } else { + (same_node, same_site) + }; + let mut add_headers = vec![]; for tag in svc.tags.iter() { if let Some(pair) = parse_tricot_add_header_tag(tag) {