fix: correct historical analysis endpoint and Chart.js loading

- Fix endpoint to use get_all_pods() instead of non-existent get_pods_by_selector()
- Move Chart.js scripts to end of body for proper loading order
- Add proper error handling for workload not found cases
- Ensure Chart.js is available before creating graphs
This commit is contained in:
2025-10-02 15:47:13 -03:00
parent e1dae22e98
commit c6f69f85c9
2 changed files with 11 additions and 9 deletions

View File

@@ -1268,13 +1268,14 @@ async def get_workload_historical_details(
): ):
"""Get detailed historical analysis for a specific workload""" """Get detailed historical analysis for a specific workload"""
try: try:
# Get pods for this workload # Get all pods and filter by namespace and workload
pods = await k8s_client.get_pods_by_selector( all_pods = await k8s_client.get_all_pods()
namespace=namespace, workload_pods = [
selector={'app': workload} pod for pod in all_pods
) if pod.namespace == namespace and _extract_workload_name(pod.name) == workload
]
if not pods: if not workload_pods:
raise HTTPException(status_code=404, detail=f"Workload {workload} not found in namespace {namespace}") raise HTTPException(status_code=404, detail=f"Workload {workload} not found in namespace {namespace}")
# Get historical data from Prometheus # Get historical data from Prometheus

View File

@@ -17,9 +17,6 @@
<!-- Font Awesome for icons --> <!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Chart.js for historical analysis graphs -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<!-- Custom OpenShift-like styles --> <!-- Custom OpenShift-like styles -->
<style> <style>
@@ -1668,5 +1665,9 @@
`; `;
} }
</script> </script>
<!-- Chart.js for historical analysis graphs -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
</body> </body>
</html> </html>