apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.43k stars 2.5k forks source link

feat: support health check for TCP upstreams #10826

Open MonkeyDLufy opened 9 months ago

MonkeyDLufy commented 9 months ago

Description

As a tcp server user, I want to use apisix for proxy tcp servers. So I need the stream upstream can support active health check. But I try and found that, the active health check seem only support for http, it can't work on tcp.

lakshya8066 commented 9 months ago

Hi @MonkeyDLufy please check the docs here if this is what you are looking for https://apisix.apache.org/docs/apisix/next/tutorials/health-check/#active-check

Are you having any specific problems in configuring it?

MonkeyDLufy commented 9 months ago

Hi @MonkeyDLufy please check the docs here if this is what you are looking for https://apisix.apache.org/docs/apisix/next/tutorials/health-check/#active-check

Are you having any specific problems in configuring it?

curl http://127.0.0.1:9180/apisix/admin/stream_routes/1 -X PUT -d ' { "server_port": 9100, "upstream": { "nodes": { "10.178.178.178:80": 1, "10.187.187.187:80": 1 }, "type": "roundrobin", "scheme": "tcp", "checks": { "active": { "type": "tcp", "unhealthy": { "interval": 1, "tcp_failures": 3 }, "healthy": { "interval": 2, "successes": 1 } } } } }'

This is my config. I used tcpdump to capture packets and observed that the probe packets for active health checks were not sent. Among the two IP addresses in the example, one of them is not reachable. I expected it to be circuit broken and not receive any traffic, but apisix still sent traffic to it until the connection timed out and then retried with another available node.

shreemaan-abhishek commented 8 months ago

AFAIK, healthchek for TCP upstreams isn't supported.

MonkeyDLufy commented 8 months ago

Thank you for helping me confirm this information. I hope that Apisix can provide support for this feature in the future

theweakgod commented 8 months ago

@shreemaan-abhishek I can handle this issue, can you assign this to me?

MonkeyDLufy commented 8 months ago

I think health check for UDP upstreams is also necessary.

fatihusta commented 3 months ago

Hi I worked on this issue. Stream proxy health check works fine now. Here is my branch. https://github.com/fatihusta/apisix/tree/stream-proxy-healthcheck-support @shreemaan-abhishek could you please check my branch. Is this right way to do this or not? Please give me advice. I will send the PR after your review.

shreemaan-abhishek commented 3 months ago

@fatihusta it would be much better if you write your proposal first.

fatihusta commented 3 months ago

@fatihusta it would be much better if you write your proposal first.

I re-imlemented this PR. Also I added new control API functions. Control API is in http context. upstream-healthcheck-stream shared-dict is in stream context. There is no access between http and stream context for shared-dicts. So I added unix domain socket in stream context. After that I access the unix socket from control API. Is this right way to do this or not?