membphis commented on code in PR #12906:
URL: https://github.com/apache/apisix/pull/12906#discussion_r2693728184


##########
apisix/discovery/eureka/init.lua:
##########
@@ -145,26 +148,36 @@ local function fetch_full_registry(premature)
         return
     end
 
-    local request_uri, basic_auth = service_info()
-    if not request_uri then
+    local endpoints = build_endpoints()
+    if not endpoints or #endpoints == 0 then
         return
     end
 
-    local res, err = request(request_uri, basic_auth, "GET", "apps")
-    if not res then
-        log.error("failed to fetch registry", err)
-        return
+    -- try endpoints from random position, failover on error
+    local selected_endpoint
+    local selected_body
+    local num_endpoints = #endpoints
+    local start = math_random(num_endpoints)
+    for i = 0, num_endpoints - 1 do
+        local endpoint = endpoints[(start + i - 1) % num_endpoints + 1]
+        local r, e = request(endpoint.url, endpoint.auth, "GET", "apps")
+        if r and r.body and r.status == 200 then
+            selected_endpoint = endpoint
+            selected_body = r.body
+            break
+        end
+        log.error("failed to fetch registry from ", endpoint.url, ": ",
+                 e or (r and ("status=" .. tostring(r.status)) or "unknown"))
     end
 
-    if not res.body or res.status ~= 200 then
-        log.error("failed to fetch registry, status = ", res.status)
+    if not selected_endpoint then
+        log.error("failed to fetch registry from all eureka hosts")

Review Comment:
   need more information, eg: no healthy registry, the count of all hosts 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to