Fix Prometheus SSL and authentication in historical analysis

This commit is contained in:
2025-09-29 13:47:58 -03:00
parent 6b2f8de6b6
commit 8307eeb646

View File

@@ -364,7 +364,23 @@ class HistoricalAnalysisService:
async def _query_prometheus(self, query: str, start_time: datetime, end_time: datetime) -> List[Dict]: async def _query_prometheus(self, query: str, start_time: datetime, end_time: datetime) -> List[Dict]:
"""Execute query in Prometheus""" """Execute query in Prometheus"""
try: 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 = { params = {
'query': query, 'query': query,
'start': start_time.timestamp(), 'start': start_time.timestamp(),
@@ -375,7 +391,8 @@ class HistoricalAnalysisService:
async with session.get( async with session.get(
f"{self.prometheus_url}/api/v1/query_range", f"{self.prometheus_url}/api/v1/query_range",
params=params, params=params,
timeout=aiohttp.ClientTimeout(total=30) timeout=aiohttp.ClientTimeout(total=30),
ssl=False
) as response: ) as response:
if response.status == 200: if response.status == 200:
data = await response.json() data = await response.json()