NeoSunJZ opened a new issue, #12819:
URL: https://github.com/apache/apisix/issues/12819
### Current Behavior
I am using Nacos as the service discovery registry for APISIX. My service
instances in Nacos are registered with custom metadata (e.g., developer:
neosunjz, version: v1).
However, when APISIX fetches the service list from Nacos, the metadata
information is discarded.
When I attempt to access the node information in a custom Lua plugin, the
resulting node objects only contain host, port, and weight. The metadata field
is nil.
Root Cause Analysis: I checked the source code of
apisix/discovery/nacos/init.lua (tested on version 3.8.0). In the
fetch_from_host function, the code explicitly constructs the node table but
omits the metadata field from the Nacos response.
Snippet from apisix/discovery/nacos/init.lua:
```
-- Current implementation
local node = {
host = host.ip,
port = host.port,
weight = host.weight or default_weight,
}
-- Metadata is ignored here unless it's for gRPC port
```
### Expected Behavior
The Nacos discovery plugin should propagate the metadata field from the
Nacos service instance to the APISIX internal node object.
This is critical for advanced routing scenarios, such as:
- Canary releases based on metadata versions.
- Development environment isolation (routing traffic to a specific
developer's local machine based on metadata tags).
Proposed Fix: The nacos/init.lua should include the metadata assignment:
```
local node = {
host = host.ip,
port = host.port,
weight = host.weight or default_weight,
metadata = host.metadata -- <--- This line is missing
}
```
### Error Logs
_No response_
### Steps to Reproduce
- Start Nacos and register a service with metadata (e.g., {"developer":
"test"}).
- Configure APISIX to use Nacos discovery in config.yaml.
- Create a Route using this Nacos service as the upstream.
- Use a serverless-pre-function or custom plugin to inspect the resolved
nodes:
```
local has_nacos, nacos = pcall(require, "apisix.discovery.nacos")
local route = ctx.matched_route
local up_conf = route.value.upstream
local service_name = up_conf.service_name
local nodes = nacos.nodes(service_name)
for _, node in ipairs(nodes) do
core.log.warn("Node metadata: ", core.json.encode(node.metadata))
end
```
- Check the error.log. The output is null or nil, even though Nacos has the
data.
### Environment
APISIX version: 3.8.0
Operating System: Linux (Docker apache/apisix:3.8.0)
OpenResty / Nginx version: (Default in Docker image)
Etcd version: (Default)
Nacos version: 2.3.2
--
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]