Skip to content

Commit

Permalink
Merge pull request #2046 from actiontech/issue-1191-2
Browse files Browse the repository at this point in the history
feat:sql manage add new field endpoint
  • Loading branch information
ColdWaterLW authored Nov 17, 2023
2 parents 50274ff + adde5d6 commit 8eeba6a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions sqle/api/controller/v1/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ func convertToModelAuditPlanSQL(c echo.Context, auditPlan *model.AuditPlan, reqS
SQLContent: reqSQL.LastReceiveText,
Info: info,
Schema: reqSQL.Schema,
Endpoint: reqSQL.Endpoint,
})
}
return sqls, nil
Expand Down
8 changes: 5 additions & 3 deletions sqle/model/audit_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type AuditPlanSQLV2 struct {
SQLContent string `json:"sql" gorm:"type:mediumtext;not null"`
Info JSON `gorm:"type:json"`
Schema string `json:"schema" gorm:"type:varchar(512);not null"`
// 可能是URL或IP地址等
Endpoint string `json:"endpoint" gorm:"type:varchar(512)"`
}

type BlackListAuditPlanSQL struct {
Expand Down Expand Up @@ -280,10 +282,10 @@ ON DUPLICATE KEY UPDATE sql_content = VALUES(sql_content),
func getBatchInsertRawSQL(auditPlanId uint, sqls []*AuditPlanSQLV2) (raw string, args []interface{}) {
pattern := make([]string, 0, len(sqls))
for _, sql := range sqls {
pattern = append(pattern, "(?, ?, ?, ?, ?, ?)")
args = append(args, auditPlanId, sql.GetFingerprintMD5(), sql.Fingerprint, sql.SQLContent, sql.Info, sql.Schema)
pattern = append(pattern, "(?, ?, ?, ?, ?, ?, ?)")
args = append(args, auditPlanId, sql.GetFingerprintMD5(), sql.Fingerprint, sql.SQLContent, sql.Info, sql.Schema, sql.Endpoint)
}
raw = fmt.Sprintf("INSERT INTO `audit_plan_sqls_v2` (`audit_plan_id`,`fingerprint_md5`, `fingerprint`, `sql_content`, `info`, `schema`) VALUES %s",
raw = fmt.Sprintf("INSERT INTO `audit_plan_sqls_v2` (`audit_plan_id`,`fingerprint_md5`, `fingerprint`, `sql_content`, `info`, `schema`, `endpoint`) VALUES %s",
strings.Join(pattern, ", "))
return
}
Expand Down
5 changes: 3 additions & 2 deletions sqle/model/audit_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestStorage_OverrideAuditPlanSQLs(t *testing.T) {
SQLContent: "select * from t1 where id = 1",
Info: []byte(`{"counter": 1, "last_receive_timestamp": "mock time"}`),
Schema: "test1",
Endpoint: "10.186.1.2",
},
}

Expand All @@ -149,8 +150,8 @@ func TestStorage_OverrideAuditPlanSQLs(t *testing.T) {
WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectCommit()

mock.ExpectExec("INSERT INTO `audit_plan_sqls_v2` (`audit_plan_id`,`fingerprint_md5`, `fingerprint`, `sql_content`, `info`, `schema`) VALUES (?, ?, ?, ?, ?, ?);").
WithArgs(ap.ID, sqls[0].GetFingerprintMD5(), sqls[0].Fingerprint, sqls[0].SQLContent, sqls[0].Info, sqls[0].Schema).
mock.ExpectExec("INSERT INTO `audit_plan_sqls_v2` (`audit_plan_id`,`fingerprint_md5`, `fingerprint`, `sql_content`, `info`, `schema`, `endpoint`) VALUES (?, ?, ?, ?, ?, ?, ?);").
WithArgs(ap.ID, sqls[0].GetFingerprintMD5(), sqls[0].Fingerprint, sqls[0].SQLContent, sqls[0].Info, sqls[0].Schema, sqls[0].Endpoint).
WillReturnResult(sqlmock.NewResult(1, 1))

err = GetStorage().OverrideAuditPlanSQLs(ap.ID, sqls)
Expand Down
1 change: 1 addition & 0 deletions sqle/model/sql_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type SqlManage struct {
LastReceiveTimestamp *time.Time `json:"last_receive_timestamp"`
InstanceName string `json:"instance_name"`
SchemaName string `json:"schema_name"`
Endpoint string `json:"endpoint"`

Assignees []*User `gorm:"many2many:sql_manage_assignees;"`
Status string `json:"status" gorm:"default:\"unhandled\""`
Expand Down
2 changes: 2 additions & 0 deletions sqle/server/auditplan/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type SQL struct {
SQLContent string
Fingerprint string
Schema string
Endpoint string
Info map[string]interface{}
}

Expand Down Expand Up @@ -277,6 +278,7 @@ func convertSQLsToModelSQLs(sqls []*SQL) []*model.AuditPlanSQLV2 {
SQLContent: sql.SQLContent,
Schema: sql.Schema,
Info: data,
Endpoint: sql.Endpoint,
}
}
return as
Expand Down

0 comments on commit 8eeba6a

Please sign in to comment.