snapshot: refine longhorn health
This commit is contained in:
parent
a6062be60e
commit
d4a632d2e4
@ -1068,7 +1068,10 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return {}
|
||||
by_state: dict[str, int] = {}
|
||||
by_robustness: dict[str, int] = {}
|
||||
unhealthy: list[dict[str, Any]] = []
|
||||
degraded: list[dict[str, Any]] = []
|
||||
attached_count = 0
|
||||
detached_count = 0
|
||||
degraded_count = 0
|
||||
for volume in items:
|
||||
metadata = volume.get("metadata") if isinstance(volume.get("metadata"), dict) else {}
|
||||
status = volume.get("status") if isinstance(volume.get("status"), dict) else {}
|
||||
@ -1080,10 +1083,17 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
robustness = (
|
||||
status.get("robustness") if isinstance(status.get("robustness"), str) else "unknown"
|
||||
)
|
||||
state_lower = state.lower()
|
||||
robustness_lower = robustness.lower()
|
||||
by_state[state] = by_state.get(state, 0) + 1
|
||||
by_robustness[robustness] = by_robustness.get(robustness, 0) + 1
|
||||
if state.lower() != "attached" or robustness.lower() != "healthy":
|
||||
unhealthy.append(
|
||||
if state_lower == "attached":
|
||||
attached_count += 1
|
||||
elif state_lower == "detached":
|
||||
detached_count += 1
|
||||
if robustness_lower in {"degraded", "faulted"}:
|
||||
degraded_count += 1
|
||||
degraded.append(
|
||||
{
|
||||
"name": name,
|
||||
"state": state,
|
||||
@ -1092,13 +1102,15 @@ def _summarize_longhorn_volumes(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
"actual_size": status.get("actualSize"),
|
||||
}
|
||||
)
|
||||
unhealthy.sort(key=lambda item: item.get("name") or "")
|
||||
degraded.sort(key=lambda item: item.get("name") or "")
|
||||
return {
|
||||
"total": len(items),
|
||||
"by_state": by_state,
|
||||
"by_robustness": by_robustness,
|
||||
"unhealthy": unhealthy,
|
||||
"unhealthy_count": len(unhealthy),
|
||||
"attached_count": attached_count,
|
||||
"detached_count": detached_count,
|
||||
"degraded": degraded,
|
||||
"degraded_count": degraded_count,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user