Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqle/api/controller/v2/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func GetInstanceTips(c echo.Context) error {
instanceTipsResV1 := make([]InstanceTipResV2, 0, len(instances))
svc := server.BackupService{}
for _, inst := range instances {
// When functional_module is view_sql_insight, only return instances
// that have SQL audit enabled. Instances without audit cannot provide
// performance insight data.
if req.FunctionalModule == v1.FunctionalModuleViewSQLInsight && !inst.SqlQueryConfig.AuditEnabled {
continue
}
instanceTipRes := InstanceTipResV2{
ID: inst.GetIDStr(),
Name: inst.Name,
Expand Down
6 changes: 6 additions & 0 deletions sqle/locale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ApMetaPerformanceCollectTips = "Performance metric collection will incur signifi
ApMetaPostgreSQLTopSQL = "TOP SQL"
ApMetaPostgreSQLSlowLog = "Slow log"
ApMetaQueries = "QPS"
ApMetaSQLServerPerformanceCollect = "SQLServer performance collect"
ApMetaSQLServerPerformanceCollectTips = "Periodically collect performance metrics such as connections and QPS from SQLServer instances"
ApMetaSQLServerProcesslist = "SQLServer active sessions"
ApMetaSQLServerSlowLog = "SQLServer slow SQL collect"
ApMetaSchemaMeta = "Database schema metadata"
ApMetaSlowLog = "Slow log"
ApMetaThreadsConnected = "ThreadsConnected"
Expand Down Expand Up @@ -324,6 +328,8 @@ ParamProjectId = "Project ID"
ParamRdsPath = "RDS Open API Address"
ParamRegion = "Region of current RDS Instance (Example: cn-east-2)"
ParamSQLMinSecond = "SQL Minimum Execution Time (Second)"
ParamSlowSqlThreshold = "Slow SQL Threshold (Second)"
ParamFirstSqlsScrappedHoursGeneric = "Time range for pulling slow logs on task startup (unit: hours)"
ParamSlowLogCollectInput = "Collect Source"
ParamTimeSpan = "Time span(hours)"
ParamTopN = "Top N"
Expand Down
6 changes: 6 additions & 0 deletions sqle/locale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ApMetaPerformanceCollectTips = "性能指标采集将产生较大性能开销,
ApMetaPostgreSQLTopSQL = "TOP SQL"
ApMetaPostgreSQLSlowLog = "慢日志"
ApMetaQueries = "QPS"
ApMetaSQLServerPerformanceCollect = "SQLServer性能采集"
ApMetaSQLServerPerformanceCollectTips = "定时采集SQLServer实例的连接数和QPS等性能指标"
ApMetaSQLServerProcesslist = "SQLServer活跃会话采集"
ApMetaSQLServerSlowLog = "SQLServer慢SQL采集"
ApMetaSchemaMeta = "库表元数据"
ApMetaSlowLog = "慢日志"
ApMetaThreadsConnected = "线程数"
Expand Down Expand Up @@ -324,6 +328,8 @@ ParamProjectId = "项目ID"
ParamRdsPath = "RDS Open API地址"
ParamRegion = "当前RDS实例所在的地区(示例:cn-east-2)"
ParamSQLMinSecond = "SQL 最小执行时间(秒)"
ParamSlowSqlThreshold = "慢SQL判定时间阈值(秒)"
ParamFirstSqlsScrappedHoursGeneric = "启动任务时拉取慢日志时间范围(单位:小时)"
ParamSlowLogCollectInput = "采集来源"
ParamTimeSpan = "时间跨度(小时)"
ParamTopN = "Top N"
Expand Down
6 changes: 6 additions & 0 deletions sqle/locale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ var (
ApMetricRowExaminedAvg = &i18n.Message{ID: "ApMetricRowExaminedAvg", Other: "平均扫描行数"}
ApMetaPerformanceCollect = &i18n.Message{ID: "ApMetaPerformanceCollect", Other: "数据源性能指标"}
ApMetaPerformanceCollectTips = &i18n.Message{ID: "ApMetaPerformanceCollectTips", Other: "性能指标采集将产生较大性能开销,请谨慎开启。开启后,系统将持续采集该数据源的性能数据(如QPS、连接数等),并生成性能趋势图表,体现在性能洞察页面。"}
ApMetaSQLServerPerformanceCollect = &i18n.Message{ID: "ApMetaSQLServerPerformanceCollect", Other: "SQLServer性能采集"}
ApMetaSQLServerPerformanceCollectTips = &i18n.Message{ID: "ApMetaSQLServerPerformanceCollectTips", Other: "定时采集SQLServer实例的连接数和QPS等性能指标"}
ApMetaSQLServerSlowLog = &i18n.Message{ID: "ApMetaSQLServerSlowLog", Other: "SQLServer慢SQL采集"}
ApMetaSQLServerProcesslist = &i18n.Message{ID: "ApMetaSQLServerProcesslist", Other: "SQLServer活跃会话采集"}
ApMetaCollectTime = &i18n.Message{ID: "ApMetaCollectTime", Other: "采集时间"}
ApMetaThreadsConnected = &i18n.Message{ID: "ApMetaThreadsConnected", Other: "线程数"}
ApMetaQPS = &i18n.Message{ID: "ApMetaQueries", Other: "QPS"}
Expand All @@ -444,6 +448,8 @@ var (
ParamOrderByColumnGeneric = &i18n.Message{ID: "ParamOrderByColumnGeneric", Other: "排序字段"}
ParamCollectIntervalSecond = &i18n.Message{ID: "ParamCollectIntervalSecond", Other: "采集周期(秒)"}
ParamSQLMinSecond = &i18n.Message{ID: "ParamSQLMinSecond", Other: "SQL 最小执行时间(秒)"}
ParamSlowSqlThreshold = &i18n.Message{ID: "ParamSlowSqlThreshold", Other: "慢SQL判定时间阈值(秒)"}
ParamFirstSqlsScrappedHoursGeneric = &i18n.Message{ID: "ParamFirstSqlsScrappedHoursGeneric", Other: "启动任务时拉取慢日志时间范围(单位:小时)"}
ParamCollectView = &i18n.Message{ID: "ParamCollectView", Other: "是否采集视图信息"}
ParamDBInstanceId = &i18n.Message{ID: "ParamDBInstanceId", Other: "实例ID"}
ParamAccessKeyId = &i18n.Message{ID: "ParamAccessKeyId", Other: "Access Key ID"}
Expand Down
12 changes: 12 additions & 0 deletions sqle/model/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ func (s *Storage) GetLatestStartTimeAuditPlanSQLV2(sourceId uint, typ string) (s
return info.StartTime, err
}

// GetLatestStartTimeAuditPlanSQLV2ForSQLServer returns the latest start time
// by max string comparison. SQLServer slow log stores a fixed-width datetime
// layout, so lexicographic order matches chronological order.
func (s *Storage) GetLatestStartTimeAuditPlanSQLV2ForSQLServer(sourceId uint, typ string) (string, error) {
info := struct {
StartTime string `gorm:"column:max_start_time"`
}{}
err := s.db.Raw(`SELECT MAX(JSON_UNQUOTE(JSON_EXTRACT(info, '$.start_time_of_last_scraped_sql')))
AS max_start_time FROM sql_manage_records WHERE source_id = ? AND source = ? AND deleted_at is NULL`, sourceId, typ).Scan(&info).Error
return info.StartTime, err
}

// HasSQLManageRecords 检查是否存在指定 source_id 和 source 的 SQL 记录
func (s *Storage) HasSQLManageRecords(sourceId string, source string) (bool, error) {
info := struct {
Expand Down
Loading