fix: disable SSL verification and add auth token for ThanosClient

This commit is contained in:
2025-10-06 13:48:15 -03:00
parent f9385c201f
commit ea1dae9e09
2 changed files with 20 additions and 1 deletions

View File

@@ -26,12 +26,31 @@ class ThanosClient:
self.thanos_url = thanos_url or self._get_thanos_url()
self.session = requests.Session()
self.session.timeout = 30
# Disable SSL verification for self-signed certificates
self.session.verify = False
# Disable SSL warnings
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Add service account token for authentication
self._add_auth_token()
def _get_thanos_url(self) -> str:
"""Get Thanos URL from environment or use default."""
import os
return os.getenv('THANOS_URL', 'http://thanos-query:9090')
def _add_auth_token(self):
"""Add service account token for authentication."""
try:
with open('/var/run/secrets/kubernetes.io/serviceaccount/token', 'r') as f:
token = f.read().strip()
self.session.headers.update({
'Authorization': f'Bearer {token}'
})
except FileNotFoundError:
logger.warning("Service account token not found, proceeding without authentication")
def query(self, query: str, time: str = None) -> Dict[str, Any]:
"""
Execute instant query against Thanos.