Authored by chunhua.zhang

add

1 local http_request = require "http_request" 1 local http_request = require "http_request"
2 local switch_controller = require "switch_controller" 2 local switch_controller = require "switch_controller"
3 3
  4 +--- those methods will be degraded. nginx will send response directly without redirecting to backend servers.
  5 +local degrade_methods = {
  6 + "method1",
  7 + "method2"
  8 +
  9 +
  10 +}
  11 +
  12 +function do_degrade()
  13 + local method = http_request.get_req_param("method")
  14 + for i, v in ipairs(degrade_methods) do
  15 + if method == v then
  16 + ngx.log(ngx.ERR, "method is degraded.", method)
  17 + ngx.exit(ngx.HTTP_OK)
  18 + end
  19 + end
  20 +
  21 +end
4 22
5 function do_direct(redirectPath) 23 function do_direct(redirectPath)
6 --- processing: api.yoho.cn/operation/get/home?xxxxx 24 --- processing: api.yoho.cn/operation/get/home?xxxxx
@@ -101,6 +119,11 @@ end @@ -101,6 +119,11 @@ end
101 ---- main 119 ---- main
102 function main() 120 function main()
103 121
  122 + local _status, _msg = pcall(do_degrade)
  123 + if not _status then
  124 + ngx.log(ngx.ERR, "call method [do_degrade] failed.", _msg)
  125 + end
  126 +
104 local status, ret = pcall(get_redirect_url) 127 local status, ret = pcall(get_redirect_url)
105 if not status then 128 if not status then
106 ngx.log(ngx.ERR, "call method [get_redirect_url] failed.", ret) 129 ngx.log(ngx.ERR, "call method [get_redirect_url] failed.", ret)