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 2021/05/11 01:07:08 UTC

[GitHub] [apisix] spacewander commented on a change in pull request #4191: fix: enable etcd health-check

spacewander commented on a change in pull request #4191:
URL: https://github.com/apache/apisix/pull/4191#discussion_r629778272



##########
File path: apisix/core/config_etcd.lua
##########
@@ -545,6 +558,33 @@ local function _automatic_fetch(premature, self)
 
             local ok, err = sync_data(self)
             if err then
+                if string.find(err, "connection refused")
+                    or string.find(err, "Service Unavailable") then
+                    local etcd_cli, err = get_etcd()
+                    if not etcd_cli then
+                        error("all etcd endpoints are unhealthy: " .. err)
+                    end
+                    self.etcd_cli = etcd_cli
+                    log.warn("changed to new etcd endpoint")
+                end
+                if string.find(err, "has no healthy etcd endpoint available") then

Review comment:
       elseif

##########
File path: apisix/core/config_etcd.lua
##########
@@ -545,6 +558,33 @@ local function _automatic_fetch(premature, self)
 
             local ok, err = sync_data(self)
             if err then
+                if string.find(err, "connection refused")
+                    or string.find(err, "Service Unavailable") then
+                    local etcd_cli, err = get_etcd()
+                    if not etcd_cli then
+                        error("all etcd endpoints are unhealthy: " .. err)
+                    end
+                    self.etcd_cli = etcd_cli
+                    log.warn("changed to new etcd endpoint")
+                end
+                if string.find(err, "has no healthy etcd endpoint available") then
+                    local reconnected = false
+                    while err and not reconnected do
+                        local backoff_duration, backoff_factor, backoff_step = 1, 2, 10
+                        for _ = 0, backoff_step, 1 do
+                            ngx_sleep(backoff_duration)
+                            _, err = sync_data(self)
+                            if not string.find(err, "has no healthy etcd endpoint available") then
+                                log.warn("reconnected to etcd")
+                                reconnected = true
+                                break
+                            end
+                            backoff_duration = backoff_duration * backoff_factor
+                            log.error("no healthy etcd endpoint available, next retry after "
+                                       .. backoff_duration .. "s")
+                        end
+                    end
+                end
                 if err ~= "timeout" and err ~= "Key not found"

Review comment:
       elseif

##########
File path: apisix/core/config_etcd.lua
##########
@@ -545,6 +558,33 @@ local function _automatic_fetch(premature, self)
 
             local ok, err = sync_data(self)
             if err then
+                if string.find(err, "connection refused")
+                    or string.find(err, "Service Unavailable") then
+                    local etcd_cli, err = get_etcd()

Review comment:
       The `get_etcd` only gets the singleton of etcd client, it doesn't recreate it.

##########
File path: apisix/core/config_etcd.lua
##########
@@ -529,6 +531,17 @@ local function _automatic_fetch(premature, self)
         return
     end
 
+    if not health_check.conf then

Review comment:
       Where will `health_check.conf` be assigned?




-- 
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.

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