diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-02-28 11:10:50 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-02-28 11:10:56 +0800 |
commit | d77dc45e7eee74a7c39e850070103fcbbc8f38b0 (patch) | |
tree | 42ba2358aa53a99e30d7f493a619a40b67f9ec4a /openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua | |
parent | eba92f2ec4bd3783633fe2408eeae582b811c70a (diff) |
Support IP Hash LB policy
Issue-ID: MSB-154
Change-Id: I11b8e3a314c6045183971bf2207b9ccee7df10c2
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua')
-rw-r--r-- | openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua index 48dc1d8..ac9bb1d 100644 --- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua +++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/balancer.lua @@ -1,6 +1,6 @@ --[[
- Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
+ Copyright (C) 2018 ZTE, Inc. and others. All rights reserved. (ZTE)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,14 +18,16 @@ local b = require "ngx.balancer"
local baseupstream = require "loadbalance.baseupstream"
-local log_util = require('lib.utils.log_util')
-local error_handler = require('lib.utils.error_handler')
+local stats = require "monitor.stats"
+local svc_util = require 'lib.utils.svc_util'
+
+local servers = ngx.ctx.backservers
+local svc_key = ngx.ctx.svc_key
+local svc_info = ngx.ctx.svc_info
+local svc_get_connect_timeout = svc_util.get_connect_timeout
+local svc_get_send_timeout = svc_util.get_send_timeout
+local svc_get_read_timeout = svc_util.get_read_timeout
-local log = log_util.log
-local ngx_ctx = ngx.ctx
-local servers = ngx_ctx.backservers
-local svc_key = ngx_ctx.svc_key
-local error_svc_not_found = error_handler.svc_not_found
local status = b.get_last_failure()
if status == nil then
@@ -35,6 +37,7 @@ elseif status == "failed" then local last_peer = ngx.ctx.last_peer
--mark the srv failed one time
baseupstream.mark_srv_failed(svc_key,last_peer)
+ stats.backend_failed()
end
local server,err = baseupstream.get_backserver(svc_key,servers)
@@ -46,5 +49,6 @@ if baseupstream.can_retry(svc_key,servers) then b.set_more_tries(1)
end
b.set_current_peer(server["ip"],server["port"])
---log("upstreamserver",server["ip"]..":"..server["port"])
-ngx.ctx.last_peer = { ip=server["ip"], port=server["port"] }
\ No newline at end of file +b.set_timeouts(svc_get_connect_timeout(svc_info), svc_get_send_timeout(svc_info), svc_get_read_timeout(svc_info))
+ngx.ctx.last_peer = { ip=server["ip"], port=server["port"] }
+stats.forward_backend()
|