All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 2m24s
新增两种日志来源(cicd / deployment),使日志中台覆盖"构建→部署→运行"全链路: 后端变更: - models.py: 新增 LogSource 枚举和 source 字段,file_path/line_number 改为可选 - main.py: 按来源生成不同指纹策略,所有查询端点支持 source 筛选,仪表盘新增来源分布统计 - database.py: 新增 4 条迁移 SQL(source 字段、索引、字段可空) - task_manager.py: 修复 Agent 仅拉取 runtime 来源的缺陷 新增组件: - k8s-monitor/: K8s Pod 健康监控脚本(Python),每 5 分钟检测异常 Pod 并上报 - k8s/monitor-cronjob.yaml: CronJob + RBAC 部署清单 - scripts/report-cicd-error.sh: CI/CD 错误上报 Bash 脚本 - scripts/gitea-actions-example.yaml: Gitea Actions 集成示例 前端变更: - api.ts: 类型定义更新,支持 source 字段 - BugList.tsx: 新增来源筛选标签页和来源列 - BugDetail.tsx: 按来源条件渲染(CI/CD 信息、部署信息),非 runtime 禁用修复按钮 - Dashboard.tsx: 新增来源分布表格 - index.css: 来源标签样式(source-badge) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
110 lines
3.2 KiB
Python
110 lines
3.2 KiB
Python
from datetime import datetime
|
|
from typing import Optional, Dict, List
|
|
from sqlmodel import SQLModel, Field, Column, JSON, Text
|
|
from enum import Enum
|
|
|
|
class LogSource(str, Enum):
|
|
RUNTIME = "runtime"
|
|
CICD = "cicd"
|
|
DEPLOYMENT = "deployment"
|
|
|
|
class LogStatus(str, Enum):
|
|
NEW = "NEW"
|
|
VERIFYING = "VERIFYING"
|
|
CANNOT_REPRODUCE = "CANNOT_REPRODUCE"
|
|
PENDING_FIX = "PENDING_FIX"
|
|
FIXING = "FIXING"
|
|
FIXED = "FIXED"
|
|
VERIFIED = "VERIFIED"
|
|
DEPLOYED = "DEPLOYED"
|
|
FIX_FAILED = "FIX_FAILED"
|
|
|
|
class ErrorLog(SQLModel, table=True):
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
project_id: str = Field(index=True)
|
|
environment: str
|
|
level: str
|
|
|
|
# Source
|
|
source: str = Field(default="runtime", index=True)
|
|
|
|
# Error Details
|
|
error_type: str
|
|
error_message: str
|
|
file_path: Optional[str] = None
|
|
line_number: Optional[int] = None
|
|
stack_trace: str = Field(sa_column=Column(JSON)) # Store full stack trace
|
|
|
|
# Context
|
|
context: Dict = Field(default={}, sa_column=Column(JSON))
|
|
|
|
# Versioning
|
|
version: Optional[str] = None
|
|
commit_hash: Optional[str] = None
|
|
|
|
# Meta
|
|
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
|
fingerprint: str = Field(unique=True, index=True) # project_id + error_type + file_path + line_number
|
|
|
|
# Status Tracking
|
|
status: LogStatus = Field(default=LogStatus.NEW)
|
|
retry_count: int = Field(default=0)
|
|
|
|
# Relationships could be added here (e.g., to a RepairTask table if 1:N)
|
|
# For simplicity, we track status on the Log itself for now.
|
|
|
|
# Pydantic Models for API
|
|
class ErrorLogCreate(SQLModel):
|
|
project_id: str
|
|
environment: str
|
|
level: str
|
|
timestamp: Optional[datetime] = None
|
|
version: Optional[str] = None
|
|
commit_hash: Optional[str] = None
|
|
|
|
source: str = "runtime"
|
|
error: Dict # {type, message, file_path, line_number, stack_trace}
|
|
context: Optional[Dict] = {}
|
|
|
|
class TaskStatusUpdate(SQLModel):
|
|
status: LogStatus
|
|
message: Optional[str] = None
|
|
|
|
class RepairTask(SQLModel, table=True):
|
|
"""Record of a repair attempt"""
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
error_log_id: int = Field(foreign_key="errorlog.id")
|
|
status: LogStatus
|
|
project_id: str
|
|
|
|
# Repair Details
|
|
ai_analysis: str = Field(sa_column=Column(Text)) # Analysis from LLM
|
|
fix_plan: str = Field(sa_column=Column(Text)) # Proposed fix plan
|
|
code_diff: str = Field(sa_column=Column(Text)) # Git diff
|
|
modified_files: List[str] = Field(sa_column=Column(JSON))
|
|
|
|
# Test Results
|
|
test_output: str = Field(sa_column=Column(Text))
|
|
test_passed: bool
|
|
|
|
# Repair Round Tracking
|
|
repair_round: int = Field(default=1) # Which round (1, 2, 3...)
|
|
failure_reason: Optional[str] = Field(default=None, sa_column=Column(Text, nullable=True))
|
|
|
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
|
|
class RepairTaskCreate(SQLModel):
|
|
"""Schema for creating a repair report via API"""
|
|
error_log_id: int
|
|
status: LogStatus
|
|
project_id: str
|
|
ai_analysis: str
|
|
fix_plan: str
|
|
code_diff: str
|
|
modified_files: List[str]
|
|
test_output: str
|
|
test_passed: bool
|
|
repair_round: int = 1
|
|
failure_reason: Optional[str] = None
|
|
|