Skip to content

Commit 7fccd33

Browse files
authored
fix: control api return wrong status data for passive health check (#12975)
Signed-off-by: Nic <qianyong@api7.ai>
1 parent 3ba27f6 commit 7fccd33

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

apisix-master-0.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = {
4141
"lua-resty-ngxvar = 0.5.2-0",
4242
"lua-resty-jit-uuid = 0.0.7-2",
4343
"lua-resty-ksuid = 1.0.1-0",
44-
"lua-resty-healthcheck-api7 = 3.2.0-0",
44+
"lua-resty-healthcheck-api7 = 3.2.1-0",
4545
"api7-lua-resty-jwt = 0.2.6-0",
4646
"lua-resty-hmac-ffi = 0.06-1",
4747
"lua-resty-cookie = 0.4.1-1",

t/control/healthcheck.t

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,95 @@ GET /v1/healthcheck/route/1
313313
--- error_code: 400
314314
--- response_body
315315
{"error_msg":"invalid src type route"}
316+
317+
318+
319+
=== TEST 7: passive health check status
320+
--- yaml_config
321+
apisix:
322+
node_listen: 1984
323+
deployment:
324+
role: data_plane
325+
role_data_plane:
326+
config_provider: yaml
327+
--- apisix_yaml
328+
routes:
329+
-
330+
id: 1
331+
uris:
332+
- /specific_status
333+
upstream:
334+
nodes:
335+
"127.0.0.1:1980": 1
336+
"127.0.0.2:1980": 1
337+
type: roundrobin
338+
checks:
339+
active:
340+
healthy:
341+
interval: 999 # large interval to avoid active check influence
342+
unhealthy:
343+
interval: 999
344+
passive:
345+
healthy:
346+
http_statuses:
347+
- 200
348+
successes: 1
349+
unhealthy:
350+
http_statuses:
351+
- 500
352+
http_failures: 3
353+
#END
354+
--- config
355+
location /t {
356+
content_by_lua_block {
357+
local json = require("toolkit.json")
358+
local t = require("lib.test_admin")
359+
local http = require "resty.http"
360+
361+
-- first request to trigger health checker manager startup
362+
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/specific_status"
363+
local httpc = http.new()
364+
local res, err = httpc:request_uri(uri, {
365+
method = "GET",
366+
headers = {
367+
["x-test-upstream-status"] = "500"
368+
}
369+
})
370+
if not res then
371+
ngx.say("failed to request: ", err)
372+
return
373+
end
374+
375+
ngx.sleep(1)
376+
377+
for i = 1, 6 do
378+
local res, err = httpc:request_uri(uri, {
379+
method = "GET",
380+
headers = {
381+
["x-test-upstream-status"] = "500"
382+
}
383+
})
384+
if not res then
385+
ngx.say("failed to request: ", err)
386+
return
387+
end
388+
end
389+
390+
local code, body, res = t.test('/v1/healthcheck/routes/1',
391+
ngx.HTTP_GET)
392+
ngx.log(ngx.ERR, "healthcheck response: ", res)
393+
res = json.decode(res)
394+
table.sort(res.nodes, function(a, b)
395+
return a.ip < b.ip
396+
end)
397+
ngx.say(json.encode(res))
398+
}
399+
}
400+
--- grep_error_log eval
401+
qr/unhealthy HTTP increment \(.+\) for '127.0.0.1\(127.0.0.1:1980\)'/
402+
--- grep_error_log_out
403+
unhealthy HTTP increment (1/3) for '127.0.0.1(127.0.0.1:1980)'
404+
unhealthy HTTP increment (2/3) for '127.0.0.1(127.0.0.1:1980)'
405+
unhealthy HTTP increment (3/3) for '127.0.0.1(127.0.0.1:1980)'
406+
--- response_body
407+
{"name":"/routes/1","nodes":[{"counter":{"http_failure":3,"success":0,"tcp_failure":0,"timeout_failure":0},"hostname":"127.0.0.1","ip":"127.0.0.1","port":1980,"status":"unhealthy"},{"counter":{"http_failure":3,"success":0,"tcp_failure":0,"timeout_failure":0},"hostname":"127.0.0.2","ip":"127.0.0.2","port":1980,"status":"unhealthy"}],"type":"http"}

t/stream-node/healthcheck-resty-events.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ passed
283283
proxy request to 127.0.0.1:9995 while connecting to upstream
284284
connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995"
285285
enabled healthcheck passive while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995",
286-
unhealthy TCP increment (1/1) for '(127.0.0.1:9995)' while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995",
286+
unhealthy TCP increment (1/1) for '127.0.0.1(127.0.0.1:9995)' while connecting to upstream, client: 127.0.0.1, server: 0.0.0.0:1985, upstream: "127.0.0.1:9995",
287287
proxy request to 127.0.0.1:1995 while connecting to upstream
288288
proxy request to 127.0.0.1:1995 while connecting to upstream
289289
proxy request to 127.0.0.1:1995 while connecting to upstream

0 commit comments

Comments
 (0)