forked from Deuxfleurs/tricot
Add support for tricot-site-lb and tricot-global-lb tags
This commit is contained in:
parent
e446d6763e
commit
85e1e7d8a4
2 changed files with 12 additions and 2 deletions
|
@ -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 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-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-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.
|
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
|
1. Select rule with the highest explicitly set priority value
|
||||||
2. Select rule with the longest path prefix that matches the incoming request
|
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
|
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
|
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
|
5. Round-robin selection of backend nodes
|
||||||
|
|
|
@ -194,6 +194,14 @@ fn parse_consul_catalog(
|
||||||
};
|
};
|
||||||
let addr = SocketAddr::new(ip_addr, svc.port);
|
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![];
|
let mut add_headers = vec![];
|
||||||
for tag in svc.tags.iter() {
|
for tag in svc.tags.iter() {
|
||||||
if let Some(pair) = parse_tricot_add_header_tag(tag) {
|
if let Some(pair) = parse_tricot_add_header_tag(tag) {
|
||||||
|
|
Loading…
Reference in a new issue