Skip to content

Commit 966b5a4

Browse files
authored
Merge pull request #2858 from actiontech/feat/sql_analysis_api
feat: sql analysis chart api definition
2 parents 30e4565 + a8555db commit 966b5a4

File tree

6 files changed

+302
-1
lines changed

6 files changed

+302
-1
lines changed

sqle/api/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
352352
v1ProjectViewRouter.GET("/:project_name/sql_manages/exports", v1.ExportSqlManagesV1)
353353
v1ProjectViewRouter.GET("/:project_name/sql_manages/rule_tips", v1.GetSqlManageRuleTips)
354354
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis", v1.GetSqlManageSqlAnalysisV1)
355+
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis_chart", v1.GetSqlManageSqlAnalysisChartV1)
355356
v1ProjectViewRouter.POST("/:project_name/sql_manages/send", v1.SendSqlManage)
356357

357358
// sql dev records

sqle/api/controller/v1/sql_manage.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v1
22

33
import (
44
"context"
5-
65
dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
76
"github.com/actiontech/sqle/sqle/api/controller"
87
"github.com/actiontech/sqle/sqle/locale"
@@ -260,6 +259,16 @@ type SqlAnalysis struct {
260259
PerformanceStatistics *PerformanceStatistics `json:"performance_statistics"`
261260
}
262261

262+
type SqlAnalysisChart struct {
263+
Points *[]ChartPoint `json:"points"`
264+
}
265+
266+
type ChartPoint struct {
267+
X *string `json:"x"`
268+
Y *float64 `json:"y"`
269+
Info map[string]string `json:"info"`
270+
}
271+
263272
type GetSqlManageSqlAnalysisResp struct {
264273
controller.BaseRes
265274
// V1版本不能引用V2版本的结构体,所以只能复制一份
@@ -290,6 +299,32 @@ func GetSqlManageSqlAnalysisV1(c echo.Context) error {
290299
return getSqlManageSqlAnalysisV1(c)
291300
}
292301

302+
type SqlManageAnalysisChartReq struct {
303+
Duration *string `query:"duration" json:"duration"`
304+
MetricName *string `query:"metric_name" json:"metric_name"`
305+
}
306+
307+
type SqlManageAnalysisChartResp struct {
308+
controller.BaseRes
309+
Data *SqlAnalysisChart `json:"data"`
310+
}
311+
312+
// GetSqlManageSqlAnalysisChartV1
313+
// @Summary 获取SQL管控SQL执行计划Cost趋势图表
314+
// @Description get sql manage analysis
315+
// @Id GetSqlManageSqlAnalysisChartV1
316+
// @Tags SqlManage
317+
// @Param project_name path string true "project name"
318+
// @Param sql_manage_id path string true "sql manage id"
319+
// @Param duration query string true "duration"
320+
// @Param metric_name query string true "metric_name"
321+
// @Security ApiKeyAuth
322+
// @Success 200 {object} SqlManageAnalysisChartResp
323+
// @Router /v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart [get]
324+
func GetSqlManageSqlAnalysisChartV1(c echo.Context) error {
325+
return getSqlManageSqlAnalysisChartV1(c)
326+
}
327+
293328
// SendSqlManage
294329
// @Summary 推送SQL管控结果到外部系统
295330
// @Description get sql manage analysis

sqle/api/controller/v1/sql_manager_ce.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func getSqlManageSqlAnalysisV1(c echo.Context) error {
3636
return ErrCommunityEditionNotSupportSqlManage
3737
}
3838

39+
func getSqlManageSqlAnalysisChartV1(c echo.Context) error {
40+
return ErrCommunityEditionNotSupportSqlManage
41+
}
42+
3943
func getAuditPlanUnsolvedSQLCount(auditPlanId uint) (int64, error) {
4044
return 0, nil
4145
}

sqle/docs/docs.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5493,6 +5493,59 @@ var doc = `{
54935493
}
54945494
}
54955495
},
5496+
"/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart": {
5497+
"get": {
5498+
"security": [
5499+
{
5500+
"ApiKeyAuth": []
5501+
}
5502+
],
5503+
"description": "get sql manage analysis",
5504+
"tags": [
5505+
"SqlManage"
5506+
],
5507+
"summary": "获取SQL管控SQL执行计划Cost趋势图表",
5508+
"operationId": "GetSqlManageSqlAnalysisChartV1",
5509+
"parameters": [
5510+
{
5511+
"type": "string",
5512+
"description": "project name",
5513+
"name": "project_name",
5514+
"in": "path",
5515+
"required": true
5516+
},
5517+
{
5518+
"type": "string",
5519+
"description": "sql manage id",
5520+
"name": "sql_manage_id",
5521+
"in": "path",
5522+
"required": true
5523+
},
5524+
{
5525+
"type": "string",
5526+
"description": "duration",
5527+
"name": "duration",
5528+
"in": "query",
5529+
"required": true
5530+
},
5531+
{
5532+
"type": "string",
5533+
"description": "metric_name",
5534+
"name": "metric_name",
5535+
"in": "query",
5536+
"required": true
5537+
}
5538+
],
5539+
"responses": {
5540+
"200": {
5541+
"description": "OK",
5542+
"schema": {
5543+
"$ref": "#/definitions/v1.SqlManageAnalysisChartResp"
5544+
}
5545+
}
5546+
}
5547+
}
5548+
},
54965549
"/v1/projects/{project_name}/sql_optimization_records": {
54975550
"get": {
54985551
"security": [
@@ -12338,6 +12391,23 @@ var doc = `{
1233812391
}
1233912392
}
1234012393
},
12394+
"v1.ChartPoint": {
12395+
"type": "object",
12396+
"properties": {
12397+
"info": {
12398+
"type": "object",
12399+
"additionalProperties": {
12400+
"type": "string"
12401+
}
12402+
},
12403+
"x": {
12404+
"type": "string"
12405+
},
12406+
"y": {
12407+
"type": "number"
12408+
}
12409+
}
12410+
},
1234112411
"v1.CheckLicenseResV1": {
1234212412
"type": "object",
1234312413
"properties": {
@@ -17288,6 +17358,17 @@ var doc = `{
1728817358
}
1728917359
}
1729017360
},
17361+
"v1.SqlAnalysisChart": {
17362+
"type": "object",
17363+
"properties": {
17364+
"points": {
17365+
"type": "array",
17366+
"items": {
17367+
"$ref": "#/definitions/v1.ChartPoint"
17368+
}
17369+
}
17370+
}
17371+
},
1729117372
"v1.SqlAnalysisResDataV1": {
1729217373
"type": "object",
1729317374
"properties": {
@@ -17457,6 +17538,23 @@ var doc = `{
1745717538
}
1745817539
}
1745917540
},
17541+
"v1.SqlManageAnalysisChartResp": {
17542+
"type": "object",
17543+
"properties": {
17544+
"code": {
17545+
"type": "integer",
17546+
"example": 0
17547+
},
17548+
"data": {
17549+
"type": "object",
17550+
"$ref": "#/definitions/v1.SqlAnalysisChart"
17551+
},
17552+
"message": {
17553+
"type": "string",
17554+
"example": "ok"
17555+
}
17556+
}
17557+
},
1746017558
"v1.SqlManageCodingReq": {
1746117559
"type": "object",
1746217560
"properties": {

sqle/docs/swagger.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5477,6 +5477,59 @@
54775477
}
54785478
}
54795479
},
5480+
"/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart": {
5481+
"get": {
5482+
"security": [
5483+
{
5484+
"ApiKeyAuth": []
5485+
}
5486+
],
5487+
"description": "get sql manage analysis",
5488+
"tags": [
5489+
"SqlManage"
5490+
],
5491+
"summary": "获取SQL管控SQL执行计划Cost趋势图表",
5492+
"operationId": "GetSqlManageSqlAnalysisChartV1",
5493+
"parameters": [
5494+
{
5495+
"type": "string",
5496+
"description": "project name",
5497+
"name": "project_name",
5498+
"in": "path",
5499+
"required": true
5500+
},
5501+
{
5502+
"type": "string",
5503+
"description": "sql manage id",
5504+
"name": "sql_manage_id",
5505+
"in": "path",
5506+
"required": true
5507+
},
5508+
{
5509+
"type": "string",
5510+
"description": "duration",
5511+
"name": "duration",
5512+
"in": "query",
5513+
"required": true
5514+
},
5515+
{
5516+
"type": "string",
5517+
"description": "metric_name",
5518+
"name": "metric_name",
5519+
"in": "query",
5520+
"required": true
5521+
}
5522+
],
5523+
"responses": {
5524+
"200": {
5525+
"description": "OK",
5526+
"schema": {
5527+
"$ref": "#/definitions/v1.SqlManageAnalysisChartResp"
5528+
}
5529+
}
5530+
}
5531+
}
5532+
},
54805533
"/v1/projects/{project_name}/sql_optimization_records": {
54815534
"get": {
54825535
"security": [
@@ -12322,6 +12375,23 @@
1232212375
}
1232312376
}
1232412377
},
12378+
"v1.ChartPoint": {
12379+
"type": "object",
12380+
"properties": {
12381+
"info": {
12382+
"type": "object",
12383+
"additionalProperties": {
12384+
"type": "string"
12385+
}
12386+
},
12387+
"x": {
12388+
"type": "string"
12389+
},
12390+
"y": {
12391+
"type": "number"
12392+
}
12393+
}
12394+
},
1232512395
"v1.CheckLicenseResV1": {
1232612396
"type": "object",
1232712397
"properties": {
@@ -17272,6 +17342,17 @@
1727217342
}
1727317343
}
1727417344
},
17345+
"v1.SqlAnalysisChart": {
17346+
"type": "object",
17347+
"properties": {
17348+
"points": {
17349+
"type": "array",
17350+
"items": {
17351+
"$ref": "#/definitions/v1.ChartPoint"
17352+
}
17353+
}
17354+
}
17355+
},
1727517356
"v1.SqlAnalysisResDataV1": {
1727617357
"type": "object",
1727717358
"properties": {
@@ -17441,6 +17522,23 @@
1744117522
}
1744217523
}
1744317524
},
17525+
"v1.SqlManageAnalysisChartResp": {
17526+
"type": "object",
17527+
"properties": {
17528+
"code": {
17529+
"type": "integer",
17530+
"example": 0
17531+
},
17532+
"data": {
17533+
"type": "object",
17534+
"$ref": "#/definitions/v1.SqlAnalysisChart"
17535+
},
17536+
"message": {
17537+
"type": "string",
17538+
"example": "ok"
17539+
}
17540+
}
17541+
},
1744417542
"v1.SqlManageCodingReq": {
1744517543
"type": "object",
1744617544
"properties": {

0 commit comments

Comments
 (0)