Skip to content

feat(auditplan): create cost metric records only when mysql #3052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

littleniannian
Copy link
Collaborator

@littleniannian littleniannian commented May 26, 2025

User description

关联的 issue

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

描述你的变更

确认项(pr提交后操作)

Tip

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


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


Description

  • 添加 MySQL 判断条件,避免非 MySQL 环境创建成本记录

  • 修改 createSqlManageCostMetricRecord 中错误日志提示信息

  • 保证批量更新和队列推送逻辑维持原有功能


Changes walkthrough 📝

Relevant files
Enhancement
task_wrap.go
为 SQL 成本记录创建增加 MySQL 条件判断                                                               

sqle/server/auditplan/task_wrap.go

  • 引入对 ap.DBType 的 MySQL 判断
  • 将创建成本记录逻辑包裹在条件判断内
  • 更新错误日志输出,简化错误描述
+8/-5     

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @actiontech-bot actiontech-bot requested a review from BugsGuru May 26, 2025 10:24
    Copy link

    PR Reviewer Guide 🔍

    🎫 Ticket compliance analysis 🔶

    2375 - Partially compliant

    Compliant requirements:

    • 添加 MySQL 判断逻辑
    • 修改错误日志提示信息
    • 保持批量更新和队列推送逻辑维持原有功能

    Non-compliant requirements:

    • 更新url路径
    • 更新swagger
    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    条件判断

    请检查仅在 MySQL 环境下执行的逻辑是否符合预期,并确认对 createSqlManageCostMetricRecord 返回错误的处理方式是否合理。

    // 目前只支持MySQL
    if ap.DBType == driverV2.DriverTypeMySQL {
    	for _, sqlQueue := range SqlQueueList {
    		err = createSqlManageCostMetricRecord(sqlQueue, ap.Instance)
    		if err != nil {
    			log.Logger().Errorf("createSqlManageCostMetricRecord: %v", err)
    		}
    日志信息

    请确认更新后的日志信息能够准确描述错误原因,以便更快定位和排查问题。

    log.Logger().Errorf("createSqlManageCostMetricRecord: failed %v", err)

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    错误处理不可忽略

    建议在处理每个 sqlQueue
    的错误时,不仅记录日志,还应及时返回错误或累计错误处理,以避免关键指标记录失败被忽略,确保数据一致性。这样可以防止后续操作在关键错误发生时继续执行,从而减少潜在的系统风险。

    sqle/server/auditplan/task_wrap.go [312-320]

     // 目前只支持MySQL
     if ap.DBType == driverV2.DriverTypeMySQL {
     	for _, sqlQueue := range SqlQueueList {
     		err = createSqlManageCostMetricRecord(sqlQueue, ap.Instance)
     		if err != nil {
     			log.Logger().Errorf("createSqlManageCostMetricRecord: %v", err)
    +			return err
     		}
     	}
     }
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion proposes returning the error in createSqlManageCostMetricRecord rather than just logging it. This change improves error transparency and data consistency but may alter the intended behavior of continuing despite metric record failures.

    Medium
    General
    增强错误日志详情

    建议在错误日志中提供更多上下文信息,比如包含相关的 SQL 文本,这样更有助于定位问题原因,同时注意不要暴露敏感信息。详细的错误信息可以提高故障排查效率。

    sqle/server/auditplan/task_wrap.go [646-649]

     cost, err := GetQueryCost(plugin, sqlManageQueue.SqlText)
     if err != nil {
    -		log.Logger().Errorf("createSqlManageCostMetricRecord: failed %v", err)
    +		log.Logger().Errorf("createSqlManageCostMetricRecord: failed to get query cost for SQL [%s]: %v", sqlManageQueue.SqlText, err)
     		return err
     }
    Suggestion importance[1-10]: 5

    __

    Why: Adding SQL text into the error log provides more context for debugging. This is a minor but useful enhancement that improves traceability without affecting the overall functionality.

    Low

    @BugsGuru BugsGuru merged commit 8e269be into main May 27, 2025
    4 checks passed
    @BugsGuru BugsGuru deleted the fix_plugin_resource_overload branch May 27, 2025 02:59
    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.

    2 participants