@@ -54,6 +54,10 @@ class DatabaseConfig:
|
||||
be_hosts: list[str] = field(default_factory=list)
|
||||
be_webserver_port: int = 8040
|
||||
|
||||
# Arrow Flight SQL Configuration (Required for ADBC tools)
|
||||
fe_arrow_flight_sql_port: int | None = None
|
||||
be_arrow_flight_sql_port: int | None = None
|
||||
|
||||
# Connection pool configuration
|
||||
# Note: min_connections is fixed at 0 to avoid at_eof connection issues
|
||||
# This prevents pre-creation of connections which can cause state problems
|
||||
@@ -133,6 +137,22 @@ class PerformanceConfig:
|
||||
max_response_content_size: int = 4096
|
||||
|
||||
|
||||
@dataclass
|
||||
class ADBCConfig:
|
||||
"""ADBC (Arrow Flight SQL) configuration"""
|
||||
|
||||
# Default query parameters
|
||||
default_max_rows: int = 100000
|
||||
default_timeout: int = 60
|
||||
default_return_format: str = "arrow" # "arrow", "pandas", "dict"
|
||||
|
||||
# Connection timeout for ADBC
|
||||
connection_timeout: int = 30
|
||||
|
||||
# Whether to enable ADBC tools
|
||||
enabled: bool = True
|
||||
|
||||
|
||||
@dataclass
|
||||
class LoggingConfig:
|
||||
"""Logging configuration"""
|
||||
@@ -190,6 +210,7 @@ class DorisConfig:
|
||||
performance: PerformanceConfig = field(default_factory=PerformanceConfig)
|
||||
logging: LoggingConfig = field(default_factory=LoggingConfig)
|
||||
monitoring: MonitoringConfig = field(default_factory=MonitoringConfig)
|
||||
adbc: ADBCConfig = field(default_factory=ADBCConfig)
|
||||
|
||||
# Custom configuration
|
||||
custom_config: dict[str, Any] = field(default_factory=dict)
|
||||
@@ -260,6 +281,15 @@ class DorisConfig:
|
||||
if be_hosts_env:
|
||||
config.database.be_hosts = [host.strip() for host in be_hosts_env.split(",") if host.strip()]
|
||||
config.database.be_webserver_port = int(os.getenv("DORIS_BE_WEBSERVER_PORT", str(config.database.be_webserver_port)))
|
||||
|
||||
# Arrow Flight SQL Configuration
|
||||
fe_arrow_port_env = os.getenv("FE_ARROW_FLIGHT_SQL_PORT")
|
||||
if fe_arrow_port_env:
|
||||
config.database.fe_arrow_flight_sql_port = int(fe_arrow_port_env)
|
||||
|
||||
be_arrow_port_env = os.getenv("BE_ARROW_FLIGHT_SQL_PORT")
|
||||
if be_arrow_port_env:
|
||||
config.database.be_arrow_flight_sql_port = int(be_arrow_port_env)
|
||||
|
||||
# Connection pool configuration
|
||||
config.database.max_connections = int(
|
||||
@@ -359,6 +389,21 @@ class DorisConfig:
|
||||
)
|
||||
config.monitoring.alert_webhook_url = os.getenv("ALERT_WEBHOOK_URL", config.monitoring.alert_webhook_url)
|
||||
|
||||
# ADBC configuration
|
||||
config.adbc.default_max_rows = int(
|
||||
os.getenv("ADBC_DEFAULT_MAX_ROWS", str(config.adbc.default_max_rows))
|
||||
)
|
||||
config.adbc.default_timeout = int(
|
||||
os.getenv("ADBC_DEFAULT_TIMEOUT", str(config.adbc.default_timeout))
|
||||
)
|
||||
config.adbc.default_return_format = os.getenv("ADBC_DEFAULT_RETURN_FORMAT", config.adbc.default_return_format)
|
||||
config.adbc.connection_timeout = int(
|
||||
os.getenv("ADBC_CONNECTION_TIMEOUT", str(config.adbc.connection_timeout))
|
||||
)
|
||||
config.adbc.enabled = (
|
||||
os.getenv("ADBC_ENABLED", str(config.adbc.enabled).lower()).lower() == "true"
|
||||
)
|
||||
|
||||
# Server configuration
|
||||
config.server_name = os.getenv("SERVER_NAME", config.server_name)
|
||||
config.server_version = os.getenv("SERVER_VERSION", config.server_version)
|
||||
@@ -412,6 +457,13 @@ class DorisConfig:
|
||||
if hasattr(config.monitoring, key):
|
||||
setattr(config.monitoring, key, value)
|
||||
|
||||
# Update ADBC configuration
|
||||
if "adbc" in config_data:
|
||||
adbc_config = config_data["adbc"]
|
||||
for key, value in adbc_config.items():
|
||||
if hasattr(config.adbc, key):
|
||||
setattr(config.adbc, key, value)
|
||||
|
||||
# Custom configuration
|
||||
config.custom_config = config_data.get("custom", {})
|
||||
|
||||
@@ -434,6 +486,8 @@ class DorisConfig:
|
||||
"fe_http_port": self.database.fe_http_port,
|
||||
"be_hosts": self.database.be_hosts,
|
||||
"be_webserver_port": self.database.be_webserver_port,
|
||||
"fe_arrow_flight_sql_port": self.database.fe_arrow_flight_sql_port,
|
||||
"be_arrow_flight_sql_port": self.database.be_arrow_flight_sql_port,
|
||||
"min_connections": self.database.min_connections, # Always 0, shown for reference
|
||||
"max_connections": self.database.max_connections,
|
||||
"connection_timeout": self.database.connection_timeout,
|
||||
@@ -483,6 +537,13 @@ class DorisConfig:
|
||||
"enable_alerts": self.monitoring.enable_alerts,
|
||||
"alert_webhook_url": self.monitoring.alert_webhook_url,
|
||||
},
|
||||
"adbc": {
|
||||
"default_max_rows": self.adbc.default_max_rows,
|
||||
"default_timeout": self.adbc.default_timeout,
|
||||
"default_return_format": self.adbc.default_return_format,
|
||||
"connection_timeout": self.adbc.connection_timeout,
|
||||
"enabled": self.adbc.enabled,
|
||||
},
|
||||
"custom": self.custom_config,
|
||||
}
|
||||
|
||||
@@ -564,6 +625,19 @@ class DorisConfig:
|
||||
if not (1 <= self.monitoring.health_check_port <= 65535):
|
||||
errors.append("Health check port must be in the range 1-65535")
|
||||
|
||||
# Validate ADBC configuration
|
||||
if self.adbc.default_max_rows <= 0:
|
||||
errors.append("ADBC default max rows must be greater than 0")
|
||||
|
||||
if self.adbc.default_timeout <= 0:
|
||||
errors.append("ADBC default timeout must be greater than 0")
|
||||
|
||||
if self.adbc.default_return_format not in ["arrow", "pandas", "dict"]:
|
||||
errors.append("ADBC default return format must be one of arrow, pandas, or dict")
|
||||
|
||||
if self.adbc.connection_timeout <= 0:
|
||||
errors.append("ADBC connection timeout must be greater than 0")
|
||||
|
||||
return errors
|
||||
|
||||
def get_connection_string(self) -> str:
|
||||
@@ -603,6 +677,7 @@ class ConfigManager:
|
||||
def setup_logging(self):
|
||||
"""Setup logging configuration using enhanced logger"""
|
||||
from .logger import setup_logging, get_logger
|
||||
import sys
|
||||
|
||||
# Determine log directory
|
||||
log_dir = "logs"
|
||||
@@ -611,11 +686,19 @@ class ConfigManager:
|
||||
from pathlib import Path
|
||||
log_dir = str(Path(self.config.logging.file_path).parent)
|
||||
|
||||
# Detect if we're in stdio mode by checking if this is likely MCP stdio communication
|
||||
# In stdio mode, we shouldn't output to console as it interferes with JSON protocol
|
||||
is_stdio_mode = (
|
||||
self.config.transport == "stdio" or
|
||||
"--transport" in sys.argv and "stdio" in sys.argv or
|
||||
not sys.stdout.isatty() # Not a terminal (likely piped/redirected)
|
||||
)
|
||||
|
||||
# Setup enhanced logging with cleanup functionality
|
||||
setup_logging(
|
||||
level=self.config.logging.level,
|
||||
log_dir=log_dir,
|
||||
enable_console=True,
|
||||
enable_console=not is_stdio_mode, # Disable console logging in stdio mode
|
||||
enable_file=True,
|
||||
enable_audit=self.config.logging.enable_audit,
|
||||
audit_file=self.config.logging.audit_file_path,
|
||||
|
||||
Reference in New Issue
Block a user