-
Notifications
You must be signed in to change notification settings - Fork 278
feature: support lua balancer set proxy bind dynamic #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8526f4
feature: support lua balancer set proxy bind dynamic
ytlm ce2f1cd
doc: add set_proxy_bind API document
ytlm 5b00d92
test: add set_proxy_bind test cases
ytlm a8b9e8b
test: add stream balancer set_proxy_bind test cases
ytlm 6bf8dc2
fix: stream test
ytlm b2550cb
fix: stream test
ytlm 0235051
fix: rebase with master
ytlm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
use lib '.'; | ||
use t::TestCore::Stream; | ||
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * (blocks() * 4); | ||
|
||
$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = "$t::TestCore::Stream::lua_package_path"; | ||
|
||
no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: balancer | ||
--- stream_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1:1234 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer("127.0.0.1", 12345)) | ||
} | ||
} | ||
|
||
server { | ||
listen 127.0.0.1:12345; | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- stream_server_config | ||
proxy_pass backend; | ||
|
||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.1/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
|
||
|
||
|
||
=== TEST 2: balancer with set_proxy_bind (addr) | ||
--- stream_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1:1234 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer("127.0.0.1", 12345)) | ||
|
||
assert(b.set_proxy_bind("127.0.0.4")) | ||
} | ||
} | ||
|
||
server { | ||
listen 127.0.0.1:12345; | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- stream_server_config | ||
proxy_pass backend; | ||
|
||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.4/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
|
||
|
||
|
||
=== TEST 3: balancer with set_proxy_bind (addr and port) | ||
--- stream_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1:1234 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer("127.0.0.1", 12345)) | ||
|
||
assert(b.set_proxy_bind("127.0.0.8:23456")) | ||
} | ||
} | ||
|
||
server { | ||
listen 127.0.0.1:12345; | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- stream_server_config | ||
proxy_pass backend; | ||
|
||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.8/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
use lib '.'; | ||
use t::TestCore; | ||
|
||
#worker_connections(1014); | ||
#master_on(); | ||
#workers(2); | ||
#log_level('warn'); | ||
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * (blocks() * 4); | ||
|
||
$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = "$t::TestCore::lua_package_path"; | ||
|
||
#worker_connections(1024); | ||
#no_diff(); | ||
no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: balancer | ||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer(ngx.var.server_addr, ngx.var.server_port)) | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
proxy_pass http://backend/echo; | ||
} | ||
|
||
location = /echo { | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.1/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
|
||
|
||
|
||
=== TEST 2: balancer with set_proxy_bind (addr) | ||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer(ngx.var.server_addr, ngx.var.server_port)) | ||
|
||
assert(b.set_proxy_bind("127.0.0.4")) | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
proxy_pass http://backend/echo; | ||
} | ||
|
||
location = /echo { | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.4/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
|
||
|
||
|
||
=== TEST 3: balancer with set_proxy_bind (addr and port) | ||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
upstream backend { | ||
server 0.0.0.1 down; | ||
balancer_by_lua_block { | ||
local b = require "ngx.balancer" | ||
assert(b.set_current_peer(ngx.var.server_addr, ngx.var.server_port)) | ||
|
||
assert(b.set_proxy_bind("127.0.0.8:23456")) | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
proxy_pass http://backend/echo; | ||
} | ||
|
||
location = /echo { | ||
content_by_lua_block { | ||
ngx.print(ngx.var.remote_addr, ":", ngx.var.remote_port) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body eval | ||
[ | ||
qr/127.0.0.8/, | ||
] | ||
--- error_code: 200 | ||
--- no_error_log | ||
[error] | ||
[warn] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.