From cf92f0121b426863e0b6e85ddfce81623c22bfac Mon Sep 17 00:00:00 2001 From: andersonid Date: Wed, 1 Oct 2025 16:36:42 -0300 Subject: [PATCH] Fix conflicting insufficient_historical_data and historical_analysis - Check both CPU and Memory data availability before historical analysis - If either CPU or Memory has insufficient data, add warning and skip analysis - Prevent conflicting insufficient_historical_data and historical_analysis - Ensure consistent data availability requirements for workload analysis - Only proceed with P95/P99 calculations when both resources have sufficient data --- app/services/historical_analysis.py | 35 +++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/services/historical_analysis.py b/app/services/historical_analysis.py index c84f32e..e96df59 100644 --- a/app/services/historical_analysis.py +++ b/app/services/historical_analysis.py @@ -225,7 +225,38 @@ class HistoricalAnalysisService: cpu_limits_data = await self._query_prometheus(cpu_limits_query, time_range) memory_limits_data = await self._query_prometheus(memory_limits_query, time_range) - # Analyze CPU metrics for workload + # Check if we have sufficient data for both CPU and Memory before doing historical analysis + cpu_has_data = cpu_usage_data and len([p for p in cpu_usage_data if p[1] != 'NaN']) >= 3 + memory_has_data = memory_usage_data and len([p for p in memory_usage_data if p[1] != 'NaN']) >= 3 + + # If either CPU or Memory has insufficient data, add insufficient data warning + if not cpu_has_data or not memory_has_data: + if not cpu_has_data: + validations.append(ResourceValidation( + pod_name=workload_name, + namespace=namespace, + container_name="workload", + validation_type="insufficient_historical_data", + severity="warning", + message=f"Limited CPU usage data ({len([p for p in cpu_usage_data if p[1] != 'NaN']) if cpu_usage_data else 0} points) for {time_range}", + recommendation="Wait for more data points or extend time range for reliable analysis" + )) + + if not memory_has_data: + validations.append(ResourceValidation( + pod_name=workload_name, + namespace=namespace, + container_name="workload", + validation_type="insufficient_historical_data", + severity="warning", + message=f"Limited memory usage data ({len([p for p in memory_usage_data if p[1] != 'NaN']) if memory_usage_data else 0} points) for {time_range}", + recommendation="Wait for more data points or extend time range for reliable analysis" + )) + + # Don't proceed with historical analysis if any resource has insufficient data + return validations + + # Analyze CPU metrics for workload (only if we have sufficient data) if cpu_usage_data and cpu_requests_data and cpu_limits_data: cpu_validations = self._analyze_cpu_metrics( workload_name, namespace, "workload", @@ -233,7 +264,7 @@ class HistoricalAnalysisService: ) validations.extend(cpu_validations) - # Analyze memory metrics for workload + # Analyze memory metrics for workload (only if we have sufficient data) if memory_usage_data and memory_requests_data and memory_limits_data: memory_validations = self._analyze_memory_metrics( workload_name, namespace, "workload",