@@ -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"}
0 commit comments