Skip to content

Conversation

@littleniannian
Copy link
Collaborator

@littleniannian littleniannian commented Jan 5, 2026

User description

关联的 issue

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

描述你的变更

  • 新增obmysql 全量扫描任务

确认项(pr提交后操作)

Tip

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


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


Description

  • 新增用户客户端IP、租户名称、请求时长指标

  • 添加SQL记录检查函数以判断记录存在

  • 更新本地化翻译消息及指标常量映射

  • 修正指标名称不一致问题


Diagram Walkthrough

flowchart LR
  A["新增i18n消息配置"] --> B["添加用户客户端IP消息"]
  A --> C["调整其他指标消息排序"]
  D["新增SQL记录检查函数"] --> A
  E["扩展指标常量定义"] --> D
  F["更新本地化翻译"] --> E
Loading

File Walkthrough

Relevant files
Enhancement
message_zh.go
新增并调整i18n消息配置                                                                                       

sqle/locale/message_zh.go

  • 添加 ApMetricUserClientIP 国际化消息
  • 新增 ApMetricNameTenantNameApMetricNameRequestTime
  • 调整指标消息的顺序和分组
+38/-34 
instance_audit_plan.go
增加SQL记录检查新方法                                                                                         

sqle/model/instance_audit_plan.go

  • 添加 HasSQLManageRecords 方法检查SQL记录存在性
  • 使用原生SQL统计记录数量
+12/-0   
metrics.go
扩展指标常量定义                                                                                                 

sqle/server/auditplan/metrics.go

  • 新增常量 MetricNameUserClientIPMetricNameTenantNameMetricNameRequestTime
  • 在 ALLMetric 映射中加入新指标
+9/-0     
active.en.toml
更新英文本地化指标翻译                                                                                           

sqle/locale/active.en.toml

  • 新增英文翻译 ApMetaOceanBaseForMySQLFullCollect
  • 新增 ApMetricUserClientIPApMetricNameRequestTimeApMetricNameTenantName
    英文翻译
+4/-0     
active.zh.toml
更新中文本地化指标翻译                                                                                           

sqle/locale/active.zh.toml

  • 新增中文翻译 ApMetaOceanBaseForMySQLFullCollect
  • 新增 ApMetricUserClientIPApMetricNameRequestTimeApMetricNameTenantName
    中文翻译
+4/-0     

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

PR Reviewer Guide 🔍

(Review updated until commit d4fde64)

🎫 Ticket compliance analysis 🔶

2615 - Partially compliant

Compliant requirements:

  • 新增 obmysql 全量扫描任务及相关指标

Non-compliant requirements:

  • Oracle 使用 sys 用户的连接修正未覆盖
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

命名一致性

请检查新增的翻译条目是否与现有命名规则及格式保持统一,确保消息ID与描述内容一致。

ApMetricUserClientIP                = &i18n.Message{ID: "ApMetricUserClientIP", Other: "客户端IP"}
ApMetricNameHost                    = &i18n.Message{ID: "ApMetricNameHost", Other: "主机"}
ApMetricNameMetaName                = &i18n.Message{ID: "ApMetricNameMetaName", Other: "对象名称"}
ApMetricNameMetaType                = &i18n.Message{ID: "ApMetricNameMetaType", Other: "对象类型"}
ApMetricNameQueryTimeTotal          = &i18n.Message{ID: "ApMetricNameQueryTimeTotal", Other: "总执行时间(s)"}
类型验证

请核实新增的 HasSQLManageRecords 函数在传递 sourceId 时的数据类型是否与数据库字段定义匹配,确保参数传递正确。

// HasSQLManageRecords 检查是否存在指定 source_id 和 source 的 SQL 记录
func (s *Storage) HasSQLManageRecords(sourceId string, source string) (bool, error) {
	info := struct {
		Count int64 `gorm:"column:cnt"`
	}{}
	err := s.db.Raw(`SELECT COUNT(*) AS cnt FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at IS NULL`, sourceId, source).Scan(&info).Error
	if err != nil {
		return false, err
	}
	return info.Count > 0, nil
}
常量定义一致性

请确认新增常量(如 MetricNameUserClientIP、MetricNameTenantName、MetricNameRequestTime)在所有模块中都使用统一的命名及数据类型,与翻译条目保持对应。

const MetricNameUserClientIP = "user_client_ip"
const MetricNameTenantName = "tenant_name"
const MetricNameRequestTime = "request_time"

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

PR Code Suggestions ✨

Latest suggestions up to d4fde64
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
参数类型统一

建议将函数 HasSQLManageRecords 中的 sourceId 参数类型与其他相关函数保持一致,例如将其类型由 string 修改为
uint。统一参数类型可以避免由于类型转换带来的潜在恐慌和数据库查询错误。

sqle/model/instance_audit_plan.go [185-194]

-func (s *Storage) HasSQLManageRecords(sourceId string, source string) (bool, error) {
+func (s *Storage) HasSQLManageRecords(sourceId uint, source string) (bool, error) {
 	info := struct {
 		Count int64 `gorm:"column:cnt"`
 	}{}
 	err := s.db.Raw(`SELECT COUNT(*) AS cnt FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at IS NULL`, sourceId, source).Scan(&info).Error
 	if err != nil {
 		return false, err
 	}
 	return info.Count > 0, nil
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion corrects the inconsistent parameter type for sourceId by aligning it with its use in related functions, which can prevent potential type conversion issues.

Medium

Previous suggestions

Suggestions up to commit e443049
CategorySuggestion                                                                                                                                    Impact
General
变量命名保持一致

建议将变量名 ApMetricUserClientIP 修改为 ApMetricClientIP,以保持与其他语言文件中的命名一致。这样可以避免混淆并提高代码可读性。

sqle/locale/message_zh.go [324-325]

 ApMetricNameDBUser                  = &i18n.Message{ID: "ApMetricNameDBUser", Other: "用户"}
-ApMetricUserClientIP                = &i18n.Message{ID: "ApMetricClientIP", Other: "客户端IP"}
+ApMetricClientIP                    = &i18n.Message{ID: "ApMetricClientIP", Other: "客户端IP"}
Suggestion importance[1-10]: 7

__

Why: The suggestion improves naming consistency by renaming ApMetricUserClientIP to ApMetricClientIP, which aligns with naming in other language files. The improved code snippet correctly reflects this change.

Medium
常量命名大小写一致

建议将常量 MetricNameUserClientIpIp 部分修改为大写 IP,以确保命名与其它相关常量一致。保持一致的命名风格有助于后续的维护和避免错误。

sqle/server/auditplan/metrics.go [82]

-const MetricNameUserClientIp = "user_client_ip"
+const MetricNameUserClientIP = "user_client_ip"
Suggestion importance[1-10]: 7

__

Why: The suggestion standardizes the constant name by capitalizing IP in MetricNameUserClientIp, ensuring consistency with other constants. The improved code snippet accurately implements this modification.

Medium

Copy link
Collaborator

@BugsGuru BugsGuru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下ai复审建议

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Persistent review updated to latest commit d4fde64

@BugsGuru BugsGuru merged commit 026b3bb into main Jan 5, 2026
3 checks passed
@BugsGuru BugsGuru deleted the feat_new_ob_task branch January 5, 2026 09:41
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.

3 participants