From fdd83e1671472ffbf74e0c749e618cc9ca18eccb Mon Sep 17 00:00:00 2001 From: iwanghc Date: Mon, 16 Dec 2024 10:37:36 +0800 Subject: [PATCH 1/2] fix: add audit status for sqls, fix unmarshal error --- sqle/model/instance_audit_plan_list.go | 9 +++++++-- sqle/server/auditplan/task_type_default.go | 1 + sqle/server/auditplan/task_type_mysql_schema_meta.go | 1 + sqle/server/auditplan/task_type_oracle_topsql.go | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sqle/model/instance_audit_plan_list.go b/sqle/model/instance_audit_plan_list.go index f9e7f90f3..bdc81165e 100644 --- a/sqle/model/instance_audit_plan_list.go +++ b/sqle/model/instance_audit_plan_list.go @@ -113,10 +113,14 @@ type InstanceAuditPlanSQLListDetail struct { Schema string `json:"schema_name"` Info JSON `json:"info"` AuditResult AuditResults `json:"audit_results"` + AuditStatus string `json:"audit_status"` Priority sql.NullString `json:"priority"` } -const AuditResultName = "audit_results" +const ( + AuditResultName = "audit_results" + AuditStatus = "audit_status" +) var AuditResultDesc = locale.ApAuditResult @@ -170,7 +174,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority {{- template "body" . -}} diff --git a/sqle/server/auditplan/task_type_default.go b/sqle/server/auditplan/task_type_default.go index 432c1bfed..f6eb8420d 100644 --- a/sqle/server/auditplan/task_type_default.go +++ b/sqle/server/auditplan/task_type_default.go @@ -252,6 +252,7 @@ func (at *DefaultTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, persist MetricNameCounter: strconv.Itoa(int(info.Get(MetricNameCounter).Int())), MetricNameLastReceiveTimestamp: info.Get(MetricNameLastReceiveTimestamp).String(), model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), + model.AuditStatus: sql.AuditStatus, }) } return rows, count, nil diff --git a/sqle/server/auditplan/task_type_mysql_schema_meta.go b/sqle/server/auditplan/task_type_mysql_schema_meta.go index f66d20fc2..c9764c7fe 100644 --- a/sqle/server/auditplan/task_type_mysql_schema_meta.go +++ b/sqle/server/auditplan/task_type_mysql_schema_meta.go @@ -361,6 +361,7 @@ func (at *BaseSchemaMetaTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, p MetricNameMetaName: info.Get(MetricNameMetaName).String(), MetricNameMetaType: info.Get(MetricNameMetaType).String(), model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), + model.AuditStatus: sql.AuditStatus, }) } return rows, count, nil diff --git a/sqle/server/auditplan/task_type_oracle_topsql.go b/sqle/server/auditplan/task_type_oracle_topsql.go index 837be52bf..4b9b944f1 100644 --- a/sqle/server/auditplan/task_type_oracle_topsql.go +++ b/sqle/server/auditplan/task_type_oracle_topsql.go @@ -242,6 +242,7 @@ func (at *OracleTopSQLTaskV2) GetSQLData(ctx context.Context, ap *AuditPlan, per MetricNameBufferGetCounter: strconv.Itoa(int(info.Get(MetricNameBufferGetCounter).Int())), MetricNameUserIOWaitTimeTotal: fmt.Sprintf("%v", utils.Round(info.Get(MetricNameUserIOWaitTimeTotal).Float()/1000, 3)), model.AuditResultName: sql.AuditResult.GetAuditJsonStrByLangTag(locale.Bundle.GetLangTagFromCtx(ctx)), + model.AuditStatus: sql.AuditStatus, }) } return rows, count, nil From a18db8b5a04f9cadc16e9eea60dcb2e53551b25f Mon Sep 17 00:00:00 2001 From: iwanghc Date: Mon, 16 Dec 2024 10:37:36 +0800 Subject: [PATCH 2/2] fix: fix go test for audit plan query --- sqle/model/instance_audit_plan_list_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sqle/model/instance_audit_plan_list_test.go b/sqle/model/instance_audit_plan_list_test.go index f7acf1139..c61cd0037 100644 --- a/sqle/model/instance_audit_plan_list_test.go +++ b/sqle/model/instance_audit_plan_list_test.go @@ -32,7 +32,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls @@ -59,7 +60,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls @@ -87,7 +89,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls @@ -115,7 +118,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls @@ -144,7 +148,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls @@ -172,7 +177,8 @@ audit_plan_sqls.sql_fingerprint, audit_plan_sqls.sql_text, audit_plan_sqls.schema_name, audit_plan_sqls.info, -IF(audit_plan_sqls.audit_results IS NULL,'being_audited',audit_plan_sqls.audit_results) AS audit_results, +audit_plan_sqls.audit_results, +IF(audit_plan_sqls.audit_results IS NULL,'being_audited','') AS audit_status, audit_plan_sqls.priority FROM sql_manage_records AS audit_plan_sqls