From 139602ba84b5001c385c1adb8a2f050cff6c1328 Mon Sep 17 00:00:00 2001 From: taolx0 Date: Mon, 18 Dec 2023 16:10:47 +0800 Subject: [PATCH 1/2] sql analysis api define --- sqle/api/app.go | 1 + sqle/api/controller/v1/sql_manage.go | 39 ++++++++++ sqle/docs/docs.go | 107 +++++++++++++++++++++++++++ sqle/docs/swagger.json | 107 +++++++++++++++++++++++++++ sqle/docs/swagger.yaml | 71 ++++++++++++++++++ 5 files changed, 325 insertions(+) diff --git a/sqle/api/app.go b/sqle/api/app.go index 54f52d8133..4544435294 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -412,6 +412,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config config.SqleConfi v1Router.PATCH("/projects/:project_name/sql_manages/batch", v1.BatchUpdateSqlManage) v1Router.GET("/projects/:project_name/sql_manages/exports", v1.ExportSqlManagesV1) v1Router.GET("/projects/:project_name/sql_manages/rule_tips", v1.GetSqlManageRuleTips) + v1Router.GET("/projects/:project_name/sql_manages/:sql_manage_id/sql_analysis", v1.GetSqlManageSqlAnalysisV1) // sql audit record v1Router.POST("/projects/:project_name/sql_audit_records", v1.CreateSQLAuditRecord) diff --git a/sqle/api/controller/v1/sql_manage.go b/sqle/api/controller/v1/sql_manage.go index 6047e93af5..600c72c57b 100644 --- a/sqle/api/controller/v1/sql_manage.go +++ b/sqle/api/controller/v1/sql_manage.go @@ -181,3 +181,42 @@ type GetSqlManageRuleTipsResp struct { func GetSqlManageRuleTips(c echo.Context) error { return getSqlManageRuleTips(c) } + +type AffectRows struct { + Count int `json:"count"` + ErrMessage string `json:"err_message"` +} + +type PerformanceStatistics struct { + AffectRows *AffectRows `json:"affect_rows"` +} + +type TableMetas struct { + ErrMessage string `json:"err_message"` + Items []*TableMeta `json:"table_meta_items"` +} + +type SqlAnalysis struct { + SQLExplain *SQLExplain `json:"sql_explain"` + TableMetas *TableMetas `json:"table_metas"` + PerformanceStatistics *PerformanceStatistics `json:"performance_statistics"` +} + +type GetSqlManageSqlAnalysisResp struct { + controller.BaseRes + Data *SqlAnalysis `json:"data"` +} + +// GetSqlManageSqlAnalysisV1 +// @Summary 获取SQL管控SQL分析 +// @Description get sql manage analysis +// @Id GetSqlManageSqlAnalysisV1 +// @Tags SqlManage +// @Param project_name path string true "project name" +// @Param sql_manage_id path string true "sql manage id" +// @Security ApiKeyAuth +// @Success 200 {object} GetSqlManageSqlAnalysisResp +// @Router /v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis [get] +func GetSqlManageSqlAnalysisV1(c echo.Context) error { + return nil +} diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 2c4b48e57e..f84496c5cf 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -5081,6 +5081,45 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get sql manage analysis", + "tags": [ + "SqlManage" + ], + "summary": "获取SQL管控SQL分析", + "operationId": "GetSqlManageSqlAnalysisV1", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "sql manage id", + "name": "sql_manage_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlManageSqlAnalysisResp" + } + } + } + } + }, "/v1/projects/{project_name}/statistic/audit_plans": { "get": { "security": [ @@ -10363,6 +10402,17 @@ var doc = `{ } } }, + "v1.AffectRows": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "err_message": { + "type": "string" + } + } + }, "v1.AuditPlanCount": { "type": "object", "properties": { @@ -13287,6 +13337,23 @@ var doc = `{ } } }, + "v1.GetSqlManageSqlAnalysisResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.SqlAnalysis" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetSyncInstanceTaskListResV1": { "type": "object", "properties": { @@ -14544,6 +14611,15 @@ var doc = `{ } } }, + "v1.PerformanceStatistics": { + "type": "object", + "properties": { + "affect_rows": { + "type": "object", + "$ref": "#/definitions/v1.AffectRows" + } + } + }, "v1.PersonaliseReqV1": { "type": "object", "properties": { @@ -15136,6 +15212,23 @@ var doc = `{ } } }, + "v1.SqlAnalysis": { + "type": "object", + "properties": { + "performance_statistics": { + "type": "object", + "$ref": "#/definitions/v1.PerformanceStatistics" + }, + "sql_explain": { + "type": "object", + "$ref": "#/definitions/v1.SQLExplain" + }, + "table_metas": { + "type": "object", + "$ref": "#/definitions/v1.TableMetas" + } + } + }, "v1.SqlAnalysisResDataV1": { "type": "object", "properties": { @@ -15422,6 +15515,20 @@ var doc = `{ } } }, + "v1.TableMetas": { + "type": "object", + "properties": { + "err_message": { + "type": "string" + }, + "table_meta_items": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.TableMeta" + } + } + } + }, "v1.TestAuditPlanNotifyConfigResDataV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 612ab90dd1..fd7641a79b 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -5065,6 +5065,45 @@ } } }, + "/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get sql manage analysis", + "tags": [ + "SqlManage" + ], + "summary": "获取SQL管控SQL分析", + "operationId": "GetSqlManageSqlAnalysisV1", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "sql manage id", + "name": "sql_manage_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlManageSqlAnalysisResp" + } + } + } + } + }, "/v1/projects/{project_name}/statistic/audit_plans": { "get": { "security": [ @@ -10347,6 +10386,17 @@ } } }, + "v1.AffectRows": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "err_message": { + "type": "string" + } + } + }, "v1.AuditPlanCount": { "type": "object", "properties": { @@ -13271,6 +13321,23 @@ } } }, + "v1.GetSqlManageSqlAnalysisResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.SqlAnalysis" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetSyncInstanceTaskListResV1": { "type": "object", "properties": { @@ -14528,6 +14595,15 @@ } } }, + "v1.PerformanceStatistics": { + "type": "object", + "properties": { + "affect_rows": { + "type": "object", + "$ref": "#/definitions/v1.AffectRows" + } + } + }, "v1.PersonaliseReqV1": { "type": "object", "properties": { @@ -15120,6 +15196,23 @@ } } }, + "v1.SqlAnalysis": { + "type": "object", + "properties": { + "performance_statistics": { + "type": "object", + "$ref": "#/definitions/v1.PerformanceStatistics" + }, + "sql_explain": { + "type": "object", + "$ref": "#/definitions/v1.SQLExplain" + }, + "table_metas": { + "type": "object", + "$ref": "#/definitions/v1.TableMetas" + } + } + }, "v1.SqlAnalysisResDataV1": { "type": "object", "properties": { @@ -15406,6 +15499,20 @@ } } }, + "v1.TableMetas": { + "type": "object", + "properties": { + "err_message": { + "type": "string" + }, + "table_meta_items": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.TableMeta" + } + } + } + }, "v1.TestAuditPlanNotifyConfigResDataV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 0bf41cbc32..d66075e64d 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -9,6 +9,13 @@ definitions: example: ok type: string type: object + v1.AffectRows: + properties: + count: + type: integer + err_message: + type: string + type: object v1.AuditPlanCount: properties: audit_plan_count: @@ -2022,6 +2029,18 @@ definitions: example: ok type: string type: object + v1.GetSqlManageSqlAnalysisResp: + properties: + code: + example: 0 + type: integer + data: + $ref: '#/definitions/v1.SqlAnalysis' + type: object + message: + example: ok + type: string + type: object v1.GetSyncInstanceTaskListResV1: properties: code: @@ -2878,6 +2897,12 @@ definitions: type: string type: array type: object + v1.PerformanceStatistics: + properties: + affect_rows: + $ref: '#/definitions/v1.AffectRows' + type: object + type: object v1.PersonaliseReqV1: properties: title: @@ -3272,6 +3297,18 @@ definitions: - sql_audit_record type: string type: object + v1.SqlAnalysis: + properties: + performance_statistics: + $ref: '#/definitions/v1.PerformanceStatistics' + type: object + sql_explain: + $ref: '#/definitions/v1.SQLExplain' + type: object + table_metas: + $ref: '#/definitions/v1.TableMetas' + type: object + type: object v1.SqlAnalysisResDataV1: properties: sql_explain: @@ -3463,6 +3500,15 @@ definitions: field_name: type: string type: object + v1.TableMetas: + properties: + err_message: + type: string + table_meta_items: + items: + $ref: '#/definitions/v1.TableMeta' + type: array + type: object v1.TestAuditPlanNotifyConfigResDataV1: properties: is_notify_send_normal: @@ -8263,6 +8309,31 @@ paths: summary: 获取管控sql列表 tags: - SqlManage + /v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis: + get: + description: get sql manage analysis + operationId: GetSqlManageSqlAnalysisV1 + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: sql manage id + in: path + name: sql_manage_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetSqlManageSqlAnalysisResp' + security: + - ApiKeyAuth: [] + summary: 获取SQL管控SQL分析 + tags: + - SqlManage /v1/projects/{project_name}/sql_manages/batch: patch: description: batch update sql manage From dff48d43b5fa52319410f44fb986692c9f05007a Mon Sep 17 00:00:00 2001 From: taolx0 Date: Wed, 20 Dec 2023 10:13:49 +0800 Subject: [PATCH 2/2] add annotation --- sqle/api/controller/v1/sql_manage.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sqle/api/controller/v1/sql_manage.go b/sqle/api/controller/v1/sql_manage.go index 600c72c57b..7ebccb9e96 100644 --- a/sqle/api/controller/v1/sql_manage.go +++ b/sqle/api/controller/v1/sql_manage.go @@ -204,6 +204,7 @@ type SqlAnalysis struct { type GetSqlManageSqlAnalysisResp struct { controller.BaseRes + // V1版本不能引用V2版本的结构体,所以只能复制一份 Data *SqlAnalysis `json:"data"` }