OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: add env to set opensearch pool maxsize (#2218)
Lucas Oliveiraa95cb00d1ee3
diff --git a/src/config/settings.py b/src/config/settings.pyindex ac241dc30..75730cbab 100644--- a/src/config/settings.py+++ b/src/config/settings.py@@ -31,6 +31,8 @@ logger = get_logger(__name__)OPENSEARCH_HOST = os.getenv("OPENSEARCH_HOST", "localhost")OPENSEARCH_PORT = get_env_int("OPENSEARCH_PORT", 9200)OPENSEARCH_URL = f"https://{OPENSEARCH_HOST}:{OPENSEARCH_PORT}"+_os_pool_maxsize = get_env_int("OPENSEARCH_POOL_MAXSIZE")+OPENSEARCH_POOL_MAXSIZE: int = max(10 if _os_pool_maxsize is None else _os_pool_maxsize, 1)# Optional: Langflow-specific OpenSearch endpointLANGFLOW_OPENSEARCH_HOST = os.getenv("LANGFLOW_OPENSEARCH_HOST")@@ -1011,6 +1013,7 @@ class AppClients:ssl_assert_fingerprint=None,http_auth=os_auth,http_compress=True,+ pool_maxsize=OPENSEARCH_POOL_MAXSIZE,)# Initialize patched OpenAI client if API key is available@@ -1687,6 +1690,7 @@ class AppClients:timeout=30, # 30 second timeoutmax_retries=3,retry_on_timeout=True,+ pool_maxsize=OPENSEARCH_POOL_MAXSIZE,)def create_basic_opensearch_client(self, username: str, password: str):@@ -1703,6 +1707,7 @@ class AppClients:timeout=30,max_retries=3,retry_on_timeout=True,+ pool_maxsize=OPENSEARCH_POOL_MAXSIZE,)def create_user_opensearch_client(self, jwt_token: str):diff --git a/tests/unit/config/test_opensearch_pool_maxsize.py b/tests/unit/config/test_opensearch_pool_maxsize.pynew file mode 100644index 000000000..5af7144d2--- /dev/null+++ b/tests/unit/config/test_opensearch_pool_maxsize.py@@ -0,0 +1,106 @@+"""Regression tests for OpenSearch connection pool maxsize configuration."""++import os+import subprocess+import sys+from pathlib import Path++ROOT = Path(__file__).resolve().parent.parent.parent.parent+SRC = ROOT / "src"+++def _python_env(env: dict[str, str]) -> dict[str, str]:+ merged = os.environ.copy()+ merged.update(env)+ return merged+++def test_settings_reads_canonical_pool_maxsize_env_var():+ env = _python_env(+ {+ "OPENSEARCH_POOL_MAXSIZE": "64",+ "PYTHONPATH": str(SRC),+ }+ )+ result = subprocess.run(+ [+ sys.executable,+ "-c",+ "from config.settings import OPENSEARCH_POOL_MAXSIZE; print(OPENSEARCH_POOL_MAXSIZE)",+ ],+ capture_output=True,+ text=True,+ check=True,+ env=env,+ cwd=str(ROOT),+ )+ assert result.stdout.splitlines()[-1].strip() == "64"+++def test_settings_default_pool_maxsize_fallback():+ env = _python_env(+ {+ "PYTHONPATH": str(SRC),+ }+ )+ env.pop("OPENSEARCH_POOL_MAXSIZE", None)+ result = subprocess.run(+ [+ sys.executable,+ "-c",+ "from config.settings import OPENSEARCH_POOL_MAXSIZE; print(OPENSEARCH_POOL_MAXSIZE)",+ ],+ capture_output=True,+ text=True,+ check=True,+ env=env,+ cwd=str(ROOT),+ )+ assert result.stdout.splitlines()[-1].strip() == "8"+++def test_opensearch_client_uses_configured_pool_maxsize():+ env = _python_env(+ {+ "OPENSEARCH_POOL_MAXSIZE": "48",+ "PYTHONPATH": str(SRC),+ }+ )+ code = (+ "from config.settings import clients; "+ "client = clients.create_basic_opensearch_client('admin', 'pass'); "+ "client.transport.set_connections([{'host': 'localhost', 'port': 9200}]); "+ "conn = client.transport.get_connection(); "+ "print(conn._limit)"+ )+ result = subprocess.run(+ [sys.executable, "-c", code],+ capture_output=True,+ text=True,+ check=True,+ env=env,+ cwd=str(ROOT),+ )+ assert result.stdout.splitlines()[-1].strip() == "48"+++def test_settings_clamps_zero_pool_maxsize_to_one():+ env = _python_env(+ {+ "OPENSEARCH_POOL_MAXSIZE": "0",+ "PYTHONPATH": str(SRC),+ }+ )+ result = subprocess.run(+ [+ sys.executable,+ "-c",+ "from config.settings import OPENSEARCH_POOL_MAXSIZE; print(OPENSEARCH_POOL_MAXSIZE)",+ ],+ capture_output=True,+ text=True,+ check=True,+ env=env,+ cwd=str(ROOT),+ )+ assert result.stdout.splitlines()[-1].strip() == "1"