Skip to content

Commit

Permalink
Merge pull request #2858 from actiontech/feat/sql_analysis_api
Browse files Browse the repository at this point in the history
feat: sql analysis chart api definition
  • Loading branch information
BugsGuru authored Jan 7, 2025
2 parents 30e4565 + a8555db commit 966b5a4
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 1 deletion.
1 change: 1 addition & 0 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v1ProjectViewRouter.GET("/:project_name/sql_manages/exports", v1.ExportSqlManagesV1)
v1ProjectViewRouter.GET("/:project_name/sql_manages/rule_tips", v1.GetSqlManageRuleTips)
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis", v1.GetSqlManageSqlAnalysisV1)
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis_chart", v1.GetSqlManageSqlAnalysisChartV1)
v1ProjectViewRouter.POST("/:project_name/sql_manages/send", v1.SendSqlManage)

// sql dev records
Expand Down
37 changes: 36 additions & 1 deletion sqle/api/controller/v1/sql_manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1

import (
"context"

dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"github.com/actiontech/sqle/sqle/api/controller"
"github.com/actiontech/sqle/sqle/locale"
Expand Down Expand Up @@ -260,6 +259,16 @@ type SqlAnalysis struct {
PerformanceStatistics *PerformanceStatistics `json:"performance_statistics"`
}

type SqlAnalysisChart struct {
Points *[]ChartPoint `json:"points"`
}

type ChartPoint struct {
X *string `json:"x"`
Y *float64 `json:"y"`
Info map[string]string `json:"info"`
}

type GetSqlManageSqlAnalysisResp struct {
controller.BaseRes
// V1版本不能引用V2版本的结构体,所以只能复制一份
Expand Down Expand Up @@ -290,6 +299,32 @@ func GetSqlManageSqlAnalysisV1(c echo.Context) error {
return getSqlManageSqlAnalysisV1(c)
}

type SqlManageAnalysisChartReq struct {
Duration *string `query:"duration" json:"duration"`
MetricName *string `query:"metric_name" json:"metric_name"`
}

type SqlManageAnalysisChartResp struct {
controller.BaseRes
Data *SqlAnalysisChart `json:"data"`
}

// GetSqlManageSqlAnalysisChartV1
// @Summary 获取SQL管控SQL执行计划Cost趋势图表
// @Description get sql manage analysis
// @Id GetSqlManageSqlAnalysisChartV1
// @Tags SqlManage
// @Param project_name path string true "project name"
// @Param sql_manage_id path string true "sql manage id"
// @Param duration query string true "duration"
// @Param metric_name query string true "metric_name"
// @Security ApiKeyAuth
// @Success 200 {object} SqlManageAnalysisChartResp
// @Router /v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart [get]
func GetSqlManageSqlAnalysisChartV1(c echo.Context) error {
return getSqlManageSqlAnalysisChartV1(c)
}

// SendSqlManage
// @Summary 推送SQL管控结果到外部系统
// @Description get sql manage analysis
Expand Down
4 changes: 4 additions & 0 deletions sqle/api/controller/v1/sql_manager_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func getSqlManageSqlAnalysisV1(c echo.Context) error {
return ErrCommunityEditionNotSupportSqlManage
}

func getSqlManageSqlAnalysisChartV1(c echo.Context) error {
return ErrCommunityEditionNotSupportSqlManage
}

func getAuditPlanUnsolvedSQLCount(auditPlanId uint) (int64, error) {
return 0, nil
}
Expand Down
98 changes: 98 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5493,6 +5493,59 @@ var doc = `{
}
}
},
"/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get sql manage analysis",
"tags": [
"SqlManage"
],
"summary": "获取SQL管控SQL执行计划Cost趋势图表",
"operationId": "GetSqlManageSqlAnalysisChartV1",
"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
},
{
"type": "string",
"description": "duration",
"name": "duration",
"in": "query",
"required": true
},
{
"type": "string",
"description": "metric_name",
"name": "metric_name",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.SqlManageAnalysisChartResp"
}
}
}
}
},
"/v1/projects/{project_name}/sql_optimization_records": {
"get": {
"security": [
Expand Down Expand Up @@ -12338,6 +12391,23 @@ var doc = `{
}
}
},
"v1.ChartPoint": {
"type": "object",
"properties": {
"info": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"x": {
"type": "string"
},
"y": {
"type": "number"
}
}
},
"v1.CheckLicenseResV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -17288,6 +17358,17 @@ var doc = `{
}
}
},
"v1.SqlAnalysisChart": {
"type": "object",
"properties": {
"points": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ChartPoint"
}
}
}
},
"v1.SqlAnalysisResDataV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -17457,6 +17538,23 @@ var doc = `{
}
}
},
"v1.SqlManageAnalysisChartResp": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "object",
"$ref": "#/definitions/v1.SqlAnalysisChart"
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.SqlManageCodingReq": {
"type": "object",
"properties": {
Expand Down
98 changes: 98 additions & 0 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5477,6 +5477,59 @@
}
}
},
"/v1/projects/{project_name}/sql_manages/{sql_manage_id}/sql_analysis_chart": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get sql manage analysis",
"tags": [
"SqlManage"
],
"summary": "获取SQL管控SQL执行计划Cost趋势图表",
"operationId": "GetSqlManageSqlAnalysisChartV1",
"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
},
{
"type": "string",
"description": "duration",
"name": "duration",
"in": "query",
"required": true
},
{
"type": "string",
"description": "metric_name",
"name": "metric_name",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.SqlManageAnalysisChartResp"
}
}
}
}
},
"/v1/projects/{project_name}/sql_optimization_records": {
"get": {
"security": [
Expand Down Expand Up @@ -12322,6 +12375,23 @@
}
}
},
"v1.ChartPoint": {
"type": "object",
"properties": {
"info": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"x": {
"type": "string"
},
"y": {
"type": "number"
}
}
},
"v1.CheckLicenseResV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -17272,6 +17342,17 @@
}
}
},
"v1.SqlAnalysisChart": {
"type": "object",
"properties": {
"points": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ChartPoint"
}
}
}
},
"v1.SqlAnalysisResDataV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -17441,6 +17522,23 @@
}
}
},
"v1.SqlManageAnalysisChartResp": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "object",
"$ref": "#/definitions/v1.SqlAnalysisChart"
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.SqlManageCodingReq": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 966b5a4

Please sign in to comment.