apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: health check not working

Open gewei2000 opened this issue 6 years ago • 14 comments

Issue description

I configured a upstream(small_center_upstream), port 7001 of 9.23.27.226 is not opened, but the traffic is still sent to this server, why health check not remove it(9.23.27.226) ,full config:

Screen Shot 2020-11-13 at 18 34 23
{
	"name": "small_center_upstream",
	"type": "chash",
	"hash_on": "header",
	"key": "remote_addr",
	"timeout": {
		"connect": 6000,
		"send": 6000,
		"read": 6000
	},
	"nodes": [{
		"host": "9.23.27.152",
		"port": 7001,
		"weight": 1
	}, {
		"host": "9.23.27.226",
		"port": 7001,
		"weight": 1
	}],
	"checks": {
		"active": {
			"type": "tcp",
			"healthy": {
				"interval": 2,
				"successes": 1
			},
			"unhealthy": {
				"interval": 1,
				"tcp_failures": 2
			}
		}
	}
}

Environment

  • apisix version (cmd: apisix version):apache/apisix:2.0-centos
  • OS:centos

gewei2000 avatar Nov 13 '20 08:11 gewei2000

@membphis @moonming

gewei2000 avatar Nov 13 '20 08:11 gewei2000

I'm not quite sure what your question means. @membphis @spacewander please help answer if you two are free.

idbeta avatar Nov 13 '20 10:11 idbeta

I used you configuration to see wheather it's as same as yours. I tried to close each port configured in the upstream and everything works well in the program. You can see if there is a warn log in the log file which means this host has been checked and it won't be choosen again.

2020/11/14 02:14:23 [warn] 218476#218476: *33720 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/upstreams/1) unhealthy TCP increment (1/2) for '(9.23.27.226:7001)', context: ngx.timer, client: ::1, server: [::]:9080
2020/11/14 02:14:25 [warn] 218473#218473: *33843 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/upstreams/1) unhealthy TCP increment (2/2) for '(9.23.27.226:7001)', context: ngx.timer, client: ::1, server: [::]:9080

And if I close both ports, I can see the log just like you.

2020/11/14 02:22:51 [error] 218476#218476: *62776 connect() failed (111: Connection refused) while connecting to upstream, client: ::1, server: , request: "GET /route1 HTTP/1.1", upstream: "http://9.23.27.226:7001/route1", host: "localhost:9080"

Here I use you ip and port to replace mine. :)

HelloBug0 avatar Nov 14 '20 02:11 HelloBug0

my env( apisix master + dashboard 2.0) can not reproduce your issue, my route like this:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/404.html",
    "upstream": {
         "nodes": {
            "192.168.0.2": 1,
            "127.0.0.1:9797": 1
        },
        "type": "roundrobin",
        "retries": 2,
        "checks": {
            "active": {
                "timeout": 5,
                "http_path": "/404.html",
                "healthy": {
                    "interval": 2,
                    "successes": 1
                },
                "unhealthy": {
                    "interval": 1,
                    "http_failures": 2
                },
                "req_headers": ["User-Agent: curl/7.29.0"]
            }
        }
    }
}'

after I close 127.0.0.1:9797, APISIX's error.log show it only sent two times traffic to the 127.0.0.1:9797

2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080

Then no more traffic to the 127.0.0.1:9797. But the log has another issue: there are redundant logs, I will report that. https://github.com/apache/apisix/issues/2745

idbeta avatar Nov 14 '20 03:11 idbeta

my env( apisix master + dashboard 2.0) can not reproduce your issue, my route like this:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/404.html",
    "upstream": {
         "nodes": {
            "192.168.0.2": 1,
            "127.0.0.1:9797": 1
        },
        "type": "roundrobin",
        "retries": 2,
        "checks": {
            "active": {
                "timeout": 5,
                "http_path": "/404.html",
                "healthy": {
                    "interval": 2,
                    "successes": 1
                },
                "unhealthy": {
                    "interval": 1,
                    "http_failures": 2
                },
                "req_headers": ["User-Agent: curl/7.29.0"]
            }
        }
    }
}'

after I close 127.0.0.1:9797, APISIX's error.log show it only sent tow times traffic to the 127.0.0.1:9797

2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080

Then no more traffic to the 127.0.0.1:9797. But the log has another issue: there are redundant logs, I will report that. #2745

let me try

gewei2000 avatar Nov 14 '20 04:11 gewei2000

my env( apisix master + dashboard 2.0) can not reproduce your issue, my route like this:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/404.html",
    "upstream": {
         "nodes": {
            "192.168.0.2": 1,
            "127.0.0.1:9797": 1
        },
        "type": "roundrobin",
        "retries": 2,
        "checks": {
            "active": {
                "timeout": 5,
                "http_path": "/404.html",
                "healthy": {
                    "interval": 2,
                    "successes": 1
                },
                "unhealthy": {
                    "interval": 1,
                    "http_failures": 2
                },
                "req_headers": ["User-Agent: curl/7.29.0"]
            }
        }
    }
}'

after I close 127.0.0.1:9797, APISIX's error.log show it only sent tow times traffic to the 127.0.0.1:9797

2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:38 [warn] 95077#3298494: *1505367 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (1/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for 'foo.com(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080
2020/11/14 11:13:41 [warn] 95077#3298494: *1505577 [lua] healthcheck.lua:1107: log(): [healthcheck] (upstream#/apisix/routes/1) unhealthy TCP increment (2/2) for '(127.0.0.1:9797)', context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:9080

Then no more traffic to the 127.0.0.1:9797. But the log has another issue: there are redundant logs, I will report that. #2745

my env(docker:apache/apisix:2.0-centos + dashboard 2.0 ), it also can not work, you can try use this json data my json data

{"name":"small_policy_center","type":"roundrobin","retries":2,"timeout":{"connect":6000,"send":6000,"read":6000},"nodes":[{"host":"9.23.27.152","port":7001,"weight":1},{"host":"9.23.27.226","port":7001,"weight":1}],"checks":{"active":{"healthy":{"interval":2,"successes":1},"http_path":"/","timeout":5,"unhealthy":{"http_failures":2,"interval":1}}}}

gewei2000 avatar Nov 14 '20 07:11 gewei2000

@gewei2000 I used your config data ( as follows ) and do not reproduce your issue. I want to know if you set the route many time or one time?

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/route.html",
    "upstream": {
	    "name":"small_policy_center",
	    "type":"roundrobin",
	    "retries":2,
	    "timeout":{
	        "connect":6000,
	        "send":6000,
	        "read":6000
	    },
	    "nodes":[
	        {
	            "host":"127.0.0.1",
	            "port":7001,
	            "weight":1
	        },
	        {
	            "host":"127.0.0.1",
	            "port":7002,
	            "weight":1
	        }
	    ],
	    "checks":{
	        "active":{
	            "healthy":{
	                "interval":2,
	                "successes":1
	            },
	            "http_path":"/",
	            "timeout":5,
	            "unhealthy":{
	                "http_failures":2,
	                "interval":1
	            }
	        }
	    }
	}
}'

idbeta avatar Nov 14 '20 10:11 idbeta

@gewei2000 I used your config data ( as follows ) and do not reproduce your issue. I want to know if you set the route many time or one time?

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/route.html",
    "upstream": {
	    "name":"small_policy_center",
	    "type":"roundrobin",
	    "retries":2,
	    "timeout":{
	        "connect":6000,
	        "send":6000,
	        "read":6000
	    },
	    "nodes":[
	        {
	            "host":"127.0.0.1",
	            "port":7001,
	            "weight":1
	        },
	        {
	            "host":"127.0.0.1",
	            "port":7002,
	            "weight":1
	        }
	    ],
	    "checks":{
	        "active":{
	            "healthy":{
	                "interval":2,
	                "successes":1
	            },
	            "http_path":"/",
	            "timeout":5,
	            "unhealthy":{
	                "http_failures":2,
	                "interval":1
	            }
	        }
	    }
	}
}'

what mean "set the route many time or one time", I only create a route(not any plugin) and a upstream, then the route ref the upstream.

gewei2000 avatar Nov 14 '20 10:11 gewei2000

@membphis @spacewander

gewei2000 avatar Nov 14 '20 12:11 gewei2000

@gewei2000 for confirming this issue, please provide more error log(set the APISIX log level to WARN).

waiting for your response.

membphis avatar Nov 14 '20 14:11 membphis

@gewei2000 for confirming this issue, please provide more error log(set the APISIX log level to WARN).

waiting for your response.

I have already set log level to WARN, but has no more health check log

gewei2000 avatar Nov 14 '20 15:11 gewei2000

@gewei2000 do you have fixed this issue? find out the reason?

what is it?

membphis avatar Nov 16 '20 15:11 membphis

@gewei2000 do you have fixed this issue? find out the reason?

what is it?

I always think that the upstream and health check are created, then health check will be worked. In fact, after created the route and refer the upstream, the log will be output when you visit to the route.

Explain: for the configuration of nodes in the upstream, IP must exist, otherwise the request will always hang there

gewei2000 avatar Nov 17 '20 12:11 gewei2000

@gewei2000 do you have fixed this issue? find out the reason?

what is it?

The active health check target is added lazily when the upstream was first referenced, at that point, no health check information, so unhealthy endpoints might be used, especially when their weight are high or because the directional selection like consistent hash.

Or after the health checker resume these offline endpoints from unhealthy to healthy, they are offline again, before the health checker spawns probe requests and achieve the threshold, these offline (or unstable) endpoints could be selected.

tokers avatar Nov 21 '20 13:11 tokers