1

I have the following nginx.config file:

events {}

http {
    # ...
    # application version 1a 
    upstream version_1a {
        server localhost:8090;
    }

    # application version 1b
    upstream version_1b {
        server localhost:8091;
    }

    split_clients "${arg_token}" $appversion {
        50%     version_1a;
        50% version_1b;
    }

    server {
        # ...
        listen 7080;
        location / {
            proxy_set_header Host $host;
            proxy_pass http://$appversion;
        }
    }
}

I have two nodejs servers listening on port 8090 and 8091 and I am hitting the URL http://localhost:7080, my expectation here is the Nginx will randomly split the traffic to version_1a and version_1b upstream, but, all the traffic is going to version_1a. Any insight into why this might be happening?

(I want to have this configuration for the canary traffic)

Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • when I used `$request_id` instead of `${arg_token}` it started splitting the traffic evenly – Vishrant Feb 13 '21 at 05:50
  • Is it possible that `arg_token` is not coming at all or coming as blank? – Tarun Lalwani Feb 14 '21 at 07:39
  • You are right Tarun arg_token was not coming. – Vishrant Feb 15 '21 at 08:04
  • how did you come up with your solution? I had the same problem (took the template code from here: https://www.nginx.com/blog/performing-a-b-testing-nginx-plus/) – Data Mastery Jul 21 '21 at 18:26
  • @DataMastery please describe what issue were you facing? if you are splitting the traffic by some variable, check if the variable value is set correctly and is uniform. – Vishrant Aug 05 '21 at 14:59

1 Answers1

0

Validate the variable you are using to split the traffic is set correctly, and the variable's value should be uniformly distributed else the traffic will not be split evenly.

Vishrant
  • 15,456
  • 11
  • 71
  • 120