Skip to content

Feat operation record ce#574

Merged
iwanghc merged 2 commits intomainfrom
feat-operation-record-ce
Mar 2, 2026
Merged

Feat operation record ce#574
iwanghc merged 2 commits intomainfrom
feat-operation-record-ce

Conversation

@BugsGuru
Copy link
Collaborator

关联的 issue

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

描述你的变更

  • dms增加操作日志的定时清理
  • 完善dms的操作记录覆盖的功能

确认项(pr提交后操作)

Tip

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


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

link https://github.com/actiontech/dms-ee/pull/733

- Updated CronTaskUsecase to include OperationRecordUsecase for regular cleaning of operation records.
- Implemented DoClean method in OperationRecordUsecase to remove expired operation records based on system variable settings.
- Added CleanOperationRecordOpTimeBefore method in operation record repository for database cleanup operations.
- Adjusted service initialization to accommodate new dependencies for operation record management.
- Introduced OperationRecordMiddleware for tracking operations in the API server.
- Created operation_record.go to define API interface information and path matching logic.
- Updated router to utilize the new middleware for enhanced operation recording.
- Added new log retrieval method in OperationRecordUsecase for better logging management.
- Expanded locale files with operation record related messages for improved internationalization support.
@LordofAvernus LordofAvernus requested review from iwanghc and removed request for iwanghc February 28, 2026 03:28
@github-actions
Copy link

PR Reviewer Guide 🔍

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

中间件空实现

OperationRecordMiddleware 方法目前仅直接调用 next,没有任何附加逻辑或记录动作,建议根据实际需求补充必要逻辑或注释说明其暂时为空的原因。

func OperationRecordMiddleware(_ *service.DMSService) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return next
	}
}
日志与错误处理

DoClean 方法中对系统变量的获取和错误处理较为分散,建议统一日志风格和错误信息输出,同时考虑对系统变量解析失败时是否需要更明确的处理措施。

func (u *OperationRecordUsecase) DoClean() {
	if u.systemVariableUsecase == nil {
		u.log.Errorf("failed to clean operation record when get systemVariableUsecase")
		return
	}

	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancel()

	variables, err := u.systemVariableUsecase.GetSystemVariables(ctx)
	if err != nil {
		u.log.Errorf("failed to clean operation record when get expired duration: %v", err)
		return
	}

	operationRecordExpiredHoursVar, ok := variables[SystemVariableOperationRecordExpiredHours]
	if !ok {
		u.log.Debugf("system variable %s not found, using default value", SystemVariableOperationRecordExpiredHours)
		operationRecordExpiredHoursVar = SystemVariable{
			Key:   SystemVariableOperationRecordExpiredHours,
			Value: strconv.Itoa(DefaultOperationRecordExpiredHours),
		}
	}

	operationRecordExpiredHours, err := strconv.Atoi(operationRecordExpiredHoursVar.Value)
	if err != nil {
		u.log.Errorf("failed to parse operation_record_expired_hours value: %v", err)
		return
	}

	if operationRecordExpiredHours <= 0 {
		u.log.Errorf("got OperationRecordExpiredHours: %d", operationRecordExpiredHours)
		return
	}

	cleanTime := time.Now().Add(time.Duration(-operationRecordExpiredHours) * time.Hour)
	rowsAffected, err := u.repo.CleanOperationRecordOpTimeBefore(ctx, cleanTime)
	if err != nil {
		u.log.Errorf("failed to clean operation record: %v", err)
		return
	}
	u.log.Infof("OperationRecord regular cleaned rows: %d operation time before: %s", rowsAffected, cleanTime.Format("2006-01-02 15:04:05"))
}

@LordofAvernus LordofAvernus requested review from iwanghc and removed request for iwanghc February 28, 2026 03:29
@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
使用默认配置解析

若解析配置值失败会导致清理任务被中断,建议在解析失败时采用默认值继续进行清理操作。这样可以避免因配置异常导致定期清理任务无法执行,防止潜在的数据堆积问题。

internal/dms/biz/operation_record.go [84-88]

 operationRecordExpiredHours, err := strconv.Atoi(operationRecordExpiredHoursVar.Value)
 if err != nil {
-    u.log.Errorf("failed to parse operation_record_expired_hours value: %v", err)
-    return
+    u.log.Errorf("failed to parse operation_record_expired_hours value: %v, using default %d", err, DefaultOperationRecordExpiredHours)
+    operationRecordExpiredHours = DefaultOperationRecordExpiredHours
 }
Suggestion importance[1-10]: 8

__

Why: This suggestion strengthens error handling by using a default value when parsing fails, preventing interruption of the clean-up task and addressing a potential issue effectively.

Medium

@iwanghc iwanghc merged commit 4f39ced into main Mar 2, 2026
1 check passed
@BugsGuru BugsGuru deleted the feat-operation-record-ce branch March 3, 2026 02:32
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