Home > Software engineering >  how to split traffic from same url path to 2 different upstreams?
how to split traffic from same url path to 2 different upstreams?

Time:06-03

i have these upstreams declared:

upstream upstream_1 {
    server some_container_1:8000;
}

upstream upstream_2 {
    server some_container_2:8001;
}

and this server:

server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  upstream_1;
    }
}

where both some_container_1 and some_container_2 are based on same image (thus offer the same apis on the same paths) but differ on env vars and other non related stuff. i want to fork 1% of all traffic from localhost:7000/path to be delivered 'as is' to upstream_2 and 99% to remain on upstream_1. both cases should keep the request as received, altering neither path nor headers

with split_clients i can fork which path will be set before forwarding the request to a single upstream, which is not my case.

here the fork is done inside an upstream between servers, not inside a location splitting between upstreams, as i need.

can i define an upstream of upstreams like

upstream compound_upstream_1 {
    upstream upstream_1 weight=99;
    upstream upstream_2;
}

to use it on

server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  compound_upstream_1;
    }

is it possible to do this with nginx? considering so, which way should be the standard to accomplish this?

CodePudding user response:

I don't understand, what stops you from using server names in the upstream block directly?

upstream compound_upstream_1 {
    server some_container_1:8000 weight=99;
    server some_container_2:8001;
}
server {
    listen       7000;
    server_name  localhost;
    location /path {
        uwsgi_pass  compound_upstream_1;
    }
}

Or maybe I misunderstand your question?

CodePudding user response:

It might be possible to accomplish this using a load balancer: https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/

I'm not sure what the weights would be for your '1%' scenario but you can toy with it and adjust it to your liking.

  • Related