log refactor

This commit is contained in:
2026-05-12 19:30:15 +03:00
parent 1d59df2233
commit b17b5333c7
84 changed files with 5827 additions and 3908 deletions

View File

@@ -22,6 +22,9 @@ from typing import Dict, Any, Optional
from src.core.plugin_base import PluginBase
from src.services.git_service import GitService
from src.core.logger import logger as app_logger, belief_scope
from src.core.cot_logger import MarkerLogger
log = MarkerLogger("GitPlugin")
from src.core.config_manager import ConfigManager
from src.core.superset_client import SupersetClient
from src.core.task_manager.context import TaskContext
@@ -39,7 +42,7 @@ class GitPlugin(PluginBase):
# @POST: Инициализированы git_service и config_manager.
def __init__(self):
with belief_scope("GitPlugin.__init__"):
app_logger.info("Initializing GitPlugin.")
log.reason("Initializing GitPlugin.")
self.git_service = GitService()
# Robust config path resolution:
@@ -54,13 +57,13 @@ class GitPlugin(PluginBase):
try:
from src.dependencies import config_manager
self.config_manager = config_manager
app_logger.info("GitPlugin initialized using shared config_manager.")
log.reflect("GitPlugin initialized using shared config_manager.")
return
except Exception:
config_path = "config.json"
self.config_manager = ConfigManager(config_path)
app_logger.info(f"GitPlugin initialized with {config_path}")
log.reflect(f"GitPlugin initialized with {config_path}")
# [/DEF:__init__:Function]
@property
@@ -137,7 +140,7 @@ class GitPlugin(PluginBase):
# @POST: Плагин готов к выполнению задач.
async def initialize(self):
with belief_scope("GitPlugin.initialize"):
app_logger.info("[GitPlugin.initialize][Action] Initializing Git Integration Plugin logic.")
log.reason("Initializing Git Integration Plugin logic")
# [DEF:execute:Function]
# @PURPOSE: Основной метод выполнения задач плагина с поддержкой TaskContext.
@@ -248,15 +251,15 @@ class GitPlugin(PluginBase):
# 5. Автоматический staging изменений (не коммит, чтобы юзер мог проверить diff)
try:
repo.git.add(A=True)
app_logger.info("[_handle_sync][Action] Changes staged in git")
log.reason("Changes staged in git")
except Exception as ge:
app_logger.warning(f"[_handle_sync][Action] Failed to stage changes: {ge}")
log.explore("Failed to stage changes", error=str(ge))
app_logger.info(f"[_handle_sync][Coherence:OK] Dashboard {dashboard_id} synced successfully.")
log.reflect("Dashboard synced successfully", payload={"dashboard_id": dashboard_id})
return {"status": "success", "message": "Dashboard synced and flattened in local repository"}
except Exception as e:
app_logger.error(f"[_handle_sync][Coherence:Failed] Sync failed: {e}")
log.explore("Sync failed", error=str(e))
raise
# [/DEF:_handle_sync:Function]
@@ -318,16 +321,16 @@ class GitPlugin(PluginBase):
f.write(zip_buffer.getvalue())
try:
app_logger.info(f"[_handle_deploy][Action] Importing dashboard to {env.name}")
log.reason("Importing dashboard", payload={"environment": env.name})
result = client.import_dashboard(temp_zip_path)
app_logger.info(f"[_handle_deploy][Coherence:OK] Deployment successful for dashboard {dashboard_id}.")
log.reflect("Deployment successful", payload={"dashboard_id": dashboard_id})
return {"status": "success", "message": f"Dashboard deployed to {env.name}", "details": result}
finally:
if temp_zip_path.exists():
os.remove(temp_zip_path)
except Exception as e:
app_logger.error(f"[_handle_deploy][Coherence:Failed] Deployment failed: {e}")
log.explore("Deployment failed", error=str(e))
raise
# [/DEF:_handle_deploy:Function]
@@ -339,13 +342,13 @@ class GitPlugin(PluginBase):
# @RETURN: Environment - Объект конфигурации окружения.
def _get_env(self, env_id: Optional[str] = None):
with belief_scope("GitPlugin._get_env"):
app_logger.info(f"[_get_env][Entry] Fetching environment for ID: {env_id}")
log.reason("Fetching environment", payload={"env_id": env_id})
# Priority 1: ConfigManager (config.json)
if env_id:
env = self.config_manager.get_environment(env_id)
if env:
app_logger.info(f"[_get_env][Exit] Found environment by ID in ConfigManager: {env.name}")
log.reflect("Found environment by ID in ConfigManager", payload={"name": env.name})
return env
# Priority 2: Database (DeploymentEnvironment)
@@ -363,7 +366,7 @@ class GitPlugin(PluginBase):
db_env = db.query(DeploymentEnvironment).first()
if db_env:
app_logger.info(f"[_get_env][Exit] Found environment in DB: {db_env.name}")
log.reflect("Found environment in DB", payload={"name": db_env.name})
from src.core.config_models import Environment
# Use token as password for SupersetClient
return Environment(
@@ -385,14 +388,14 @@ class GitPlugin(PluginBase):
# but we have other envs, maybe it's one of them?
env = next((e for e in envs if e.id == env_id), None)
if env:
app_logger.info(f"[_get_env][Exit] Found environment {env_id} in ConfigManager list")
log.reflect("Found environment in ConfigManager list", payload={"env_id": env_id})
return env
if not env_id:
app_logger.info(f"[_get_env][Exit] Using first environment from ConfigManager: {envs[0].name}")
log.reflect("Using first environment from ConfigManager", payload={"name": envs[0].name})
return envs[0]
app_logger.error(f"[_get_env][Coherence:Failed] No environments configured (searched config.json and DB). env_id={env_id}")
log.explore("No environments configured", payload={"env_id": env_id}, error="No Superset environments found in config or database")
raise ValueError("No environments configured. Please add a Superset Environment in Settings.")
# [/DEF:_get_env:Function]