log refactor
This commit is contained in:
@@ -19,7 +19,10 @@ from ...core.config_models import AppConfig, Environment, GlobalSettings, Loggin
|
||||
from ...models.storage import StorageConfig
|
||||
from ...dependencies import get_config_manager, has_permission
|
||||
from ...core.config_manager import ConfigManager
|
||||
from ...core.logger import logger, belief_scope
|
||||
from ...core.logger import belief_scope
|
||||
from ...core.cot_logger import MarkerLogger
|
||||
|
||||
log = MarkerLogger("Settings")
|
||||
from ...core.superset_client import SupersetClient
|
||||
from ...services.llm_prompt_templates import normalize_llm_settings
|
||||
from ...models.llm import ValidationPolicy
|
||||
@@ -98,7 +101,7 @@ async def get_settings(
|
||||
_=Depends(has_permission("admin:settings", "READ")),
|
||||
):
|
||||
with belief_scope("get_settings"):
|
||||
logger.info("[get_settings][Entry] Fetching all settings")
|
||||
log.reason("Fetching all settings")
|
||||
config = config_manager.get_config().copy(deep=True)
|
||||
config.settings.llm = normalize_llm_settings(config.settings.llm)
|
||||
# Mask passwords
|
||||
@@ -141,7 +144,7 @@ async def update_global_settings(
|
||||
_=Depends(has_permission("admin:settings", "WRITE")),
|
||||
):
|
||||
with belief_scope("update_global_settings"):
|
||||
logger.info("[update_global_settings][Entry] Updating global settings")
|
||||
log.reason("Updating global settings")
|
||||
|
||||
config_manager.update_global_settings(settings)
|
||||
return settings
|
||||
@@ -204,7 +207,7 @@ async def get_environments(
|
||||
_=Depends(has_permission("admin:settings", "READ")),
|
||||
):
|
||||
with belief_scope("get_environments"):
|
||||
logger.info("[get_environments][Entry] Fetching environments")
|
||||
log.reason("Fetching environments")
|
||||
environments = config_manager.get_environments()
|
||||
return [
|
||||
env.copy(update={"url": _normalize_superset_env_url(env.url)})
|
||||
@@ -229,16 +232,14 @@ async def add_environment(
|
||||
_=Depends(has_permission("admin:settings", "WRITE")),
|
||||
):
|
||||
with belief_scope("add_environment"):
|
||||
logger.info(f"[add_environment][Entry] Adding environment {env.id}")
|
||||
log.reason("Adding environment", payload={"env_id": env.id})
|
||||
env = env.copy(update={"url": _normalize_superset_env_url(env.url)})
|
||||
|
||||
# Validate connection before adding (fast path)
|
||||
try:
|
||||
_validate_superset_connection_fast(env)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"[add_environment][Coherence:Failed] Connection validation failed: {e}"
|
||||
)
|
||||
log.explore("Connection validation failed", payload={"env_id": env.id}, error=str(e))
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f"Connection validation failed: {e}"
|
||||
)
|
||||
@@ -265,7 +266,7 @@ async def update_environment(
|
||||
config_manager: ConfigManager = Depends(get_config_manager),
|
||||
):
|
||||
with belief_scope("update_environment"):
|
||||
logger.info(f"[update_environment][Entry] Updating environment {id}")
|
||||
log.reason("Updating environment", payload={"id": id})
|
||||
|
||||
env = env.copy(update={"url": _normalize_superset_env_url(env.url)})
|
||||
|
||||
@@ -282,9 +283,7 @@ async def update_environment(
|
||||
try:
|
||||
_validate_superset_connection_fast(env_to_validate)
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"[update_environment][Coherence:Failed] Connection validation failed: {e}"
|
||||
)
|
||||
log.explore("Connection validation failed", payload={"id": id}, error=str(e))
|
||||
raise HTTPException(
|
||||
status_code=400, detail=f"Connection validation failed: {e}"
|
||||
)
|
||||
@@ -308,7 +307,7 @@ async def delete_environment(
|
||||
id: str, config_manager: ConfigManager = Depends(get_config_manager)
|
||||
):
|
||||
with belief_scope("delete_environment"):
|
||||
logger.info(f"[delete_environment][Entry] Deleting environment {id}")
|
||||
log.reason("Deleting environment", payload={"id": id})
|
||||
config_manager.delete_environment(id)
|
||||
return {"message": f"Environment {id} deleted"}
|
||||
|
||||
@@ -328,7 +327,7 @@ async def test_environment_connection(
|
||||
id: str, config_manager: ConfigManager = Depends(get_config_manager)
|
||||
):
|
||||
with belief_scope("test_environment_connection"):
|
||||
logger.info(f"[test_environment_connection][Entry] Testing environment {id}")
|
||||
log.reason("Testing environment connection", payload={"id": id})
|
||||
|
||||
# Find environment
|
||||
env = next((e for e in config_manager.get_environments() if e.id == id), None)
|
||||
@@ -338,14 +337,10 @@ async def test_environment_connection(
|
||||
try:
|
||||
_validate_superset_connection_fast(env)
|
||||
|
||||
logger.info(
|
||||
f"[test_environment_connection][Coherence:OK] Connection successful for {id}"
|
||||
)
|
||||
log.reflect("Connection successful", payload={"id": id})
|
||||
return {"status": "success", "message": "Connection successful"}
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"[test_environment_connection][Coherence:Failed] Connection failed for {id}: {e}"
|
||||
)
|
||||
log.explore("Connection failed", payload={"id": id}, error=str(e))
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
@@ -389,9 +384,7 @@ async def update_logging_config(
|
||||
_=Depends(has_permission("admin:settings", "WRITE")),
|
||||
):
|
||||
with belief_scope("update_logging_config"):
|
||||
logger.info(
|
||||
f"[update_logging_config][Entry] Updating logging config: level={config.level}, task_log_level={config.task_log_level}"
|
||||
)
|
||||
log.reason("Updating logging config", payload={"level": config.level, "task_log_level": config.task_log_level})
|
||||
|
||||
# Get current settings and update logging config
|
||||
settings = config_manager.get_config().settings
|
||||
@@ -444,7 +437,7 @@ async def get_consolidated_settings(
|
||||
_=Depends(has_permission("admin:settings", "READ")),
|
||||
):
|
||||
with belief_scope("get_consolidated_settings"):
|
||||
logger.reason("Fetching consolidated settings payload")
|
||||
log.reason("Fetching consolidated settings payload")
|
||||
|
||||
config = config_manager.get_config()
|
||||
|
||||
@@ -491,9 +484,9 @@ async def get_consolidated_settings(
|
||||
notifications=notifications_payload,
|
||||
features=config.settings.features.model_dump(),
|
||||
)
|
||||
logger.reflect(
|
||||
log.reflect(
|
||||
"Consolidated settings payload assembled",
|
||||
extra={
|
||||
payload={
|
||||
"environment_count": len(response_payload.environments),
|
||||
"provider_count": len(response_payload.llm_providers),
|
||||
},
|
||||
@@ -516,9 +509,7 @@ async def update_consolidated_settings(
|
||||
_=Depends(has_permission("admin:settings", "WRITE")),
|
||||
):
|
||||
with belief_scope("update_consolidated_settings"):
|
||||
logger.info(
|
||||
"[update_consolidated_settings][Entry] Applying consolidated settings patch"
|
||||
)
|
||||
log.reason("Applying consolidated settings patch")
|
||||
|
||||
current_config = config_manager.get_config()
|
||||
current_settings = current_config.settings
|
||||
|
||||
Reference in New Issue
Block a user