Skip to content

fix: 查询实例列表时支持按 clusters 参数过滤#290

Open
lly835 wants to merge 1 commit intonacos-group:masterfrom
lly835:fix/clusters-filter
Open

fix: 查询实例列表时支持按 clusters 参数过滤#290
lly835 wants to merge 1 commit intonacos-group:masterfrom
lly835:fix/clusters-filter

Conversation

@lly835
Copy link

@lly835 lly835 commented Feb 26, 2026

修复问题

修复 #210:subscribe 以及 selectOneHealthyInstance 传递 clusters 参数后未生效的问题。

原因分析

Service::get_instance_list 方法接收了 cluster_names 参数(变量名为 _cluster_names,带下划线前缀),但方法体内直接调用 get_all_instances 返回所有实例,完全忽略了 clusters 过滤条件。

修复方案

cluster_names 非空时,在遍历实例时增加 cluster_names.contains(&x.cluster_name) 过滤条件,只返回属于指定 cluster 的实例;当 cluster_names 为空时保持原有行为,返回所有实例。

修复 nacos-group#210:subscribe 以及 selectOneHealthyInstance 传递 clusters 参数后未生效的问题。

原因:Service::get_instance_list 方法接收了 cluster_names 参数但未使用,
直接调用 get_all_instances 返回所有实例,导致 clusters 过滤完全失效。

修复:当 cluster_names 非空时,按 cluster_name 过滤实例列表;为空时保持原有行为。
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants