tzssangglass commented on a change in pull request #6282: URL: https://github.com/apache/apisix/pull/6282#discussion_r816438024
########## File path: t/discovery/nacos2.t ########## @@ -112,3 +112,105 @@ GET /hello --- error_code_like: ^(?:50\d)$ --- error_log nacos login fail + + + +=== TEST 3: same service is registered in route, service and upstream, de-duplicate +--- yaml_config +apisix: + node_listen: 1984 + admin_key: null +--- extra_yaml_config +discovery: + nacos: + host: + - "http://127.0.0.1:8858" + fetch_interval: 1 +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/hello", + "upstream": { + "service_name": "APISIX-NACOS", + "discovery_type": "nacos", + "scheme": "http", + "type": "roundrobin", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PUT, + [[{ + "upstream": { + "type": "roundrobin", + "scheme": "http", + "discovery_type": "nacos", + "pass_host": "pass", + "service_name": "APISIX-NACOS", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + local code, body = t('/apisix/admin/upstreams/1', + ngx.HTTP_PUT, + [[{ + "type": "roundrobin", + "scheme": "http", + "discovery_type": "nacos", + "pass_host": "pass", + "service_name": "APISIX-NACOS", + "discovery_args": { + "namespace_id": "public", + "group_name": "DEFAULT_GROUP" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + + ngx.sleep(1.5) + + local json_decode = require("toolkit.json").decode + local http = require "resty.http" + local httpc = http.new() + local dump_uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/v1/discovery/nacos/dump" + local res, err = httpc:request_uri(dump_uri, { method = "GET"}) + if err then + ngx.log(ngx.ERR, err) + ngx.status = res.status + return + end + + local body = json_decode(res.body) + local services = body.services + local service = services["public"]["DEFAULT_GROUP"]["APISIX-NACOS"] + local number = table.getn(service) + ngx.say(number) + } + } +--- response_body +2 Review comment: In fact, it is 2 instances of the same service. In docker-compose, the 2 service instances are started with the same namespace, group and service name, but have different exposed ports, which is equivalent to different instances of the same service registered to nacos. docker-compose: https://github.com/apache/apisix/blob/48398d3f1501fe425b08673609605ea9d8039f54/ci/pod/docker-compose.yml#L230-L263 these 2 service instances on nacos-dashboard:  Before de-duplication, the number of APISIX fetches to these two services is 6: https://github.com/apache/apisix/runs/5180101415?check_suite_focus=true  6 = 2 instances * ( in route + in service + in upstream ) -- 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]
