add bugfix
All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 1m36s
All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 1m36s
This commit is contained in:
parent
25c9b2d18e
commit
01f87e38aa
26
app/main.py
26
app/main.py
@ -85,7 +85,8 @@ def generate_fingerprint(log: ErrorLogCreate) -> str:
|
|||||||
|
|
||||||
if source == "cicd":
|
if source == "cicd":
|
||||||
ctx = log.context or {}
|
ctx = log.context or {}
|
||||||
raw = f"{log.project_id}|cicd|{log.error.get('type')}|{ctx.get('job_name', 'unknown')}|{ctx.get('step_name', 'unknown')}"
|
# 加入 error_message 避免同一 job 不同错误被去重
|
||||||
|
raw = f"{log.project_id}|cicd|{log.error.get('type')}|{ctx.get('job_name', 'unknown')}|{ctx.get('step_name', 'unknown')}|{log.error.get('message', '')}"
|
||||||
elif source == "deployment":
|
elif source == "deployment":
|
||||||
ctx = log.context or {}
|
ctx = log.context or {}
|
||||||
raw = f"{log.project_id}|deployment|{log.error.get('type')}|{ctx.get('namespace', 'default')}|{ctx.get('deployment_name', 'unknown')}"
|
raw = f"{log.project_id}|deployment|{log.error.get('type')}|{ctx.get('namespace', 'default')}|{ctx.get('deployment_name', 'unknown')}"
|
||||||
@ -105,13 +106,28 @@ async def report_log(log_data: ErrorLogCreate, session: AsyncSession = Depends(g
|
|||||||
existing_log = results.first()
|
existing_log = results.first()
|
||||||
|
|
||||||
if existing_log:
|
if existing_log:
|
||||||
# If exists and not resolved, just ignore or update count (implied)
|
# If exists and not resolved, update error content but keep status
|
||||||
if existing_log.status not in [LogStatus.DEPLOYED, LogStatus.FIXED, LogStatus.VERIFIED]:
|
if existing_log.status not in [LogStatus.DEPLOYED, LogStatus.FIXED, LogStatus.VERIFIED]:
|
||||||
return {"message": "Log deduplicated", "id": existing_log.id, "status": existing_log.status}
|
# 更新错误内容,确保始终反映最新的错误信息
|
||||||
# If it was resolved but happened again -> Regression! Reset to NEW?
|
existing_log.error_message = log_data.error.get("message", existing_log.error_message)
|
||||||
|
existing_log.stack_trace = log_data.error.get("stack_trace", existing_log.stack_trace)
|
||||||
|
existing_log.context = log_data.context or existing_log.context
|
||||||
|
existing_log.timestamp = log_data.timestamp or datetime.utcnow()
|
||||||
|
if log_data.commit_hash:
|
||||||
|
existing_log.commit_hash = log_data.commit_hash
|
||||||
|
session.add(existing_log)
|
||||||
|
await session.commit()
|
||||||
|
await session.refresh(existing_log)
|
||||||
|
return {"message": "Log deduplicated (content updated)", "id": existing_log.id, "status": existing_log.status}
|
||||||
|
# If it was resolved but happened again -> Regression! Reset to NEW
|
||||||
existing_log.status = LogStatus.NEW
|
existing_log.status = LogStatus.NEW
|
||||||
|
existing_log.error_message = log_data.error.get("message", existing_log.error_message)
|
||||||
|
existing_log.stack_trace = log_data.error.get("stack_trace", existing_log.stack_trace)
|
||||||
|
existing_log.context = log_data.context or existing_log.context
|
||||||
existing_log.timestamp = log_data.timestamp or datetime.utcnow()
|
existing_log.timestamp = log_data.timestamp or datetime.utcnow()
|
||||||
existing_log.retry_count = 0 # Reset retries for new occurrence
|
existing_log.retry_count = 0
|
||||||
|
if log_data.commit_hash:
|
||||||
|
existing_log.commit_hash = log_data.commit_hash
|
||||||
session.add(existing_log)
|
session.add(existing_log)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
await session.refresh(existing_log)
|
await session.refresh(existing_log)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user