SkyeYoung commented on code in PR #12445:
URL: https://github.com/apache/apisix/pull/12445#discussion_r2241982959


##########
apisix/discovery/nacos/init.lua:
##########
@@ -355,6 +374,19 @@ function _M.nodes(service_name, discovery_args)
         return nil
     end
     local nodes = core.json.decode(value)
+
+    -- Apply metadata filtering if specified
+    local route_metadata = discovery_args and discovery_args.metadata
+    if route_metadata and next(route_metadata) then
+        local filtered_nodes = {}
+        for _, node in ipairs(nodes) do
+            if metadata_contains(node.metadata, route_metadata) then
+                core.table.insert(filtered_nodes, node)
+            end
+        end
+        return filtered_nodes
+    end
+

Review Comment:
   ditto



##########
apisix/discovery/nacos/init.lua:
##########
@@ -54,6 +55,23 @@ local function get_key(namespace_id, group_name, 
service_name)
     return namespace_id .. '.' .. group_name .. '.' .. service_name
 end
 
+
+local function metadata_contains(host_metadata, route_metadata)
+    if not route_metadata or not next(route_metadata) then
+        return true
+    end
+    if not host_metadata or not next(host_metadata) then
+        return false
+    end
+
+    for k, v in pairs(route_metadata) do
+        if host_metadata[k] ~= v then
+            return false
+        end
+    end
+    return true
+end

Review Comment:
   Can u abstract this func into a separate file for reuse?



-- 
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: notifications-unsubscr...@apisix.apache.org

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

Reply via email to