Skip to content

feat(nacos): add metadata filtering support to nacos discovery #12445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

beardnick
Copy link
Contributor

@beardnick beardnick commented Jul 19, 2025

Description

Add metadata filtering support to nacos discovery.

Which issue(s) this PR fixes:

Fixes #12392

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

- Add metadata validation schema in schema_def.lua
- Implement metadata filtering logic in nacos discovery
- Add comprehensive test cases for metadata validation
- Update documentation for metadata filtering feature
- Fix lint issues and code formatting
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 19, 2025
@jizhuozhi
Copy link

There seems to be duplicate work #12448 (coincidentally, we have similar demands). According to my understanding of apisix, all routes share the same service discovery results, so it is not suitable to filter in the discovery.

@Baoyuantop
Copy link
Contributor

There seems to be duplicate work #12448 (coincidentally, we have similar demands). According to my understanding of apisix, all routes share the same service discovery results, so it is not suitable to filter in the discovery.

I don't think it's a duplicate at the moment. Using metadata to filter nacos services is a very useful feature. For more information, you can check the related issue.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what these two parameters mean?




=== TEST 28: get APISIX-NACOS info from NACOS - metadata filtering lane=b (only server2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is somewhat repetitive, I think the configuration can be changed to

discovery_args:
    metadata:

Test the behavior of metadata being empty.

@jizhuozhi
Copy link

I don't think it's a duplicate at the moment. Using metadata to filter nacos services is a very useful feature. For more information, you can check the related issue.

Got it, thanks for you reply :)

This is used to filter when pulling the service list from service discovery to avoid pulling a large number of useless instances. We also have similar demands when using Consul. I will try to add the following.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

discovery_args not work in upstream when using nacos
3 participants