Authored by chunhua.zhang

switch

local lrucache = require "resty.lrucache"
local switch_controller = require "switch_controller"
-- init redis twemproxy config
... ... @@ -20,6 +21,8 @@ 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()
... ...
local modname= ...
local M={}
_G[modname]=M
package.loaded[modname]=M
-- switch.
-- switch_to_aws: http://erp.yoho.yohoops.org/switch/?method=switch&percentage=10
-- switch query: http://erp.yoho.yohoops.org/switch/?method=query
-- mal ip controller api --------
function M:switch()
local method=http_request.get_req_param("method")
if method == "query" then
local percentage = lua_context.lua_conf_cache:get("switch:percentage")
ngx.say(percentage)
ngx.exit(ngx.HTTP_OK)
end
if method == "switch" then
local percentage = http_request.get_req_param("percentage")
if percentage then
lua_context.lua_conf_cache:set("switch:percentage", percentage)
ngx.exit(ngx.HTTP_OK)
end
end
end
function M:init()
return lua_context.lua_conf_cache:set("switch:percentage", 0)
end
function M:get_percentage()
return lua_context.lua_conf_cache:get("switch:percentage")
end
... ...
... ... @@ -36,6 +36,14 @@ server {
';
}
## switch management
location = /switch {
content_by_lua '
local switch = require "switch_controller";
switch:switch();
';
}
location = /upstreams {
content_by_lua_file "conf/lua/upstream.lua";
}
... ...
... ... @@ -176,6 +176,12 @@ http
#apigatewayend
# upstream for yoho-core-java aws
upstream java-aws {
server java-gateway-431f16063270008f.elb.cn-north-1.amazonaws.com.cn:8080 max_fails=5 fail_timeout=3s;
keepalive 32;
}
#apigatewayend
# activity
... ...