fix: disable SSL verification and add auth token for ThanosClient
This commit is contained in:
@@ -26,12 +26,31 @@ class ThanosClient:
|
|||||||
self.thanos_url = thanos_url or self._get_thanos_url()
|
self.thanos_url = thanos_url or self._get_thanos_url()
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.timeout = 30
|
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:
|
def _get_thanos_url(self) -> str:
|
||||||
"""Get Thanos URL from environment or use default."""
|
"""Get Thanos URL from environment or use default."""
|
||||||
import os
|
import os
|
||||||
return os.getenv('THANOS_URL', 'http://thanos-query:9090')
|
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]:
|
def query(self, query: str, time: str = None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Execute instant query against Thanos.
|
Execute instant query against Thanos.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ data:
|
|||||||
PROMETHEUS_URL: "https://prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
|
PROMETHEUS_URL: "https://prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
|
||||||
|
|
||||||
# URL do Thanos
|
# URL do Thanos
|
||||||
THANOS_URL: "https://thanos-query.openshift-monitoring.svc.cluster.local:9091"
|
THANOS_URL: "https://thanos-querier.openshift-monitoring.svc.cluster.local:9091"
|
||||||
|
|
||||||
# Configurações de relatório
|
# Configurações de relatório
|
||||||
REPORT_EXPORT_PATH: "/tmp/reports"
|
REPORT_EXPORT_PATH: "/tmp/reports"
|
||||||
|
|||||||
Reference in New Issue
Block a user