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
4 changes: 3 additions & 1 deletion sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v2ProjectRouter.POST("/:project_name/sql_optimization_records", v2.SQLOptimize)
v2ProjectRouter.GET("/:project_name/sql_optimization_records", v2.GetOptimizationRecords)
v2ProjectRouter.GET("/:project_name/sql_optimization_records/:optimization_record_id/detail", v2.GetOptimizationSQLDetail)

v2ProjectRouter.POST("/:project_name/sql_optimization_records/:optimization_record_id/feedback", v2.AddOptimizedSQLFeedback)
v2ProjectRouter.PATCH("/:project_name/sql_optimization_records/:optimization_record_id/feedback/:feedback_id", v2.UpdateOptimizedSQLFeedback)
v2ProjectRouter.DELETE("/:project_name/sql_optimization_records/:optimization_record_id/feedback/:feedback_id", v2.DeleteOptimizedSQLFeedback)
}

{
Expand Down
69 changes: 69 additions & 0 deletions sqle/api/controller/v2/optimization.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type OptimizationRecord struct {
PerformanceImprove float64 `json:"performance_improve"` // 优化提升性能
NumberOfRule int `json:"number_of_rule"` // 优化规则数量
NumberOfIndex int `json:"number_of_index"` // 优化索引数量
AdoptionRate *float64 `json:"adoption_rate"` // 优化采纳率
}

type GetOptimizationRecordsRes struct {
Expand Down Expand Up @@ -142,6 +143,16 @@ type OptimizationSQLDetail struct {
TotalAnalysis *sql_flash.TotalAnalysis `json:"total_analysis"` // 总体分析
AdvisedIndex *sql_flash.AdvisedIndex `json:"advised_index"` // 索引建议详情

OptimizedSQLFeedbacks []*OptimizedSQLFeedback `json:"optimized_sql_feedbacks,omitempty"` // 优化后的SQL反馈

}

type OptimizedSQLFeedback struct {
ID uint `json:"id"`
Vote string `json:"vote" enums:"agree,disagree"`
Reason string `json:"reason"`
Creator string `json:"creator"`
CreatedAt time.Time `json:"created_at"`
}

// GetOptimizationSQLDetail
Expand All @@ -157,3 +168,61 @@ type OptimizationSQLDetail struct {
func GetOptimizationSQLDetail(c echo.Context) error {
return getOptimizationSQL(c)
}

type OptimizedSQLFeedbackReq struct {
Vote string `json:"vote" example:"agree" enums:"agree,disagree" valid:"required,oneof=agree disagree"`
Reason string `json:"reason" example:"the sql is not optimized"`
}

// AddOptimizedSQLFeedback
// @Summary 添加SQL优化语句反馈
// @Description add optimized sql feedback
// @Accept json
// @Id AddOptimizedSQLFeedback
// @Tags sql_optimization
// @Security ApiKeyAuth
// @Param project_name path string true "project name"
// @Param optimization_record_id path string true "sql optimization record id"
// @Param instance body v2.OptimizedSQLFeedbackReq true "add optimized sql feedback req"
// @Success 200 {object} controller.BaseRes
// @router /v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback [post]
func AddOptimizedSQLFeedback(c echo.Context) error {
return addOptimizedSQLFeedback(c)
}

type UpdateOptimizedSQLFeedbackReq struct {
Vote string `json:"vote" example:"agree" enums:"agree,disagree"`
Reason string `json:"reason" example:"the sql is not optimized"`
}

// UpdateOptimizedSQLFeedback
// @Summary 更新SQL优化语句反馈
// @Description update optimized sql feedback
// @Accept json
// @Id UpdateOptimizedSQLFeedback
// @Tags sql_optimization
// @Param project_name path string true "project name"
// @Param optimization_record_id path string true "sql optimization record id"
// @Param feedback_id path string true "feedback id"
// @Param instance body v2.UpdateOptimizedSQLFeedbackReq true "update optimized sql feedback req"
// @Security ApiKeyAuth
// @Success 200 {object} controller.BaseRes
// @router /v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback/{feedback_id}/ [patch]
func UpdateOptimizedSQLFeedback(c echo.Context) error {
return updateOptimizedSQLFeedback(c)
}

// DeleteOptimizedSQLFeedback
// @Summary 删除SQL优化语句反馈
// @Description delete optimized sql feedback
// @Id DeleteOptimizedSQLFeedback
// @Tags sql_optimization
// @Param project_name path string true "project name"
// @Param optimization_record_id path string true "sql optimization record id"
// @Param feedback_id path string true "feedback id"
// @Security ApiKeyAuth
// @Success 200 {object} controller.BaseRes
// @router /v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback/{feedback_id}/ [delete]
func DeleteOptimizedSQLFeedback(c echo.Context) error {
return deleteOptimizedSQLFeedback(c)
}
12 changes: 12 additions & 0 deletions sqle/api/controller/v2/optimization_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ func getOptimizationRecords(c echo.Context) error {
func getOptimizationSQL(c echo.Context) error {
return errors.New(errors.SQLOptimizationCommunityNotSupported, e.New("sql optimization community not supported"))
}

func addOptimizedSQLFeedback(c echo.Context) error {
return errors.New(errors.SQLOptimizationCommunityNotSupported, e.New("sql optimization community not supported"))
}

func updateOptimizedSQLFeedback(c echo.Context) error {
return errors.New(errors.SQLOptimizationCommunityNotSupported, e.New("sql optimization community not supported"))
}

func deleteOptimizedSQLFeedback(c echo.Context) error {
return errors.New(errors.SQLOptimizationCommunityNotSupported, e.New("sql optimization community not supported"))
}
222 changes: 222 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7703,6 +7703,159 @@ var doc = `{
}
}
},
"/v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "add optimized sql feedback",
"consumes": [
"application/json"
],
"tags": [
"sql_optimization"
],
"summary": "添加SQL优化语句反馈",
"operationId": "AddOptimizedSQLFeedback",
"parameters": [
{
"type": "string",
"description": "project name",
"name": "project_name",
"in": "path",
"required": true
},
{
"type": "string",
"description": "sql optimization record id",
"name": "optimization_record_id",
"in": "path",
"required": true
},
{
"description": "add optimized sql feedback req",
"name": "instance",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v2.OptimizedSQLFeedbackReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.BaseRes"
}
}
}
}
},
"/v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback/{feedback_id}/": {
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "delete optimized sql feedback",
"tags": [
"sql_optimization"
],
"summary": "删除SQL优化语句反馈",
"operationId": "DeleteOptimizedSQLFeedback",
"parameters": [
{
"type": "string",
"description": "project name",
"name": "project_name",
"in": "path",
"required": true
},
{
"type": "string",
"description": "sql optimization record id",
"name": "optimization_record_id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "feedback id",
"name": "feedback_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.BaseRes"
}
}
}
},
"patch": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "update optimized sql feedback",
"consumes": [
"application/json"
],
"tags": [
"sql_optimization"
],
"summary": "更新SQL优化语句反馈",
"operationId": "UpdateOptimizedSQLFeedback",
"parameters": [
{
"type": "string",
"description": "project name",
"name": "project_name",
"in": "path",
"required": true
},
{
"type": "string",
"description": "sql optimization record id",
"name": "optimization_record_id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "feedback id",
"name": "feedback_id",
"in": "path",
"required": true
},
{
"description": "update optimized sql feedback req",
"name": "instance",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v2.UpdateOptimizedSQLFeedbackReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/controller.BaseRes"
}
}
}
}
},
"/v2/projects/{project_name}/workflows": {
"post": {
"security": [
Expand Down Expand Up @@ -14374,6 +14527,10 @@ var doc = `{
"v2.OptimizationRecord": {
"type": "object",
"properties": {
"adoption_rate": {
"description": "优化采纳率",
"type": "number"
},
"created_time": {
"description": "创建时间",
"type": "string"
Expand Down Expand Up @@ -14447,6 +14604,13 @@ var doc = `{
"type": "object",
"$ref": "#/definitions/sql_flash.OptimizeDetail"
},
"optimized_sql_feedbacks": {
"description": "优化后的SQL反馈",
"type": "array",
"items": {
"$ref": "#/definitions/v2.OptimizedSQLFeedback"
}
},
"origin_query_plan": {
"description": "原始SQL查询计划",
"type": "object",
Expand Down Expand Up @@ -14540,6 +14704,47 @@ var doc = `{
}
}
},
"v2.OptimizedSQLFeedback": {
"type": "object",
"properties": {
"created_at": {
"type": "string"
},
"creator": {
"type": "string"
},
"id": {
"type": "integer"
},
"reason": {
"type": "string"
},
"vote": {
"type": "string",
"enum": [
"agree",
"disagree"
]
}
}
},
"v2.OptimizedSQLFeedbackReq": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"example": "the sql is not optimized"
},
"vote": {
"type": "string",
"enum": [
"agree",
"disagree"
],
"example": "agree"
}
}
},
"v2.PartialSyncAuditPlanSQLsReqV2": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -14688,6 +14893,23 @@ var doc = `{
}
}
},
"v2.UpdateOptimizedSQLFeedbackReq": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"example": "the sql is not optimized"
},
"vote": {
"type": "string",
"enum": [
"agree",
"disagree"
],
"example": "agree"
}
}
},
"v2.UpdateWorkflowReqV2": {
"type": "object",
"properties": {
Expand Down
Loading
Loading