Skip to content

Commit 295ffb0

Browse files
committed
fix: 查询实例列表时支持按 clusters 参数过滤
修复 #210:subscribe 以及 selectOneHealthyInstance 传递 clusters 参数后未生效的问题。 原因:Service::get_instance_list 方法接收了 cluster_names 参数但未使用, 直接调用 get_all_instances 返回所有实例,导致 clusters 过滤完全失效。 修复:当 cluster_names 非空时,按 cluster_name 过滤实例列表;为空时保持原有行为。
1 parent 098703e commit 295ffb0

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/naming/service.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,23 @@ impl Service {
392392

393393
pub(crate) fn get_instance_list(
394394
&self,
395-
_cluster_names: Vec<String>,
395+
cluster_names: Vec<String>,
396396
only_healthy: bool,
397397
only_enable: bool,
398398
) -> Vec<Arc<Instance>> {
399-
self.get_all_instances(only_healthy, only_enable)
399+
if cluster_names.is_empty() {
400+
self.get_all_instances(only_healthy, only_enable)
401+
} else {
402+
self.instances
403+
.values()
404+
.filter(|x| {
405+
(x.enabled || !only_enable)
406+
&& (x.healthy || !only_healthy)
407+
&& cluster_names.contains(&x.cluster_name)
408+
})
409+
.cloned()
410+
.collect::<Vec<_>>()
411+
}
400412
}
401413

402414
pub fn get_service_key(&self) -> ServiceKey {

0 commit comments

Comments
 (0)