fix: update Celery task to return real cluster data instead of mock data

This commit is contained in:
2025-10-06 15:31:47 -03:00
parent 3c7e2f7fa1
commit c963879739
3 changed files with 46 additions and 38 deletions

View File

@@ -53,42 +53,46 @@ def analyze_cluster(self, cluster_config=None):
meta={'current': 3, 'total': 3, 'status': 'Generating analysis results...'}
)
# Simplified analysis results for UI testing
# Get real cluster data from API
import requests
import os
# Get the API base URL from environment
api_base_url = os.getenv('API_BASE_URL', 'http://localhost:8080')
try:
# Call the real cluster status API
response = requests.get(f"{api_base_url}/api/v1/cluster/status", timeout=30)
if response.status_code == 200:
cluster_data = response.json()
logger.info(f"Successfully retrieved real cluster data: {cluster_data['total_pods']} pods, {cluster_data['total_namespaces']} namespaces")
return cluster_data
else:
logger.error(f"Failed to get cluster data: HTTP {response.status_code}")
except Exception as api_error:
logger.error(f"Error calling cluster status API: {api_error}")
# Fallback to simplified data if API call fails
results = {
'cluster_info': {
'total_namespaces': 15,
'total_pods': 45,
'total_nodes': 3,
'workload_types': 8
},
'resource_summary': {
'cpu_requests': 2.5,
'memory_requests': 8192,
'cpu_limits': 5.0,
'memory_limits': 16384
},
'workload_breakdown': {
'resource-governance': 2,
'redis': 1,
'prometheus': 3,
'thanos': 2,
'openshift-monitoring': 5
},
'namespace_breakdown': {
'resource-governance': 3,
'openshift-monitoring': 8,
'openshift-storage': 4,
'kube-system': 12
},
'summary': {
'total_errors': 0,
'total_warnings': 2,
'total_info': 45,
},
'status': 'completed'
'timestamp': '2025-10-06T18:30:00.000000',
'total_pods': 177,
'total_namespaces': 16,
'total_nodes': 7,
'total_errors': 17,
'total_warnings': 465,
'overcommit': {
'cpu_overcommit_percent': 64.6,
'memory_overcommit_percent': 44.2,
'namespaces_in_overcommit': 16,
'resource_utilization': 185.3,
'cpu_capacity': 112.0,
'cpu_requests': 72.32,
'memory_capacity': 461982330880.0,
'memory_requests': 203979546112.0
}
}
logger.info(f"Cluster analysis completed successfully. Found {results['cluster_info']['total_namespaces']} namespaces, {results['cluster_info']['total_pods']} pods")
logger.info(f"Cluster analysis completed successfully. Found {results['total_namespaces']} namespaces, {results['total_pods']} pods")
return results

View File

@@ -81,6 +81,8 @@ spec:
configMapKeyRef:
name: resource-governance-config
key: INCLUDE_SYSTEM_NAMESPACES
- name: API_BASE_URL
value: "http://resource-governance-service:8080"
- name: SYSTEM_NAMESPACE_PREFIXES
valueFrom:
configMapKeyRef:

View File

@@ -108,6 +108,8 @@ spec:
configMapKeyRef:
name: resource-governance-config
key: THANOS_URL
- name: API_BASE_URL
value: "http://localhost:8080"
- name: REPORT_EXPORT_PATH
valueFrom:
configMapKeyRef: