fix: add nacos catalog fallback
This commit is contained in:
parent
2bf9a547ce
commit
e54bf80e5a
@ -329,6 +329,25 @@ def list_instances(namespace_id: str, service_name: str, group_name: str) -> lis
|
||||
return list(payload.get("hosts") or [])
|
||||
|
||||
|
||||
def catalog_instances(namespace_id: str, service_name: str, group_name: str) -> list[dict[str, Any]]:
|
||||
# 调用 catalog/instances 获取注册表视图。
|
||||
payload = nacos_request(
|
||||
"GET",
|
||||
"/nacos/v1/ns/catalog/instances",
|
||||
{
|
||||
"serviceName": service_name,
|
||||
"groupName": group_name,
|
||||
"namespaceId": namespace_id or None,
|
||||
"clusterName": NACOS_DISCOVERY_CLUSTER_NAME,
|
||||
"pageNo": "1",
|
||||
"pageSize": str(max(NACOS_PAGE_SIZE, 200)),
|
||||
},
|
||||
)
|
||||
|
||||
# 返回 list 字段。
|
||||
return list(payload.get("list") or [])
|
||||
|
||||
|
||||
def build_service_level(instance_total: int, healthy_total: int, enabled_total: int) -> str:
|
||||
# 没有实例时直接标 bad。
|
||||
if instance_total == 0:
|
||||
@ -422,6 +441,14 @@ def build_nacos_payload() -> dict[str, Any]:
|
||||
for query in queries_by_key.values():
|
||||
# 拉取当前服务实例。
|
||||
instance_items = list_instances(namespace["namespaceId"], query["registryName"], query["groupName"])
|
||||
|
||||
# 常规实例接口为空时,再走 catalog 视图兜底。
|
||||
if not instance_items:
|
||||
instance_items = catalog_instances(
|
||||
namespace["namespaceId"],
|
||||
query["registryName"],
|
||||
query["groupName"],
|
||||
)
|
||||
# 归一化实例结构。
|
||||
normalized_instances: list[dict[str, Any]] = []
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user