Authored by chunhua.zhang

some changes

local lrucache = require "resty.lrucache"
local switch_controller = require "switch_controller"
-- init redis twemproxy config
... ... @@ -21,8 +20,5 @@ lua_context.lua_conf_cache=ngx.shared.ngxconf
lua_context.configs={}
--- init switch to aws percentage
switch_controller.init()
ngx.shared.upstream:flush_all()
ngx.shared.upstream:flush_expired()
... ...
... ... @@ -16,6 +16,9 @@ function M:switch()
if method == "query" then
local percentage = lua_context.lua_conf_cache:get("switch:percentage")
if not percentage then
percentage = '0'
end
ngx.say(percentage)
ngx.exit(ngx.HTTP_OK)
... ... @@ -35,13 +38,15 @@ function M:switch()
lua_context.lua_conf_cache:set("switch:uid", uid)
ngx.exit(ngx.HTTP_OK)
end
end
end
function M:init()
return lua_context.lua_conf_cache:set("switch:percentage", 0)
end
end
--- reset all
if method == "reset" then
lua_context.lua_conf_cache:delete("switch:uid")
lua_context.lua_conf_cache:delete("switch:percentage")
ngx.exit(ngx.HTTP_OK)
end
end
function M:get_percentage()
local per = lua_context.lua_conf_cache:get("switch:percentage")
... ...
... ... @@ -15,6 +15,15 @@
## 切换
- `重置`: http://erp.yoho.yohoops.org/switch?method=reset
- `查询`: http://erp.yoho.yohoops.org/switch?method=query
- `设置UID强制到aws`: http://erp.yoho.yohoops.org/switch?method=force&uid=50873076
- `设置按照比率切换到aws`: http://erp.yoho.yohoops.org/switch?method=switch&percentage=10
## 动态`upstream`的支持
基于 [lua-upstream-nginx-module] (https://github.com/openresty/lua-upstream-nginx-module) 动态设置upstream的 `up`, `down`
... ...