diff --git a/internal/nginx/extensions.go b/internal/nginx/extensions.go index 7b87a3f82d..b23205cc52 100644 --- a/internal/nginx/extensions.go +++ b/internal/nginx/extensions.go @@ -18,21 +18,34 @@ func ParseLBMethod(method string) (string, error) { return method, err } - if method == "least_conn" || method == "ip_hash" { + if _, exists := nginxLBValidInput[method]; exists { return method, nil } return "", fmt.Errorf("Invalid load balancing method: %q", method) } +var nginxLBValidInput = map[string]bool{ + "least_conn": true, + "ip_hash": true, + "random": true, + "random two": true, + "random two least_conn": true, +} + var nginxPlusLBValidInput = map[string]bool{ - "least_time": true, - "last_byte": true, - "least_conn": true, - "ip_hash": true, - "least_time header": true, - "least_time last_byte": true, - "least_time header inflight": true, - "least_time last_byte inflight": true, + "least_time": true, + "last_byte": true, + "least_conn": true, + "ip_hash": true, + "random": true, + "random two": true, + "random two least_conn": true, + "random two least_time=header": true, + "random two least_time=last_byte": true, + "least_time header": true, + "least_time last_byte": true, + "least_time header inflight": true, + "least_time last_byte inflight": true, } // ParseLBMethodForPlus parses method and matches it to a corresponding load balancing method in NGINX Plus. An error is returned if method is not valid diff --git a/internal/nginx/extensions_test.go b/internal/nginx/extensions_test.go index 75effa062a..ef645c0242 100644 --- a/internal/nginx/extensions_test.go +++ b/internal/nginx/extensions_test.go @@ -10,6 +10,9 @@ func TestParseLBMethod(t *testing.T) { {"least_conn", "least_conn"}, {"round_robin", ""}, {"ip_hash", "ip_hash"}, + {"random", "random"}, + {"random two", "random two"}, + {"random two least_conn", "random two least_conn"}, {"hash $request_id", "hash $request_id"}, {"hash $request_id consistent", "hash $request_id consistent"}, } @@ -20,6 +23,10 @@ func TestParseLBMethod(t *testing.T) { "least_time header", "hash123", "hash $request_id conwrongspelling", + "random one", + "random two least_time=header", + "random two least_time=last_byte", + "random two ip_hash", } for _, test := range testsWithValidInput { @@ -49,6 +56,11 @@ func TestParseLBMethodForPlus(t *testing.T) { {"least_conn", "least_conn"}, {"round_robin", ""}, {"ip_hash", "ip_hash"}, + {"random", "random"}, + {"random two", "random two"}, + {"random two least_conn", "random two least_conn"}, + {"random two least_time=header", "random two least_time=header"}, + {"random two least_time=last_byte", "random two least_time=last_byte"}, {"hash $request_id", "hash $request_id"}, {"least_time header", "least_time header"}, {"least_time last_byte", "least_time last_byte"}, @@ -61,6 +73,9 @@ func TestParseLBMethodForPlus(t *testing.T) { "blabla", "hash123", "least_time inflight header", + "random one", + "random two ip_hash", + "random two least_time", } for _, test := range testsWithValidInput { @@ -82,7 +97,6 @@ func TestParseLBMethodForPlus(t *testing.T) { } } - func TestParseSlowStart(t *testing.T) { var testsWithValidInput = []string{"1", "1m10s", "11 11", "5m 30s", "1s", "100m", "5w", "15m", "11M", "3h", "100y", "600"} var invalidInput = []string{"ss", "rM", "m0m", "s1s", "-5s", "", "1L"} @@ -101,4 +115,4 @@ func TestParseSlowStart(t *testing.T) { t.Errorf("TestParseSlowStart(%q) didn't return error. Returned: %q", test, result) } } -} \ No newline at end of file +}