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
11 changes: 10 additions & 1 deletion sqle/api/controller/v1/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ func GetInstanceAuditPlanOverview(c echo.Context) error {
}

typeBase := ConvertAuditPlanTypeToRes(c.Request().Context(), v.ID, v.Type)
lastCollectionStatus := ""
if v.AuditPlanTaskInfo != nil {
lastCollectionStatus = v.AuditPlanTaskInfo.LastCollectionStatus
}
resAuditPlan := InstanceAuditPlanInfo{
ID: v.ID,
Type: typeBase,
Expand All @@ -696,7 +700,7 @@ func GetInstanceAuditPlanOverview(c echo.Context) error {
TotalSQLNums: totalSQLNums,
UnsolvedSQLNums: unsolvedSQLNums,
ActiveStatus: v.ActiveStatus,
LastCollectionStatus: v.AuditPlanTaskInfo.LastCollectionStatus,
LastCollectionStatus: lastCollectionStatus,
}
if v.AuditPlanTaskInfo != nil {
resAuditPlan.LastCollectionTime = v.AuditPlanTaskInfo.LastCollectionTime
Expand Down Expand Up @@ -866,6 +870,11 @@ func UpdateAuditPlanStatus(c echo.Context) error {
auditPlan.ActiveStatus = req.Active
// 重启扫描任务时,重置最后采集状态
if req.Active == model.ActiveStatusNormal {
if auditPlan.AuditPlanTaskInfo == nil {
auditPlan.AuditPlanTaskInfo = &model.AuditPlanTaskInfo{
AuditPlanID: auditPlan.ID,
}
}
auditPlan.AuditPlanTaskInfo.LastCollectionStatus = ""
err = s.Save(auditPlan.AuditPlanTaskInfo)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion sqle/api/controller/v2/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ func ConvertAuditPlanTypeToResByID(ctx context.Context, id string, token string)
}
for _, meta := range auditplan.Metas {
if meta.Type == auditPlan.Type {
lastCollectionStatus := ""
if auditPlan.AuditPlanTaskInfo != nil {
lastCollectionStatus = auditPlan.AuditPlanTaskInfo.LastCollectionStatus
}
return AuditPlanTypeResBase{
AuditPlanType: auditPlan.Type,
AuditPlanTypeDesc: locale.Bundle.LocalizeMsgByCtx(ctx, meta.Desc),
AuditPlanId: auditPlan.ID,
Token: token,
ActiveStatus: auditPlan.ActiveStatus,
LastCollectionStatus: auditPlan.AuditPlanTaskInfo.LastCollectionStatus,
LastCollectionStatus: lastCollectionStatus,
}, nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16345,6 +16345,9 @@ var doc = `{
"db_type": {
"type": "string"
},
"default_port": {
"type": "integer"
},
"params": {
"type": "array",
"items": {
Expand Down
3 changes: 3 additions & 0 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16329,6 +16329,9 @@
"db_type": {
"type": "string"
},
"default_port": {
"type": "integer"
},
"params": {
"type": "array",
"items": {
Expand Down
2 changes: 2 additions & 0 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ definitions:
properties:
db_type:
type: string
default_port:
type: integer
params:
items:
$ref: '#/definitions/v1.InstanceAdditionalParamResV1'
Expand Down
10 changes: 10 additions & 0 deletions sqle/locale/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ApMetaGaussDBProcesslist = "GaussDB Processlist"
ApMetaGaussDBSlowLog = "GaussDB Slow Log"
ApMetaGoldenDBTopSQL = "GoldenDB TOP SQL"
ApMetaHanaTopSQL = "HANA TOP SQL"
ApMetaHiveSlowLog = "Hive slow log"
ApMetaHuaweiRdsMySQLSlowLog = "Huawei Cloud RDS MySQL slow log"
ApMetaMDBSlowLog = "slow log(Monitor DB)"
ApMetaMSSQLTopSQL = "SQL Server TOP SQL"
Expand Down Expand Up @@ -67,6 +68,7 @@ ApMetaTBaseProcesslist = "TBase Active Session Collection"
ApMetaTiDBProcesslist = "TiDB Processlist"
ApMetaTopSQL = "Top SQL"
ApMetricEngine = "engine"
ApMetricHiveSlowLogDbUser = "Execution user"
ApMetricNameActiveTimeTotal = "Total active time (ms)"
ApMetricNameActiveWaitTimeTotal = "Total active wait time (ms)"
ApMetricNameBufferGetCounter = "Logical read count"
Expand Down Expand Up @@ -185,6 +187,14 @@ ExportWorkflowName = "Task name"
ExportWorkflowNumber = "Task ID"
FileOrderMethodPrefixNumAsc = "Prefix number ascending"
FileOrderMethodSuffixNumAsc = "Suffix number ascending"
HiveSlowLogErrAuthInvalid = "Invalid Hive datasource `auth` parameter. Allowed values: `NOSASL` / `NONE` / `LDAP` / `CUSTOM`. Please correct it on the SQLE datasource management page. Origin error: %s"
HiveSlowLogErrColumnMismatch = "Hive slow log collection SQL failed: invalid column reference. The Hive version may differ from the SQLE adapted baseline (Hive 4.2). Please share the output of `SELECT version()` with the SQLE maintainer. Origin error: %s"
HiveSlowLogErrConnectFailed = "Hive instance connection failed: HiveServer2 may have SASL/LDAP authentication enabled while the datasource `auth` is set to `NOSASL`. Please edit this Hive datasource on the SQLE datasource management page and change `auth` to `NONE` or `LDAP`. Origin error: %s"
HiveSlowLogErrHS2ServerError = "Hive HS2 server returned an error. Common causes: 1) `sys.query_history` table does not exist - please ensure `hive.query.history.enabled=true` is set in HS2 `hive-site.xml` and Restart HS2; 2) `sys` database does not exist - same as above, HS2 auto-creates it after restart; 3) Hive version differs from the SQLE adapted baseline (Hive 4.2). Please inspect HS2 server-side logs for details. Origin error: %s"
HiveSlowLogErrPluginTransportClosing = "Hive slow log collection failed: the sqle-hive-plugin subprocess exited abnormally (gRPC channel closed with the signal `transport is closing`). The most common trigger is an invalid Hive datasource `auth` value (gohive panics inside `innerConnect` with `panic: Unrecognized auth`, and the panic message is not propagated across the gRPC channel after the plugin process crashes). Please self-check in the following order: 1) Verify on the SQLE datasource management page that `auth` is one of the allowed values: `NOSASL` / `NONE` / `LDAP` / `CUSTOM`; 2) Confirm host / port reachability; 3) Inspect the plugin / HS2 server-side logs for the panic stack. Origin error: %s"
HiveSlowLogErrSysDbNotFound = "Hive instance `sys` database does not exist. Please contact your Hive platform operator: 1) set `hive.query.history.enabled=true` in HS2 `hive-site.xml`; 2) restart HS2 so that it auto-creates the `sys.query_history` table. Origin error: %s"
HiveSlowLogErrTableNotFound = "Hive instance `sys.query_history` table does not exist. HS2 may not have query history enabled. Please verify that `hive.query.history.enabled` is true and HS2 has been restarted. Origin error: %s"
HiveSlowLogErrUnknown = "Hive slow log collection failed: %s"
LicenseDurationOfRunning = "Running days"
LicenseEstimatedMaturity = "Estimated maturity date"
LicenseInstanceNum = "Instance count"
Expand Down
10 changes: 10 additions & 0 deletions sqle/locale/active.zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ApMetaGaussDBProcesslist = "GaussDB 进程列表"
ApMetaGaussDBSlowLog = "GaussDB 慢日志"
ApMetaGoldenDBTopSQL = "GoldenDB TOP SQL"
ApMetaHanaTopSQL = "HANA TOP SQL"
ApMetaHiveSlowLog = "Hive慢日志"
ApMetaHuaweiRdsMySQLSlowLog = "华为云RDS MySQL慢日志"
ApMetaMDBSlowLog = "慢日志(监控库)"
ApMetaMSSQLTopSQL = "SQL Server TOP SQL"
Expand Down Expand Up @@ -67,6 +68,7 @@ ApMetaTBaseProcesslist = "TBase 活跃会话采集"
ApMetaTiDBProcesslist = "TiDB Processlist"
ApMetaTopSQL = "Top SQL"
ApMetricEngine = "引擎"
ApMetricHiveSlowLogDbUser = "执行用户"
ApMetricNameActiveTimeTotal = "活动总时间(ms)"
ApMetricNameActiveWaitTimeTotal = "活动等待总时间(ms)"
ApMetricNameBufferGetCounter = "逻辑读次数"
Expand Down Expand Up @@ -185,6 +187,14 @@ ExportWorkflowName = "工单名称"
ExportWorkflowNumber = "工单编号"
FileOrderMethodPrefixNumAsc = "文件名前缀数字升序"
FileOrderMethodSuffixNumAsc = "文件名后缀数字升序"
HiveSlowLogErrAuthInvalid = "Hive 数据源 auth 参数值非法。允许的值:`NOSASL` / `NONE` / `LDAP` / `CUSTOM`。请在 SQLE 数据源管理页修正。原始错误:%s"
HiveSlowLogErrColumnMismatch = "Hive 慢日志采集 SQL 执行失败:字段引用错误。可能是 Hive 版本与 SQLE 适配版本(基线 Hive 4.2)存在差异;请把 `SELECT version()` 输出反馈给 SQLE 维护者。原始错误:%s"
HiveSlowLogErrConnectFailed = "Hive 实例连接失败:可能是 HiveServer2 启用了 SASL/LDAP 鉴权而数据源配置的 `auth` 为 `NOSASL`。请在 SQLE 数据源管理页编辑该 Hive 数据源,把 `auth` 改为 `NONE` 或 `LDAP`。原始错误:%s"
HiveSlowLogErrHS2ServerError = "Hive HS2 服务端返回错误。常见原因:1) `sys.query_history` 表不存在 —— 请确认 HS2 的 hive-site.xml 中已配置 `hive.query.history.enabled=true` 并重启 HS2 服务;2) `sys` 库不存在 —— 同上,重启 HS2 后会自动创建;3) Hive 版本与 SQLE 适配基线(Hive 4.2)字段不一致。请查阅 HS2 服务端日志获取详细错误信息。原始错误:%s"
HiveSlowLogErrPluginTransportClosing = "Hive 慢日志采集失败:sqle-hive-plugin 进程异常退出(gRPC 通道关闭,错误信号 `transport is closing`)。最常见的原因是 Hive 数据源 `auth` 参数值非法(plugin 内 gohive 在 `innerConnect` 内 `panic: Unrecognized auth`,进程崩溃后 panic 信息不会跨 gRPC 传递)。请按以下顺序自查:1) 在 SQLE 数据源管理页确认 `auth` 是允许的值:`NOSASL` / `NONE` / `LDAP` / `CUSTOM`;2) 确认 host / port 可达;3) 查阅 plugin / HS2 服务端日志获取 panic 堆栈。原始错误:%s"
HiveSlowLogErrSysDbNotFound = "Hive 实例 `sys` 库不存在。请联系 Hive 平台运维:1) 在 HS2 的 hive-site.xml 中配置 `hive.query.history.enabled=true`;2) 重启 HS2 服务后,HS2 会自动创建 `sys.query_history` 表。原始错误:%s"
HiveSlowLogErrTableNotFound = "Hive 实例 `sys.query_history` 表不存在。HS2 可能未启用 query history。请检查 HS2 配置 `hive.query.history.enabled` 是否为 true,并确认 HS2 已重启。原始错误:%s"
HiveSlowLogErrUnknown = "Hive 慢日志采集失败:%s"
LicenseDurationOfRunning = "已运行时长(天)"
LicenseEstimatedMaturity = "预计到期时间"
LicenseInstanceNum = "实例数"
Expand Down
11 changes: 11 additions & 0 deletions sqle/locale/message_zh.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ var (
ApMetaAliRdsMySQLSlowLog = &i18n.Message{ID: "ApMetaAliRdsMySQLSlowLog", Other: "阿里RDS MySQL慢日志"}
ApMetaAliRdsMySQLAuditLog = &i18n.Message{ID: "ApMetaAliRdsMySQLAuditLog", Other: "阿里RDS MySQL审计日志"}
ApMetaBaiduRdsMySQLSlowLog = &i18n.Message{ID: "ApMetaBaiduRdsMySQLSlowLog", Other: "百度云RDS MySQL慢日志"}
ApMetaHiveSlowLog = &i18n.Message{ID: "ApMetaHiveSlowLog", Other: "Hive慢日志"}
ApMetaHuaweiRdsMySQLSlowLog = &i18n.Message{ID: "ApMetaHuaweiRdsMySQLSlowLog", Other: "华为云RDS MySQL慢日志"}
ApMetaOracleTopSQL = &i18n.Message{ID: "ApMetaOracleTopSQL", Other: "Oracle TOP SQL"}
ApMetaOracleSlowLog = &i18n.Message{ID: "ApMetaOracleSlowLog", Other: "Oracle慢日志"}
Expand Down Expand Up @@ -444,6 +445,7 @@ var (
ApMetaMSSQLTopSQL = &i18n.Message{ID: "ApMetaMSSQLTopSQL", Other: "SQL Server TOP SQL"}
ApMetricQueryTimeAvg = &i18n.Message{ID: "ApMetricQueryTimeAvg", Other: "平均查询时间(s)"}
ApMetricRowExaminedAvg = &i18n.Message{ID: "ApMetricRowExaminedAvg", Other: "平均扫描行数"}
ApMetricHiveSlowLogDbUser = &i18n.Message{ID: "ApMetricHiveSlowLogDbUser", Other: "执行用户"}
ApMetaPerformanceCollectTips = &i18n.Message{ID: "ApMetaPerformanceCollectTips", Other: "性能指标采集将产生较大性能开销,请谨慎开启。开启后,系统将持续采集该数据源的性能数据(如QPS、连接数等),并生成性能趋势图表,体现在性能洞察页面。"}
ApMetaSQLServerPerformanceCollect = &i18n.Message{ID: "ApMetaSQLServerPerformanceCollect", Other: "SQLServer性能采集"}
ApMetaSQLServerPerformanceCollectTips = &i18n.Message{ID: "ApMetaSQLServerPerformanceCollectTips", Other: "定时采集SQLServer实例的连接数和QPS等性能指标"}
Expand Down Expand Up @@ -501,6 +503,15 @@ var (
OperatorLessThan = &i18n.Message{ID: "OperatorLessThan", Other: "小于"}

OperationParamAuditLevel = &i18n.Message{ID: "OperationParamAuditLevel", Other: "触发审核级别"}

HiveSlowLogErrSysDbNotFound = &i18n.Message{ID: "HiveSlowLogErrSysDbNotFound", Other: "Hive 实例 `sys` 库不存在。请联系 Hive 平台运维:1) 在 HS2 的 hive-site.xml 中配置 `hive.query.history.enabled=true`;2) 重启 HS2 服务后,HS2 会自动创建 `sys.query_history` 表。原始错误:%s"}
HiveSlowLogErrTableNotFound = &i18n.Message{ID: "HiveSlowLogErrTableNotFound", Other: "Hive 实例 `sys.query_history` 表不存在。HS2 可能未启用 query history。请检查 HS2 配置 `hive.query.history.enabled` 是否为 true,并确认 HS2 已重启。原始错误:%s"}
HiveSlowLogErrColumnMismatch = &i18n.Message{ID: "HiveSlowLogErrColumnMismatch", Other: "Hive 慢日志采集 SQL 执行失败:字段引用错误。可能是 Hive 版本与 SQLE 适配版本(基线 Hive 4.2)存在差异;请把 `SELECT version()` 输出反馈给 SQLE 维护者。原始错误:%s"}
HiveSlowLogErrConnectFailed = &i18n.Message{ID: "HiveSlowLogErrConnectFailed", Other: "Hive 实例连接失败:可能是 HiveServer2 启用了 SASL/LDAP 鉴权而数据源配置的 `auth` 为 `NOSASL`。请在 SQLE 数据源管理页编辑该 Hive 数据源,把 `auth` 改为 `NONE` 或 `LDAP`。原始错误:%s"}
HiveSlowLogErrAuthInvalid = &i18n.Message{ID: "HiveSlowLogErrAuthInvalid", Other: "Hive 数据源 auth 参数值非法。允许的值:`NOSASL` / `NONE` / `LDAP` / `CUSTOM`。请在 SQLE 数据源管理页修正。原始错误:%s"}
HiveSlowLogErrHS2ServerError = &i18n.Message{ID: "HiveSlowLogErrHS2ServerError", Other: "Hive HS2 服务端返回错误。常见原因:1) `sys.query_history` 表不存在 —— 请确认 HS2 的 hive-site.xml 中已配置 `hive.query.history.enabled=true` 并重启 HS2 服务;2) `sys` 库不存在 —— 同上,重启 HS2 后会自动创建;3) Hive 版本与 SQLE 适配基线(Hive 4.2)字段不一致。请查阅 HS2 服务端日志获取详细错误信息。原始错误:%s"}
HiveSlowLogErrPluginTransportClosing = &i18n.Message{ID: "HiveSlowLogErrPluginTransportClosing", Other: "Hive 慢日志采集失败:sqle-hive-plugin 进程异常退出(gRPC 通道关闭,错误信号 `transport is closing`)。最常见的原因是 Hive 数据源 `auth` 参数值非法(plugin 内 gohive 在 `innerConnect` 内 `panic: Unrecognized auth`,进程崩溃后 panic 信息不会跨 gRPC 传递)。请按以下顺序自查:1) 在 SQLE 数据源管理页确认 `auth` 是允许的值:`NOSASL` / `NONE` / `LDAP` / `CUSTOM`;2) 确认 host / port 可达;3) 查阅 plugin / HS2 服务端日志获取 panic 堆栈。原始错误:%s"}
HiveSlowLogErrUnknown = &i18n.Message{ID: "HiveSlowLogErrUnknown", Other: "Hive 慢日志采集失败:%s"}
)

var (
Expand Down
16 changes: 16 additions & 0 deletions sqle/model/instance_audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,22 @@ func (s *Storage) BatchSaveAuditPlans(auditPlans []*AuditPlanV2) error {
if err := txDB.Save(auditPlan).Error; err != nil {
return err
}
// 更新已存在的扫描任务时,兜底补齐缺失的 audit_plan_task_infos 行,
// 避免历史数据/手工修改造成 Preload 后 AuditPlanTaskInfo == nil 引发空指针。
var taskInfoCount int64
if err := txDB.Model(&AuditPlanTaskInfo{}).
Where("audit_plan_id = ?", auditPlan.ID).
Count(&taskInfoCount).Error; err != nil {
return err
}
if taskInfoCount == 0 {
apTaskInfo := &AuditPlanTaskInfo{
AuditPlanID: auditPlan.ID,
}
if err := txDB.Save(apTaskInfo).Error; err != nil {
return err
}
}
}
}
return nil
Expand Down
Loading