You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2020/12/20 12:09:54 UTC
[apisix] branch master updated: fix: upgrade lua-resty-ngxvar to
solve the upstream_xxx_time problem (#3065)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 31b49ad fix: upgrade lua-resty-ngxvar to solve the upstream_xxx_time problem (#3065)
31b49ad is described below
commit 31b49ad0e1f3e3d32ee572d69a610586f1fde111
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Sun Dec 20 20:09:46 2020 +0800
fix: upgrade lua-resty-ngxvar to solve the upstream_xxx_time problem (#3065)
Fix #2954
Signed-off-by: spacewander <sp...@gmail.com>
---
apisix/balancer/ewma.lua | 5 +-
apisix/plugins/limit-conn.lua | 2 +
apisix/plugins/prometheus/exporter.lua | 3 +-
rockspec/apisix-master-0.rockspec | 2 +-
t/plugin/limit-conn2.t | 109 +++++++++++++++++++++++++++++++++
5 files changed, 115 insertions(+), 6 deletions(-)
diff --git a/apisix/balancer/ewma.lua b/apisix/balancer/ewma.lua
index bdc7722..b66b07a 100644
--- a/apisix/balancer/ewma.lua
+++ b/apisix/balancer/ewma.lua
@@ -11,7 +11,6 @@ local ngx_now = ngx.now
local math = math
local pairs = pairs
local next = next
-local tonumber = tonumber
local _M = {}
local DECAY_TIME = 10 -- this value is in seconds
@@ -152,8 +151,8 @@ local function _ewma_after_balance(ctx, before_retry)
return nil
end
- local response_time = tonumber(ctx.var.upstream_response_time) or 0
- local connect_time = tonumber(ctx.var.upstream_connect_time) or 0
+ local response_time = ctx.var.upstream_response_time or 0
+ local connect_time = ctx.var.upstream_connect_time or 0
local rtt = connect_time + response_time
local upstream = ctx.var.upstream_addr
diff --git a/apisix/plugins/limit-conn.lua b/apisix/plugins/limit-conn.lua
index 0249116..734cffb 100644
--- a/apisix/plugins/limit-conn.lua
+++ b/apisix/plugins/limit-conn.lua
@@ -116,6 +116,8 @@ function _M.log(conf, ctx)
latency = ctx.var.request_time - delay
end
+ core.log.debug("request latency is ", latency) -- for test
+
local conn, err = lim:leaving(key, latency)
if not conn then
core.log.error("failed to record the connection leaving request: ",
diff --git a/apisix/plugins/prometheus/exporter.lua b/apisix/plugins/prometheus/exporter.lua
index 85f7436..1bfb039 100644
--- a/apisix/plugins/prometheus/exporter.lua
+++ b/apisix/plugins/prometheus/exporter.lua
@@ -20,7 +20,6 @@ local ipairs = ipairs
local ngx = ngx
local ngx_capture = ngx.location.capture
local re_gmatch = ngx.re.gmatch
-local tonumber = tonumber
local select = select
local type = type
local prometheus
@@ -153,7 +152,7 @@ function _M.log(conf, ctx)
local overhead = latency
if ctx.var.upstream_response_time then
- overhead = overhead - tonumber(ctx.var.upstream_response_time) * 1000
+ overhead = overhead - ctx.var.upstream_response_time * 1000
end
metrics.overhead:observe(overhead,
gen_arr("request", service_id, consumer_name, balancer_ip))
diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec
index e93aaec..bf2912a 100644
--- a/rockspec/apisix-master-0.rockspec
+++ b/rockspec/apisix-master-0.rockspec
@@ -34,7 +34,7 @@ dependencies = {
"lua-resty-template = 1.9",
"lua-resty-etcd = 1.4.3",
"lua-resty-balancer = 0.02rc5",
- "lua-resty-ngxvar = 0.5",
+ "lua-resty-ngxvar = 0.5.2",
"lua-resty-jit-uuid = 0.0.7",
"lua-resty-healthcheck-api7 = 2.2.0",
"lua-resty-jwt = 0.2.0",
diff --git a/t/plugin/limit-conn2.t b/t/plugin/limit-conn2.t
new file mode 100644
index 0000000..914abca
--- /dev/null
+++ b/t/plugin/limit-conn2.t
@@ -0,0 +1,109 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+BEGIN {
+ if ($ENV{TEST_NGINX_CHECK_LEAK}) {
+ $SkipReason = "unavailable for the hup tests";
+
+ } else {
+ $ENV{TEST_NGINX_USE_HUP} = 1;
+ undef $ENV{TEST_NGINX_USE_STAP};
+ }
+}
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_shuffle();
+no_root_location();
+
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->error_log && !$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: limit-conn with retry upstream, set upstream
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/upstreams/1',
+ ngx.HTTP_PUT,
+ [[{
+ "nodes": {
+ "127.0.0.2:1": 1,
+ "127.0.0.1:1980": 1
+ },
+ "retries": 2,
+ "type": "roundrobin"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/mysleep",
+ "plugins": {
+ "limit-conn": {
+ "conn": 1,
+ "burst": 0,
+ "default_conn_delay": 0.3,
+ "rejected_code": 503,
+ "key": "remote_addr"
+ }
+ },
+ "upstream_id": "1"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 2: hit route
+--- log_level: debug
+--- request
+GET /mysleep?seconds=0.1
+--- error_log
+request latency is 0.1
+--- response_body
+0.1