diff --git a/sqle/api/app.go b/sqle/api/app.go index 8eb471536..d8573c014 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -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) } { diff --git a/sqle/api/controller/v2/optimization.go b/sqle/api/controller/v2/optimization.go index d9a601a13..6c6d7d426 100644 --- a/sqle/api/controller/v2/optimization.go +++ b/sqle/api/controller/v2/optimization.go @@ -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 { @@ -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 @@ -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) +} diff --git a/sqle/api/controller/v2/optimization_ce.go b/sqle/api/controller/v2/optimization_ce.go index 769e7ae67..b96a99bf1 100644 --- a/sqle/api/controller/v2/optimization_ce.go +++ b/sqle/api/controller/v2/optimization_ce.go @@ -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")) +} diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 076fa7a9b..d58b41c61 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -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": [ @@ -14374,6 +14527,10 @@ var doc = `{ "v2.OptimizationRecord": { "type": "object", "properties": { + "adoption_rate": { + "description": "优化采纳率", + "type": "number" + }, "created_time": { "description": "创建时间", "type": "string" @@ -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", @@ -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": { @@ -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": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 5698047d7..575849f0c 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -7687,6 +7687,159 @@ } } }, + "/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": [ @@ -14358,6 +14511,10 @@ "v2.OptimizationRecord": { "type": "object", "properties": { + "adoption_rate": { + "description": "优化采纳率", + "type": "number" + }, "created_time": { "description": "创建时间", "type": "string" @@ -14431,6 +14588,13 @@ "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", @@ -14524,6 +14688,47 @@ } } }, + "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": { @@ -14672,6 +14877,23 @@ } } }, + "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": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index a2ca3fedb..af98421fd 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -4067,6 +4067,9 @@ definitions: type: object v2.OptimizationRecord: properties: + adoption_rate: + description: 优化采纳率 + type: number created_time: description: 创建时间 type: string @@ -4121,6 +4124,11 @@ definitions: $ref: '#/definitions/sql_flash.OptimizeDetail' description: 优化详情 type: object + optimized_sql_feedbacks: + description: 优化后的SQL反馈 + items: + $ref: '#/definitions/v2.OptimizedSQLFeedback' + type: array origin_query_plan: $ref: '#/definitions/sql_flash.QueryPlan' description: 原始SQL查询计划 @@ -4188,6 +4196,34 @@ definitions: sql_optimization_record_id: type: string type: object + v2.OptimizedSQLFeedback: + properties: + created_at: + type: string + creator: + type: string + id: + type: integer + reason: + type: string + vote: + enum: + - agree + - disagree + type: string + type: object + v2.OptimizedSQLFeedbackReq: + properties: + reason: + example: the sql is not optimized + type: string + vote: + enum: + - agree + - disagree + example: agree + type: string + type: object v2.PartialSyncAuditPlanSQLsReqV2: properties: audit_plan_sql_list: @@ -4287,6 +4323,18 @@ definitions: $ref: '#/definitions/v2.TableMetas' type: object type: object + v2.UpdateOptimizedSQLFeedbackReq: + properties: + reason: + example: the sql is not optimized + type: string + vote: + enum: + - agree + - disagree + example: agree + type: string + type: object v2.UpdateWorkflowReqV2: properties: task_ids: @@ -9400,6 +9448,106 @@ paths: summary: 获取SQL优化语句详情 tags: - sql_optimization + /v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback: + post: + consumes: + - application/json + description: add optimized sql feedback + operationId: AddOptimizedSQLFeedback + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: sql optimization record id + in: path + name: optimization_record_id + required: true + type: string + - description: add optimized sql feedback req + in: body + name: instance + required: true + schema: + $ref: '#/definitions/v2.OptimizedSQLFeedbackReq' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 添加SQL优化语句反馈 + tags: + - sql_optimization + /v2/projects/{project_name}/sql_optimization_records/{optimization_record_id}/feedback/{feedback_id}/: + delete: + description: delete optimized sql feedback + operationId: DeleteOptimizedSQLFeedback + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: sql optimization record id + in: path + name: optimization_record_id + required: true + type: string + - description: feedback id + in: path + name: feedback_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 删除SQL优化语句反馈 + tags: + - sql_optimization + patch: + consumes: + - application/json + description: update optimized sql feedback + operationId: UpdateOptimizedSQLFeedback + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: sql optimization record id + in: path + name: optimization_record_id + required: true + type: string + - description: feedback id + in: path + name: feedback_id + required: true + type: string + - description: update optimized sql feedback req + in: body + name: instance + required: true + schema: + $ref: '#/definitions/v2.UpdateOptimizedSQLFeedbackReq' + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 更新SQL优化语句反馈 + tags: + - sql_optimization /v2/projects/{project_name}/workflows: post: consumes: