atlasbot: summarize workload health in snapshot
This commit is contained in:
parent
daf17968e9
commit
b429975699
@ -80,6 +80,7 @@ def build_summary(snapshot: dict[str, Any] | None) -> dict[str, Any]:
|
||||
summary.update(_build_namespace_nodes(snapshot))
|
||||
summary.update(_build_node_pods(snapshot))
|
||||
summary.update(_build_pod_issues(snapshot))
|
||||
summary.update(_build_workload_health(snapshot))
|
||||
summary.update(_build_events(snapshot))
|
||||
summary.update(_build_postgres(metrics))
|
||||
summary.update(_build_hottest(metrics))
|
||||
@ -190,6 +191,24 @@ def _build_pod_issues(snapshot: dict[str, Any]) -> dict[str, Any]:
|
||||
return {"pod_issues": pod_issues}
|
||||
|
||||
|
||||
def _build_workload_health(snapshot: dict[str, Any]) -> dict[str, Any]:
|
||||
health = snapshot.get("workloads_health")
|
||||
if not isinstance(health, dict) or not health:
|
||||
return {}
|
||||
deployments = health.get("deployments")
|
||||
statefulsets = health.get("statefulsets")
|
||||
daemonsets = health.get("daemonsets")
|
||||
if not isinstance(deployments, dict) or not isinstance(statefulsets, dict) or not isinstance(daemonsets, dict):
|
||||
return {}
|
||||
return {
|
||||
"workloads_health": {
|
||||
"deployments": deployments,
|
||||
"statefulsets": statefulsets,
|
||||
"daemonsets": daemonsets,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _build_events(snapshot: dict[str, Any]) -> dict[str, Any]:
|
||||
events = snapshot.get("events")
|
||||
if not isinstance(events, dict) or not events:
|
||||
@ -496,6 +515,25 @@ def _format_pod_issue_top(pod_issues: dict[str, Any]) -> str:
|
||||
return "pod_issues_top: " + "; ".join(top) if top else ""
|
||||
|
||||
|
||||
def _append_workload_health(lines: list[str], summary: dict[str, Any]) -> None:
|
||||
health = summary.get("workloads_health") if isinstance(summary.get("workloads_health"), dict) else {}
|
||||
if not health:
|
||||
return
|
||||
deployments = health.get("deployments") if isinstance(health.get("deployments"), dict) else {}
|
||||
statefulsets = health.get("statefulsets") if isinstance(health.get("statefulsets"), dict) else {}
|
||||
daemonsets = health.get("daemonsets") if isinstance(health.get("daemonsets"), dict) else {}
|
||||
total_not_ready = 0
|
||||
for entry in (deployments, statefulsets, daemonsets):
|
||||
total_not_ready += int(entry.get("not_ready") or 0)
|
||||
lines.append(
|
||||
"workloads_not_ready: "
|
||||
f"deployments={deployments.get('not_ready', 0)}, "
|
||||
f"statefulsets={statefulsets.get('not_ready', 0)}, "
|
||||
f"daemonsets={daemonsets.get('not_ready', 0)} "
|
||||
f"(total={total_not_ready})"
|
||||
)
|
||||
|
||||
|
||||
def _append_node_usage_stats(lines: list[str], summary: dict[str, Any]) -> None:
|
||||
metrics = summary.get("metrics") if isinstance(summary.get("metrics"), dict) else {}
|
||||
stats = metrics.get("node_usage_stats") if isinstance(metrics.get("node_usage_stats"), dict) else {}
|
||||
@ -690,6 +728,7 @@ def summary_text(snapshot: dict[str, Any] | None) -> str:
|
||||
_append_namespace_nodes(lines, summary)
|
||||
_append_node_pods(lines, summary)
|
||||
_append_pod_issues(lines, summary)
|
||||
_append_workload_health(lines, summary)
|
||||
_append_events(lines, summary)
|
||||
_append_node_usage_stats(lines, summary)
|
||||
_append_namespace_usage(lines, summary)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user