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/26 15:55:07 UTC

[GitHub] [apisix] Firstsawyou commented on a change in pull request #4313: feat: nacos discovery support namespace

Firstsawyou commented on a change in pull request #4313:
URL: https://github.com/apache/apisix/pull/4313#discussion_r639826338



##########
File path: t/discovery/nacos.t
##########
@@ -251,3 +251,134 @@ discovery:
 ]
 --- no_error_log
 [error]
+
+
+
+=== TEST 8: get APISIX-NACOS info from NACOS - no auth with namespace
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+  -
+    uri: /hello
+    upstream:
+      service_name: APISIX-NACOS
+      discovery_type: nacos
+      type: roundrobin
+      nacos_namespace_id: test_ns
+#END
+--- pipelined_requests eval
+[
+    "GET /hello",
+    "GET /hello",
+]
+--- response_body_like eval
+[
+    qr/server [1-2]/,
+    qr/server [1-2]/,
+]
+--- no_error_log
+[error, error]

Review comment:
       ```suggestion
   [error]
   ```

##########
File path: apisix/discovery/nacos.lua
##########
@@ -254,10 +264,10 @@ local function fetch_full_registry(premature)
         applications = up_apps
         return
     end
-
     local data, err
-    for _, service_name in ipairs(infos) do
-        data, err = get_url(base_uri, instance_list_path .. service_name .. token_param)
+    for _, service_info in ipairs(infos) do
+        local namespace_param = get_namespace_param(service_info.nacos_namespace_id);
+        data, err = get_url(base_uri, instance_list_path .. service_info.service_name .. token_param .. namespace_param)

Review comment:
       ```suggestion
           data, err = get_url(base_uri, instance_list_path .. service_info.service_name ..
                               token_param .. namespace_param)
   ```

##########
File path: t/discovery/nacos.t
##########
@@ -251,3 +251,134 @@ discovery:
 ]
 --- no_error_log
 [error]
+
+
+
+=== TEST 8: get APISIX-NACOS info from NACOS - no auth with namespace
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+  -
+    uri: /hello
+    upstream:
+      service_name: APISIX-NACOS
+      discovery_type: nacos
+      type: roundrobin
+      nacos_namespace_id: test_ns
+#END
+--- pipelined_requests eval
+[
+    "GET /hello",
+    "GET /hello",
+]
+--- response_body_like eval
+[
+    qr/server [1-2]/,
+    qr/server [1-2]/,
+]
+--- no_error_log
+[error, error]
+
+
+
+=== TEST 9: get APISIX-NACOS info from NACOS - configured in services with namespace
+--- yaml_config eval: $::yaml_config
+--- apisix_yaml
+routes:
+  -
+    uri: /hello
+    service_id: 1
+services:
+  -
+    id: 1
+    upstream:
+      service_name: APISIX-NACOS
+      discovery_type: nacos
+      type: roundrobin
+      nacos_namespace_id: test_ns
+#END
+--- pipelined_requests eval
+[
+    "GET /hello",
+    "GET /hello",
+]
+--- response_body_like eval
+[
+    qr/server [1-2]/,
+    qr/server [1-2]/,
+]
+--- no_error_log
+[error]
+
+
+
+=== TEST 10: get APISIX-NACOS info from NACOS - configured in upstreams + etcd with namespace
+--- 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/upstreams/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "service_name": "APISIX-NACOS",
+                    "discovery_type": "nacos",
+                    "type": "roundrobin",
+                    "nacos_namespace_id": "test_ns"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+                ngx.say(body)
+                return
+            end
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "uri": "/hello",
+                    "upstream_id": 1
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 11: hit with namespace
+--- extra_yaml_config
+discovery:
+  nacos:
+      host:
+        - "http://127.0.0.1:8858"
+      fetch_interval: 1
+--- pipelined_requests eval
+[
+    "GET /hello",
+    "GET /hello",
+]
+--- response_body_like eval
+[
+    qr/server [1-2]/,
+    qr/server [1-2]/,
+]
+--- no_error_log
+[error]

Review comment:
       A blank line is required at the end of the file.




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