Skip to content

Conversation

@BugsGuru
Copy link
Collaborator

@BugsGuru BugsGuru commented Nov 21, 2025

User description

关联的 issue

https://github.com/actiontech/sqle-ee/issues/2586

描述你的变更

DMS工作台调用的审核接口返回SQLType字段

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc


Description

  • 新增自动创建工单及执行的 API 接口(仅限 sys 用户)

  • 定义并实现 AutoCreateAndExecuteWorkflowV1 相关数据结构与流程

  • 增加 SQLType 字段在 SQL 审计响应中的传递

  • 更新 swagger 文档,完善 API 定义与错误提示


Diagram Walkthrough

flowchart LR
  A["更新 API 路由"] -- "新增 endpoint" --> B["AutoCreateAndExecuteWorkflowV1"]
  B -- "调用新请求/响应结构" --> C["AutoCreateAndExecuteWorkflowReqV1/ResV1"]
  C -- "创建、审核及执行工单" --> D["任务组与工单处理"]
  D -- "审计 SQL 处理" --> E["增加 SQLType 字段"]
  E -- "更新 swagger 文档" --> F["文档与接口定义"]
Loading

File Walkthrough

Relevant files
Enhancement
4 files
app.go
添加自动创建并执行工单的 API 路由                                                                           
+1/-0     
workflow.go
实现 AutoCreateAndExecuteWorkflowV1 及辅助函数                                   
+401/-2 
sql_audit.go
SQL 审计响应中添加 SQLType 字段                                                                     
+3/-0     
audit.go
将 SQLType 字段加入任务 SQL 解析中                                                                 
+1/-0     
Bug fix
3 files
workflow.go
优化 workflow 转换逻辑处理 nil 模板                                                               
+8/-2     
sqled.go
调整 SQL 执行异常处理代码                                                                                   
+2/-2     
workflow_schedule.go
放宽用户权限检查,允许 sys 与 admin 操作工单                                                         
+6/-1     
Documentation
3 files
docs.go
更新 swagger 文档,添加新接口定义                                                                       
+129/-0 
swagger.json
补充新 API 的 swagger 定义与参数                                                                   
+129/-0 
swagger.yaml
添加自动执行接口及响应模型的文档说明                                                                             
+87/-0   

@github-actions
Copy link

github-actions bot commented Nov 21, 2025

PR Reviewer Guide 🔍

(Review updated until commit 8594d69)

🎫 Ticket compliance analysis 🔶

2586 - Partially compliant

Compliant requirements:

• 返回 SQLType 字段
• API 接口更新
• Swagger 文档完善

Non-compliant requirements:

Requires further human verification:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

文档一致性

新增加的自动创建和执行工单接口在路由注册中已添加,请确认此接口在 Swagger 文档中的描述和定义与实际实现保持一致,确保接口文档和实现同步更新。

v1ProjectOpRouter.POST("/:project_name/workflows/auto_create_and_execute", v1.AutoCreateAndExecuteWorkflowV1)
错误处理

在执行 SQL 后调用 st.Save(currentSQL) 时,建议增加日志记录或重试机制,以便在保存失败时能够更好地追踪错误并做出相应处理,提升错误处理的健壮性。

_, execErr = a.plugin.Exec(context.TODO(), node.Text)
if execErr != nil {
	currentSQL.ExecStatus = model.SQLExecuteStatusFailed
	currentSQL.ExecResult = execErr.Error()
} else {
	currentSQL.ExecStatus = model.SQLExecuteStatusSucceeded
	currentSQL.ExecResult = model.TaskExecResultOK
}
if execErr = st.Save(currentSQL); execErr != nil {

@github-actions
Copy link

github-actions bot commented Nov 21, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
使用合适的上下文

建议将传递给 Close 方法的 context 从 context.TODO() 改为使用实际的请求上下文,比如
c.Request().Context(),这样可以确保在请求取消或超时时正确释放资源,防止潜在的资源泄露问题。

sqle/api/controller/v1/workflow.go [2135]

-defer plugin.Close(context.TODO())
+defer plugin.Close(c.Request().Context())
Suggestion importance[1-10]: 7

__

Why: 该建议将 context.TODO() 替换为 c.Request().Context(),有助于在请求取消或超时时正确释放资源,从而提高资源管理的准确性。

Medium
添加超时机制保护

建议在从 channel 中接收结果时增加超时或上下文取消的控制,防止在通道未返回结果时导致服务阻塞。可以使用 select 语句结合 time.After 或上下文
Done 通道来实现超时处理,提高系统健壮性。

sqle/api/controller/v1/workflow.go [2260]

-return <-ch, nil
+select {
+case result := <-ch:
+    return result, nil
+case <-time.After(30 * time.Second):
+    return "", fmt.Errorf("execute workflow timeout")
+}
Suggestion importance[1-10]: 6

__

Why: 该建议为从 channel 接收结果增加了超时处理,提高了系统的健壮性,但可能改变原有的阻塞行为,因此建议评估是否符合预期的业务逻辑。

Low

@github-actions
Copy link

Persistent review updated to latest commit a64dde9

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
使用合适的上下文

建议将传递给 Close 方法的 context 从 context.TODO() 改为使用实际的请求上下文,比如
c.Request().Context(),这样可以确保在请求取消或超时时正确释放资源,防止潜在的资源泄露问题。

sqle/api/controller/v1/workflow.go [2135]

-defer plugin.Close(context.TODO())
+defer plugin.Close(c.Request().Context())
Suggestion importance[1-10]: 7

__

Why: 该建议将 context.TODO() 替换为 c.Request().Context(),有助于在请求取消或超时时正确释放资源,从而提高资源管理的准确性。

Medium
添加超时机制保护

建议在从 channel 中接收结果时增加超时或上下文取消的控制,防止在通道未返回结果时导致服务阻塞。可以使用 select 语句结合 time.After 或上下文
Done 通道来实现超时处理,提高系统健壮性。

sqle/api/controller/v1/workflow.go [2260]

-return <-ch, nil
+select {
+case result := <-ch:
+    return result, nil
+case <-time.After(30 * time.Second):
+    return "", fmt.Errorf("execute workflow timeout")
+}
Suggestion importance[1-10]: 6

__

Why: 该建议为从 channel 接收结果增加了超时处理,提高了系统的健壮性,但可能改变原有的阻塞行为,因此建议评估是否符合预期的业务逻辑。

Low

@github-actions
Copy link

Persistent review updated to latest commit 8594d69

@github-actions
Copy link

Failed to generate code suggestions for PR

@BugsGuru BugsGuru mentioned this pull request Nov 27, 2025
6 tasks
@LordofAvernus LordofAvernus merged commit e530a9d into main Nov 28, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants