xianshun163 opened a new issue #5767:
URL: https://github.com/apache/apisix/issues/5767


   ### Issue description
   
   1、deploy a  service  to register to the nacos
   2、config some rule  and service and upstreams  at the apisix
   3、make a test   
   4、add some  log  at the balancer.lua, and  print the  upstream  nodes
   5、 from the log  , that  is  3 instance  in the apisix,  but  that is  one  
in the nacos.
   
   I  read the  code  nacos.lua   ,and  find the reason:  it will get the same 
service  the  follow code,
   local function get_nacos_services()
       local services = {}
       -- here we use lazy load to work around circle dependency
       local get_upstreams = require('apisix.upstream').upstreams
       local get_routes = require('apisix.router').http_routes
       local get_services = require('apisix.http.service').services
       local values = get_upstreams()
       iter_and_add_service(services, values)
       values = get_routes()
       iter_and_add_service(services, values)
       values = get_services()
       iter_and_add_service(services, values)
       return services
   end
   
   ---------------------
   and  I  try to fix it  like this, in the  local function 
fetch_full_registry(premature)  :
   local infos = get_nacos_services()
       if #infos == 0 then
           applications = up_apps
           return
       end
       table.sort(infos,function(a,b)
           return a.namespace_id .. a.group_name .. a.service_name > 
b.namespace_id .. b.group_name .. b.service_name
       end)
       local last_service_info
       for _, service_info in ipairs(infos) do
           if compareService(last_service_info,service_info) then
               goto CONTINUE
           end
           last_service_info = service_info
           local data, err
           local namespace_id = service_info.namespace_id
   
   ----------------------
   It  that   another  better way to fix it?  Thank you who can  fix it  in the 
github,     and I   can   get the code  next time。
   
   
   
   
   
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):2.10.1
   - OS (cmd: `uname -a`):
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - the plugin runner version, if the issue is about a plugin runner (cmd: 
depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks 
--version`):
   
   
   ### Steps to reproduce
   
   use  the  nacos as the discovery .
   and  add some code to print the upstream nodes  at the balancer.lua
   
   ### Actual result
   
   the  instance is the same as the nacos
   
   ### Error log
   
   no  error log
   
   ### Expected result
   
   _No response_


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