optimize: reduce cluster/status API response size by removing heavy pod data
This commit is contained in:
@@ -101,77 +101,10 @@ async def get_cluster_status(
|
||||
# Get resource utilization information
|
||||
resource_utilization_info = await prometheus_client.get_cluster_resource_utilization()
|
||||
|
||||
# Get VPA recommendations
|
||||
vpa_recommendations = await k8s_client.get_vpa_recommendations()
|
||||
|
||||
# Group pods by namespace for the frontend
|
||||
namespaces_data = {}
|
||||
pod_validations_map = {}
|
||||
|
||||
# Create a map of pod validations (static + historical)
|
||||
for validation in all_validations:
|
||||
pod_key = f"{validation.namespace}/{validation.pod_name}"
|
||||
if pod_key not in pod_validations_map:
|
||||
pod_validations_map[pod_key] = []
|
||||
pod_validations_map[pod_key].append(validation)
|
||||
|
||||
for pod in pods:
|
||||
namespace = pod.namespace
|
||||
if namespace not in namespaces_data:
|
||||
namespaces_data[namespace] = {
|
||||
'namespace': namespace,
|
||||
'pods': {},
|
||||
'total_validations': 0,
|
||||
'severity_breakdown': {'error': 0, 'warning': 0, 'info': 0}
|
||||
}
|
||||
|
||||
# Add pod to namespace
|
||||
pod_name = pod.name
|
||||
pod_key = f"{namespace}/{pod_name}"
|
||||
pod_validations = pod_validations_map.get(pod_key, [])
|
||||
|
||||
# Convert pod to the format expected by frontend
|
||||
pod_data = {
|
||||
'pod_name': pod_name,
|
||||
'namespace': namespace,
|
||||
'phase': pod.phase,
|
||||
'node_name': pod.node_name,
|
||||
'containers': [],
|
||||
'validations': []
|
||||
}
|
||||
|
||||
# Add containers
|
||||
for container in pod.containers:
|
||||
container_data = {
|
||||
'name': container['name'],
|
||||
'image': container['image'],
|
||||
'resources': container['resources']
|
||||
}
|
||||
pod_data['containers'].append(container_data)
|
||||
|
||||
# Add validations for this pod
|
||||
for validation in pod_validations:
|
||||
validation_data = {
|
||||
'rule_name': validation.validation_type,
|
||||
'namespace': namespace,
|
||||
'message': validation.message,
|
||||
'recommendation': validation.recommendation,
|
||||
'severity': validation.severity
|
||||
}
|
||||
pod_data['validations'].append(validation_data)
|
||||
|
||||
# Update namespace severity breakdown
|
||||
namespaces_data[namespace]['severity_breakdown'][validation.severity] += 1
|
||||
namespaces_data[namespace]['total_validations'] += 1
|
||||
|
||||
namespaces_data[namespace]['pods'][pod_name] = pod_data
|
||||
|
||||
# Convert to list format expected by frontend
|
||||
namespaces_list = list(namespaces_data.values())
|
||||
|
||||
# Count total errors and warnings
|
||||
total_errors = sum(ns['severity_breakdown']['error'] for ns in namespaces_list)
|
||||
total_warnings = sum(ns['severity_breakdown']['warning'] for ns in namespaces_list)
|
||||
# Skip heavy data processing for dashboard performance
|
||||
# Count total errors and warnings from validations
|
||||
total_errors = sum(1 for v in all_validations if v.severity == 'error')
|
||||
total_warnings = sum(1 for v in all_validations if v.severity == 'warning')
|
||||
|
||||
# Process overcommit information
|
||||
cpu_overcommit_percent = 0
|
||||
@@ -226,6 +159,7 @@ async def get_cluster_status(
|
||||
if cpu_requests > 0 and memory_requests > 0:
|
||||
resource_utilization = 75 # Placeholder fallback
|
||||
|
||||
# Return lightweight data for dashboard
|
||||
return {
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"total_pods": len(pods),
|
||||
@@ -233,7 +167,6 @@ async def get_cluster_status(
|
||||
"total_nodes": len(nodes_info) if nodes_info else 0,
|
||||
"total_errors": total_errors,
|
||||
"total_warnings": total_warnings,
|
||||
"namespaces": namespaces_list,
|
||||
"overcommit": {
|
||||
"cpu_overcommit_percent": cpu_overcommit_percent,
|
||||
"memory_overcommit_percent": memory_overcommit_percent,
|
||||
|
||||
Reference in New Issue
Block a user