Authored by chunhua.zhang

redirect to gray

local http_request = require "http_request"
local switch_controller = require "switch_controller"
local iptool=require "iptool"
function do_direct(redirectPath)
... ... @@ -70,8 +71,16 @@ end
function get_redirect_url()
local redirectPath = "/apigateway"
local awsPath = "/apiaws"
local grayPath = "/apigateway2"
---- check if gray
if ngx.var.host == 'api.yoho.yohoops.org' or ngx.var.host == 'service.yoho.yohoops.org' then
local is_gray_container = iptool:pcall_check_ip_in_ipblock(ngx.var.remote_addr, "192.168.96.0/19",false)
local is_gray_java = iptool:pcall_check_ip_in_ipblock(ngx.var.remote_addr, "10.66.71.0/19",false)
if is_gray_container or is_gray_java then
return grayPath
end
end
-- get params
local force_uid = switch_controller.get_force_uid()
... ... @@ -83,7 +92,7 @@ function get_redirect_url()
end
-- force uid
if force_uid and uid == force_uid then
return awsPath
return grayPath
end
--- hash percentage
... ... @@ -91,7 +100,7 @@ function get_redirect_url()
if percentage >= 1 then
local hash = uid % 100
if uid > 0 and hash <= percentage then
return awsPath
return grayPath
end
end
return redirectPath
... ...
... ... @@ -203,10 +203,11 @@ server {
proxy_set_header Host $host;
}
location /apiaws{
## gray configuration
location /apigateway2{
internal;
proxy_redirect off;
proxy_pass http://java-aws/gateway;
proxy_pass http://apigateway-gray/gateway;
proxy_set_header X-Real-IP $real_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
... ...
... ... @@ -168,9 +168,9 @@ http
#apigatewayend
# upstream for yoho-core-java aws
upstream java-aws {
server {{ groups['java-gateway'][0] }}:8080 max_fails=5 fail_timeout=3s;
# upstream for gray java gateway
upstream apigateway-gray {
server 10.66.71.6:8080 max_fails=5 fail_timeout=3s;
keepalive 32;
}
#apigatewayend
... ...