You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/22 01:57:50 UTC

[GitHub] [apisix] Raymond0331 commented on issue #7964: help request: no checker for upstreams

Raymond0331 commented on issue #7964:
URL: https://github.com/apache/apisix/issues/7964#issuecomment-1254414525

   I've try to reproduce in openresty use  by lua-resty-upstream-healthcheck script it works.
   
   **init_worker_by_lua_block code like the below:** 
   
   ```
   
   init_worker_by_lua_block {
           local hc = require "resty.upstream.healthcheck"
           local ok, err = hc.spawn_checker{
               shm = "myhealthcheck",  -- defined by "lua_shared_dict"
               upstream = "dvsapi", -- defined by "upstream"
               type = "http",
   
               http_req = "GET /dashboard HTTP/1.0\r\nHost: dvsapi\r\n\r\n" , --.. "{\"query\":\"query IntrospectionQuery {\\n      __schema {\\n        subscriptionType { name }\\n      }\\n    }\",\"variables\":{}}" .. "\r\n\r\n",
               interval = 3000,  -- run the check cycle every 3 sec
               timeout = 3000,   -- 3 sec is the timeout for network operations
               fall = 3,  -- # of successive failures before turning a peer down
               rise = 2,  -- # of successive successes before turning a peer up
               valid_statuses = {400},  -- a list valid HTTP status code
               concurrency = 10,  -- concurrency level for test requests
           }
           ngx.log(ngx.ERR, "ok status: ", ok)
           if not ok then
               ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
               return
           end
   }
   ```
   
   **the nginx.conf, like the below:**
   ```
   upstream dvsapi {
       server prod-xxx-xxx-ip1.xxxxxx.com:443;
       server prod-xxx-xxx-ip2.xxxxxx.com:443;
       keepalive 1024;
   }
   
   
   
   server {
       listen       90;
       server_name  localhost;
   
       location / {
   	proxy_set_header HOST $host;
   	proxy_set_header X-Forwarded-Proto $scheme;
      	proxy_set_header X-Real-IP $remote_addr;
      	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_pass          https://dvsapi;
        }
   
       location /server/status {
           access_log off;
           allow 127.0.0.1;
   
           default_type text/plain;
           content_by_lua_block {
               local hc = require "resty.upstream.healthcheck"
               ngx.say("Nginx Worker PID: ", ngx.worker.pid())
               ngx.print(hc.status_page())
           }
       }
   }
   ```
   
   check the server status:
   `curl localhost:90/server/status`, the results: 
   
   Nginx Worker PID: 16103
   Upstream dvsapi
       Primary Peers
           xx.xx.xxx.95:443 up
           xx.xx.xxx.20:443 up
       Backup Peers
   
   
   Am i do something wrong in APISIX?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org