From 8307eeb646ee62227fabfafdc85c29a8e74fe7f1 Mon Sep 17 00:00:00 2001 From: andersonid Date: Mon, 29 Sep 2025 13:47:58 -0300 Subject: [PATCH] Fix Prometheus SSL and authentication in historical analysis --- app/services/historical_analysis.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/services/historical_analysis.py b/app/services/historical_analysis.py index c2b30e9..d55d0e2 100644 --- a/app/services/historical_analysis.py +++ b/app/services/historical_analysis.py @@ -364,7 +364,23 @@ class HistoricalAnalysisService: async def _query_prometheus(self, query: str, start_time: datetime, end_time: datetime) -> List[Dict]: """Execute query in Prometheus""" try: - async with aiohttp.ClientSession() as session: + # Get service account token for authentication + token = None + try: + with open('/var/run/secrets/kubernetes.io/serviceaccount/token', 'r') as f: + token = f.read().strip() + except FileNotFoundError: + logger.warning("Service account token not found, proceeding without authentication") + + # Create headers with token if available + headers = {} + if token: + headers['Authorization'] = f'Bearer {token}' + + # Create session with SSL verification disabled for self-signed certificates + connector = aiohttp.TCPConnector(ssl=False) + + async with aiohttp.ClientSession(connector=connector, headers=headers) as session: params = { 'query': query, 'start': start_time.timestamp(), @@ -375,7 +391,8 @@ class HistoricalAnalysisService: async with session.get( f"{self.prometheus_url}/api/v1/query_range", params=params, - timeout=aiohttp.ClientTimeout(total=30) + timeout=aiohttp.ClientTimeout(total=30), + ssl=False ) as response: if response.status == 200: data = await response.json()