diff --git a/sqle/api/app.go b/sqle/api/app.go index c9bc35ede..281077d59 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -363,6 +363,10 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti v1ProjectViewRouter.POST("/:project_name/sql_manages/send", v1.SendSqlManage) v1ProjectViewRouter.GET("/:project_name/sql_manages/abnormal_audit_plan_instance", v1.GetAbnormalInstanceAuditPlans) + v1ProjectViewRouter.GET("/:project_name/sql_performance_insights", v1.GetSqlPerformanceInsights) + v1ProjectViewRouter.GET("/:project_name/sql_performance_insights/related_sql", v1.GetSqlPerformanceInsightsRelatedSQL) + v1ProjectViewRouter.GET("/:project_name/sql_performance_insights/related_sql/related_transaction", v1.GetSqlPerformanceInsightsRelatedTransaction) + // sql dev records v1ProjectViewRouter.GET("/:project_name/sql_dev_records", v1.GetSqlDEVRecordList) diff --git a/sqle/api/controller/v1/sql_manage.go b/sqle/api/controller/v1/sql_manage.go index 60f1b0496..c29e20186 100644 --- a/sqle/api/controller/v1/sql_manage.go +++ b/sqle/api/controller/v1/sql_manage.go @@ -275,9 +275,10 @@ type SqlAnalysisChart struct { } type ChartPoint struct { - X *string `json:"x"` - Y *float64 `json:"y"` - Infos []map[string]string `json:"info"` + X *string `json:"x"` + Y *float64 `json:"y"` + Infos []map[string]string `json:"info"` + Status *int `json:"status"` } type GetSqlManageSqlAnalysisResp struct { diff --git a/sqle/api/controller/v1/sql_manage_insight.go b/sqle/api/controller/v1/sql_manage_insight.go new file mode 100644 index 000000000..dfdb8d20e --- /dev/null +++ b/sqle/api/controller/v1/sql_manage_insight.go @@ -0,0 +1,223 @@ +package v1 + +import ( + "github.com/actiontech/sqle/sqle/api/controller" + "github.com/labstack/echo/v4" +) + +type GetSqlPerformanceInsightsResp struct { + controller.BaseRes + Data *SqlPerformanceInsights `json:"data"` +} + +// SqlPerformanceInsights SQL性能洞察数据结构体 +type SqlPerformanceInsights struct { + TaskSupport bool `json:"task_support"` // 是否支持任务 + TaskEnable bool `json:"task_enable"` // 是否启用任务 + XInfo string `json:"x_info"` // X轴信息 + YInfo string `json:"y_info"` // Y轴信息 + Message string `json:"message"` // 提示信息 + Lines []Line `json:"lines"` // 图表线条数据 +} + +// Line 图表线条数据结构体 +type Line struct { + LineName string `json:"line_name"` // 线条名称 + Points *[]ChartPoint `json:"points"` // 图表点数据 +} + +// MetricName SQL性能洞察指标类型 +type MetricName string + +const ( + MetricNameComprehensiveTrend MetricName = "comprehensive_trend" // 数据源综合趋势 + MetricNameSlowSQLTrend MetricName = "slow_sql_trend" // 慢SQL趋势 + MetricNameTopSQLTrend MetricName = "top_sql_trend" // TopSQL趋势 + MetricNameActiveSessionTrend MetricName = "active_session_trend" // 活跃会话数趋势 +) + +type GetSqlPerformanceInsightsReq struct { + InstanceId string `query:"instance_id" json:"instance_id" valid:"required"` + StartTime string `query:"start_time" json:"start_time" valid:"required"` + EndTime string `query:"end_time" json:"end_time" valid:"required"` + MetricName MetricName `query:"metric_name" json:"metric_name" enums:"comprehensive_trend,slow_sql_trend,active_session_trend" valid:"required"` +} + +// GetSqlPerformanceInsights +// @Summary 获取SQL管控SQL性能洞察图表数据 +// @Description get sql manage sql performance insights +// @Id GetSqlPerformanceInsights +// @Tags SqlInsight +// @Param project_name path string true "project name" +// @Param metric_name query string true "metric name" Enums(comprehensive_trend,slow_sql_trend,top_sql_trend,active_session_trend) +// @Param start_time query string true "start time" +// @Param end_time query string true "end time" +// @Param instance_id query string true "instance id" +// @Security ApiKeyAuth +// @Success 200 {object} GetSqlPerformanceInsightsResp +// @Router /v1/projects/{project_name}/sql_performance_insights [get] +func GetSqlPerformanceInsights(c echo.Context) error { + return getSqlPerformanceInsights(c) +} + +type GetSqlPerformanceInsightsRelatedSQLResp struct { + controller.BaseRes + Data []*RelatedSQLInfo `json:"data"` + TotalNums uint32 `json:"total_nums"` +} + +type SqlSourceTypeEnum string + +const ( + SqlSourceTypeWorkflow SqlSourceTypeEnum = "workflow" + SqlSourceTypeSqlManage SqlSourceTypeEnum = "sql_manage" + SqlSourceTypeWorkBench SqlSourceTypeEnum = "workbench" +) + +type RelatedSQLInfo struct { + SqlFingerprint string `json:"sql_fingerprint"` + Source SqlSourceTypeEnum `json:"source" enums:"workflow,sql_manage"` + ExecuteTimeAvg float64 `json:"execute_time_avg"` // 平均执行时间(s) + ExecuteTimeMax float64 `json:"execute_time_max"` // 最大执行时间(s) + ExecuteTimeMin float64 `json:"execute_time_min"` // 最小执行时间(s) + ExecuteTimeSum float64 `json:"execute_time_sum"` // 总执行时间(s) + LockWaitTime float64 `json:"lock_wait_time"` // 锁等待时间(s) + ExecutionTimeTrend *SqlAnalysisScatterChart `json:"execution_time_trend,omitempty"` // SQL 趋势图表 +} + +// 散点图结构体,专用于SQL执行代价的散点图表示 +type SqlAnalysisScatterChart struct { + Points *[]ScatterPoint `json:"points"` + XInfo *string `json:"x_info"` + YInfo *string `json:"y_info"` + Message string `json:"message"` +} + +type ScatterPoint struct { + Time *string `json:"time"` // 时间点 + ExecuteTime *float64 `json:"execute_time"` // 执行时间 + SQL *string `json:"sql"` // SQL语句 + Id uint64 `json:"id"` // SQL ID + IsInTransaction bool `json:"is_in_transaction"` // 是否在事务中 + Infos []map[string]string `json:"info"` // 额外信息 +} + +type GetSqlPerformanceInsightsRelatedSQLReq struct { + ProjectName string `param:"project_name" json:"project_name" valid:"required"` + InstanceId string `query:"instance_id" json:"instance_id" valid:"required"` + StartTime string `query:"start_time" json:"start_time" valid:"required"` + EndTime string `query:"end_time" json:"end_time" valid:"required"` + FilterSource SqlSourceTypeEnum `query:"filter_source" json:"filter_source,omitempty" enums:"workflow,sql_manage,workbench" valid:"required"` + OrderBy *string `query:"order_by" json:"order_by,omitempty" enums:"execute_time_avg,execute_time_max,execute_time_min,execute_time_sum,lock_wait_time"` + IsAsc *bool `query:"is_asc" json:"is_asc,omitempty"` + PageIndex uint32 `query:"page_index" valid:"required" json:"page_index"` + PageSize uint32 `query:"page_size" valid:"required" json:"page_size"` +} + +// fixme: 这个接口的设计上由于产品对于SQL指纹浮动的图表的展示情况还有疑问。所以对应的设计应该是缺失了部分。 +// 1、由于后续还需要查询具体sql的管理事务等。所以可能需要设计一个 id 之类的字段以便后续查询。但是现在list里的内容是sql指纹,不是具体的sql,所以这个ID要放在哪还需要等产品的结论。 +// 2、同样的,对于关联事物功能。目前产品的设计里,关联事物打开的是具体的SQL,而不是SQL指纹。但是又不是所有SQL都在事务里。 +// 2.1、所以问题一为,点击按钮的时候要打开的是哪一条具体的SQL。 +// 2.2、需要设计字段显示的告诉前端这条SQL是否在一个事务当中。以便前端展示 "关联事务" 按钮是否可用。 +// 3、这个table还有一个跳转到SQL分析的功能。但是现有的SQL分析也是针对单条SQL。而这个地方也是SQL指纹。 +// 3.1、而且看上去现有的SQL是基于生成了分析结果。然后这个结果有个类似于 sql_manage_id 的玩意来获取的。但是从这里跳过去就没这个id了。需要前后端讨论一下具体实现。 +// GetSqlPerformanceInsightsRelatedSQL +// @Summary 获取sql洞察 时间选区 的关联SQL +// @Description Get related SQL for the selected time range in SQL performance insights +// @Id GetSqlPerformanceInsightsRelatedSQL +// @Tags SqlInsight +// @Param project_name path string true "project name" +// @Param instance_id query string true "instance id" +// @Param start_time query string true "start time" +// @Param end_time query string true "end time" +// @Param filter_source query string true "filter by SQL source" Enums(workflow,sql_manage,workbench) +// @Param order_by query string false "order by field" +// @Param is_asc query bool false "is ascending order" +// @Param page_index query uint32 true "page index" +// @Param page_size query uint32 true "size of per page" +// @Security ApiKeyAuth +// @Success 200 {object} GetSqlPerformanceInsightsRelatedSQLResp +// @Router /v1/projects/{project_name}/sql_performance_insights/related_sql [get] +func GetSqlPerformanceInsightsRelatedSQL(c echo.Context) error { + return getSqlPerformanceInsightsRelatedSQL(c) +} + +type LockType string + +const ( + LockTypeShared LockType = "SHARED" // 共享锁 + LockTypeExclusive LockType = "EXCLUSIVE" // 排他锁 + LockTypeIntentionShared LockType = "INTENTION_SHARED" // 意向共享锁 + LockTypeIntentionExclusive LockType = "INTENTION_EXCLUSIVE" // 意向排他锁 + LockTypeSharedIntentionExclusive LockType = "SHARED_INTENTION_EXCLUSIVE" // 共享意向排他锁 + LockTypeRowLock LockType = "ROW_LOCK" // 行锁 + LockTypeTableLock LockType = "TABLE_LOCK" // 表锁 + LockTypeMetadataLock LockType = "METADATA_LOCK" // 元数据锁 +) + +type TransactionState string + +const ( + TransactionStateRunning TransactionState = "RUNNING" // 执行中 + TransactionStateCompleted TransactionState = "COMPLETED" // 已完成 +) + +type TransactionInfo struct { + TransactionId string `json:"transaction_id"` // 事务ID + LockType LockType `json:"lock_type" enums:"SHARED,EXCLUSIVE,INTENTION_SHARED,INTENTION_EXCLUSIVE,SHARED_INTENTION_EXCLUSIVE,ROW_LOCK,TABLE_LOCK,METADATA_LOCK"` // 锁类型 + TransactionStartTime string `json:"transaction_start_time"` // 事务开始时间 + TransactionEndTime string `json:"transaction_end_time"` // 事务结束时间 + TransactionDuration float64 `json:"transaction_duration"` // 事务持续时间 + TransactionState TransactionState `json:"transaction_state" enums:"RUNNING,COMPLETED"` // 事务状态 +} + +type TransactionTimelineItem struct { + StartTime string `json:"start_time"` // 开始时间 + Description string `json:"description"` // 描述信息 +} + +type TransactionTimeline struct { + Timeline []*TransactionTimelineItem `json:"timeline"` // 时间线项目列表 + CurrentStepIndex int `json:"current_step_index"` // 当前步骤索引 +} + +// fixme: 这里同样有SQL分析功能。所以有跟上面3.1相同的问题。 + +type TransactionSQL struct { + SQL string `json:"sql"` // SQL语句 + ExecuteDuration float64 `json:"execute_duration"` // 执行时长 + LockType LockType `json:"lock_type" enums:"SHARED,EXCLUSIVE,INTENTION_SHARED,INTENTION_EXCLUSIVE,SHARED_INTENTION_EXCLUSIVE,ROW_LOCK,TABLE_LOCK,METADATA_LOCK"` // 锁类型 +} + +type TransactionLockInfo struct { + LockType LockType `json:"lock_type" enums:"SHARED,EXCLUSIVE,INTENTION_SHARED,INTENTION_EXCLUSIVE,SHARED_INTENTION_EXCLUSIVE,ROW_LOCK,TABLE_LOCK,METADATA_LOCK"` // 锁类型 + TableName string `json:"table_name"` // 表名 + CreateLockSQL string `json:"create_lock_sql"` // 创建锁的SQL语句 +} + +type RelatedTransactionInfo struct { + TransactionInfo *TransactionInfo `json:"transaction_info"` // 事务信息 + TransactionTimeline *TransactionTimeline `json:"transaction_timeline"` // 事务时间线 + TransactionSQLList []*TransactionSQL `json:"related_sql_info"` // 相关SQL列表 + TransactionLockInfo []*TransactionLockInfo `json:"transaction_lock_info"` // 事务锁信息 +} + +type GetSqlPerformanceInsightsRelatedTransactionResp struct { + controller.BaseRes + Data *RelatedTransactionInfo `json:"data"` +} + +// GetSqlPerformanceInsightsRelatedTransaction +// @Summary 获取sql洞察 相关SQL中具体一条SQL 的关联事务 +// @Description Get related transaction for the selected SQL in SQL performance insights +// @Id GetSqlPerformanceInsightsRelatedTransaction +// @Tags SqlInsight +// @Param project_name path string true "project name" +// @Param instance_id query string true "instance id" +// @Param sql_id query string true "sql id" +// @Security ApiKeyAuth +// @Success 200 {object} GetSqlPerformanceInsightsRelatedTransactionResp +// @Router /v1/projects/{project_name}/sql_performance_insights/related_sql/related_transaction [get] +func GetSqlPerformanceInsightsRelatedTransaction(c echo.Context) error { + return getSqlPerformanceInsightsRelatedTransaction(c) +} diff --git a/sqle/api/controller/v1/sql_manage_insight_ce.go b/sqle/api/controller/v1/sql_manage_insight_ce.go new file mode 100644 index 000000000..458535b05 --- /dev/null +++ b/sqle/api/controller/v1/sql_manage_insight_ce.go @@ -0,0 +1,24 @@ +//go:build !enterprise +// +build !enterprise + +package v1 + +import ( + e "errors" + "github.com/actiontech/sqle/sqle/errors" + "github.com/labstack/echo/v4" +) + +var ErrCommunityEditionNotSupportSqlInsight = errors.New(errors.EnterpriseEditionFeatures, e.New("sql insight is enterprise version feature")) + +func getSqlPerformanceInsights(c echo.Context) error { + return ErrCommunityEditionNotSupportSqlInsight +} + +func getSqlPerformanceInsightsRelatedSQL(c echo.Context) error { + return ErrCommunityEditionNotSupportSqlInsight +} + +func getSqlPerformanceInsightsRelatedTransaction(c echo.Context) error { + return ErrCommunityEditionNotSupportSqlInsight +} diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 30af0cda3..9b687ee95 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -6219,6 +6219,209 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/sql_performance_insights": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get sql manage sql performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取SQL管控SQL性能洞察图表数据", + "operationId": "GetSqlPerformanceInsights", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "enum": [ + "comprehensive_trend", + "slow_sql_trend", + "top_sql_trend", + "active_session_trend" + ], + "type": "string", + "description": "metric name", + "name": "metric_name", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "start time", + "name": "start_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "end time", + "name": "end_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsResp" + } + } + } + } + }, + "/v1/projects/{project_name}/sql_performance_insights/related_sql": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get related SQL for the selected time range in SQL performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取sql洞察 时间选区 的关联SQL", + "operationId": "GetSqlPerformanceInsightsRelatedSQL", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "start time", + "name": "start_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "end time", + "name": "end_time", + "in": "query", + "required": true + }, + { + "enum": [ + "workflow", + "sql_manage", + "workbench" + ], + "type": "string", + "description": "filter by SQL source", + "name": "filter_source", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "order by field", + "name": "order_by", + "in": "query" + }, + { + "type": "boolean", + "description": "is ascending order", + "name": "is_asc", + "in": "query" + }, + { + "type": "integer", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "size of per page", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsRelatedSQLResp" + } + } + } + } + }, + "/v1/projects/{project_name}/sql_performance_insights/related_sql/related_transaction": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get related transaction for the selected SQL in SQL performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取sql洞察 相关SQL中具体一条SQL 的关联事务", + "operationId": "GetSqlPerformanceInsightsRelatedTransaction", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "sql id", + "name": "sql_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsRelatedTransactionResp" + } + } + } + } + }, "/v1/projects/{project_name}/sql_versions": { "get": { "security": [ @@ -13479,6 +13682,9 @@ var doc = `{ } } }, + "status": { + "type": "integer" + }, "x": { "type": "string" }, @@ -16396,6 +16602,62 @@ var doc = `{ } } }, + "v1.GetSqlPerformanceInsightsRelatedSQLResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.RelatedSQLInfo" + } + }, + "message": { + "type": "string", + "example": "ok" + }, + "total_nums": { + "type": "integer" + } + } + }, + "v1.GetSqlPerformanceInsightsRelatedTransactionResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.RelatedTransactionInfo" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, + "v1.GetSqlPerformanceInsightsResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.SqlPerformanceInsights" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetSqlVersionDetailResV1": { "type": "object", "properties": { @@ -17451,6 +17713,22 @@ var doc = `{ } } }, + "v1.Line": { + "type": "object", + "properties": { + "line_name": { + "description": "线条名称", + "type": "string" + }, + "points": { + "description": "图表点数据", + "type": "array", + "items": { + "$ref": "#/definitions/v1.ChartPoint" + } + } + } + }, "v1.ListTableBySchemaResV1": { "type": "object", "properties": { @@ -17994,6 +18272,75 @@ var doc = `{ } } }, + "v1.RelatedSQLInfo": { + "type": "object", + "properties": { + "execute_time_avg": { + "description": "平均执行时间(s)", + "type": "number" + }, + "execute_time_max": { + "description": "最大执行时间(s)", + "type": "number" + }, + "execute_time_min": { + "description": "最小执行时间(s)", + "type": "number" + }, + "execute_time_sum": { + "description": "总执行时间(s)", + "type": "number" + }, + "execution_time_trend": { + "description": "SQL 趋势图表", + "type": "object", + "$ref": "#/definitions/v1.SqlAnalysisScatterChart" + }, + "lock_wait_time": { + "description": "锁等待时间(s)", + "type": "number" + }, + "source": { + "type": "string", + "enum": [ + "workflow", + "sql_manage" + ] + }, + "sql_fingerprint": { + "type": "string" + } + } + }, + "v1.RelatedTransactionInfo": { + "type": "object", + "properties": { + "related_sql_info": { + "description": "相关SQL列表", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionSQL" + } + }, + "transaction_info": { + "description": "事务信息", + "type": "object", + "$ref": "#/definitions/v1.TransactionInfo" + }, + "transaction_lock_info": { + "description": "事务锁信息", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionLockInfo" + } + }, + "transaction_timeline": { + "description": "事务时间线", + "type": "object", + "$ref": "#/definitions/v1.TransactionTimeline" + } + } + }, "v1.ReleaseWorkflows": { "type": "object", "properties": { @@ -18660,6 +19007,41 @@ var doc = `{ } } }, + "v1.ScatterPoint": { + "type": "object", + "properties": { + "execute_time": { + "description": "执行时间", + "type": "number" + }, + "id": { + "description": "SQL ID", + "type": "integer" + }, + "info": { + "description": "额外信息", + "type": "array", + "items": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "is_in_transaction": { + "description": "是否在事务中", + "type": "boolean" + }, + "sql": { + "description": "SQL语句", + "type": "string" + }, + "time": { + "description": "时间点", + "type": "string" + } + } + }, "v1.ScheduleTaskDefaultOption": { "type": "object", "properties": { @@ -18787,6 +19169,26 @@ var doc = `{ } } }, + "v1.SqlAnalysisScatterChart": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "points": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.ScatterPoint" + } + }, + "x_info": { + "type": "string" + }, + "y_info": { + "type": "string" + } + } + }, "v1.SqlAverageExecutionTime": { "type": "object", "properties": { @@ -18991,6 +19393,38 @@ var doc = `{ } } }, + "v1.SqlPerformanceInsights": { + "type": "object", + "properties": { + "lines": { + "description": "图表线条数据", + "type": "array", + "items": { + "$ref": "#/definitions/v1.Line" + } + }, + "message": { + "description": "提示信息", + "type": "string" + }, + "task_enable": { + "description": "是否启用任务", + "type": "boolean" + }, + "task_support": { + "description": "是否支持任务", + "type": "boolean" + }, + "x_info": { + "description": "X轴信息", + "type": "string" + }, + "y_info": { + "description": "Y轴信息", + "type": "string" + } + } + }, "v1.SqlVersionDetailResV1": { "type": "object", "properties": { @@ -19514,6 +19948,132 @@ var doc = `{ } } }, + "v1.TransactionInfo": { + "type": "object", + "properties": { + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "transaction_duration": { + "description": "事务持续时间", + "type": "number" + }, + "transaction_end_time": { + "description": "事务结束时间", + "type": "string" + }, + "transaction_id": { + "description": "事务ID", + "type": "string" + }, + "transaction_start_time": { + "description": "事务开始时间", + "type": "string" + }, + "transaction_state": { + "description": "事务状态", + "type": "string", + "enum": [ + "RUNNING", + "COMPLETED" + ] + } + } + }, + "v1.TransactionLockInfo": { + "type": "object", + "properties": { + "create_lock_sql": { + "description": "创建锁的SQL语句", + "type": "string" + }, + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "table_name": { + "description": "表名", + "type": "string" + } + } + }, + "v1.TransactionSQL": { + "type": "object", + "properties": { + "execute_duration": { + "description": "执行时长", + "type": "number" + }, + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "sql": { + "description": "SQL语句", + "type": "string" + } + } + }, + "v1.TransactionTimeline": { + "type": "object", + "properties": { + "current_step_index": { + "description": "当前步骤索引", + "type": "integer" + }, + "timeline": { + "description": "时间线项目列表", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionTimelineItem" + } + } + } + }, + "v1.TransactionTimelineItem": { + "type": "object", + "properties": { + "description": { + "description": "描述信息", + "type": "string" + }, + "start_time": { + "description": "开始时间", + "type": "string" + } + } + }, "v1.TriggerAuditPlanResV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 76c83212c..680a1aa60 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -6203,6 +6203,209 @@ } } }, + "/v1/projects/{project_name}/sql_performance_insights": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get sql manage sql performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取SQL管控SQL性能洞察图表数据", + "operationId": "GetSqlPerformanceInsights", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "enum": [ + "comprehensive_trend", + "slow_sql_trend", + "top_sql_trend", + "active_session_trend" + ], + "type": "string", + "description": "metric name", + "name": "metric_name", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "start time", + "name": "start_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "end time", + "name": "end_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsResp" + } + } + } + } + }, + "/v1/projects/{project_name}/sql_performance_insights/related_sql": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get related SQL for the selected time range in SQL performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取sql洞察 时间选区 的关联SQL", + "operationId": "GetSqlPerformanceInsightsRelatedSQL", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "start time", + "name": "start_time", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "end time", + "name": "end_time", + "in": "query", + "required": true + }, + { + "enum": [ + "workflow", + "sql_manage", + "workbench" + ], + "type": "string", + "description": "filter by SQL source", + "name": "filter_source", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "order by field", + "name": "order_by", + "in": "query" + }, + { + "type": "boolean", + "description": "is ascending order", + "name": "is_asc", + "in": "query" + }, + { + "type": "integer", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "size of per page", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsRelatedSQLResp" + } + } + } + } + }, + "/v1/projects/{project_name}/sql_performance_insights/related_sql/related_transaction": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Get related transaction for the selected SQL in SQL performance insights", + "tags": [ + "SqlInsight" + ], + "summary": "获取sql洞察 相关SQL中具体一条SQL 的关联事务", + "operationId": "GetSqlPerformanceInsightsRelatedTransaction", + "parameters": [ + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "instance id", + "name": "instance_id", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "sql id", + "name": "sql_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetSqlPerformanceInsightsRelatedTransactionResp" + } + } + } + } + }, "/v1/projects/{project_name}/sql_versions": { "get": { "security": [ @@ -13463,6 +13666,9 @@ } } }, + "status": { + "type": "integer" + }, "x": { "type": "string" }, @@ -16380,6 +16586,62 @@ } } }, + "v1.GetSqlPerformanceInsightsRelatedSQLResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.RelatedSQLInfo" + } + }, + "message": { + "type": "string", + "example": "ok" + }, + "total_nums": { + "type": "integer" + } + } + }, + "v1.GetSqlPerformanceInsightsRelatedTransactionResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.RelatedTransactionInfo" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, + "v1.GetSqlPerformanceInsightsResp": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "object", + "$ref": "#/definitions/v1.SqlPerformanceInsights" + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetSqlVersionDetailResV1": { "type": "object", "properties": { @@ -17435,6 +17697,22 @@ } } }, + "v1.Line": { + "type": "object", + "properties": { + "line_name": { + "description": "线条名称", + "type": "string" + }, + "points": { + "description": "图表点数据", + "type": "array", + "items": { + "$ref": "#/definitions/v1.ChartPoint" + } + } + } + }, "v1.ListTableBySchemaResV1": { "type": "object", "properties": { @@ -17978,6 +18256,75 @@ } } }, + "v1.RelatedSQLInfo": { + "type": "object", + "properties": { + "execute_time_avg": { + "description": "平均执行时间(s)", + "type": "number" + }, + "execute_time_max": { + "description": "最大执行时间(s)", + "type": "number" + }, + "execute_time_min": { + "description": "最小执行时间(s)", + "type": "number" + }, + "execute_time_sum": { + "description": "总执行时间(s)", + "type": "number" + }, + "execution_time_trend": { + "description": "SQL 趋势图表", + "type": "object", + "$ref": "#/definitions/v1.SqlAnalysisScatterChart" + }, + "lock_wait_time": { + "description": "锁等待时间(s)", + "type": "number" + }, + "source": { + "type": "string", + "enum": [ + "workflow", + "sql_manage" + ] + }, + "sql_fingerprint": { + "type": "string" + } + } + }, + "v1.RelatedTransactionInfo": { + "type": "object", + "properties": { + "related_sql_info": { + "description": "相关SQL列表", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionSQL" + } + }, + "transaction_info": { + "description": "事务信息", + "type": "object", + "$ref": "#/definitions/v1.TransactionInfo" + }, + "transaction_lock_info": { + "description": "事务锁信息", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionLockInfo" + } + }, + "transaction_timeline": { + "description": "事务时间线", + "type": "object", + "$ref": "#/definitions/v1.TransactionTimeline" + } + } + }, "v1.ReleaseWorkflows": { "type": "object", "properties": { @@ -18644,6 +18991,41 @@ } } }, + "v1.ScatterPoint": { + "type": "object", + "properties": { + "execute_time": { + "description": "执行时间", + "type": "number" + }, + "id": { + "description": "SQL ID", + "type": "integer" + }, + "info": { + "description": "额外信息", + "type": "array", + "items": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "is_in_transaction": { + "description": "是否在事务中", + "type": "boolean" + }, + "sql": { + "description": "SQL语句", + "type": "string" + }, + "time": { + "description": "时间点", + "type": "string" + } + } + }, "v1.ScheduleTaskDefaultOption": { "type": "object", "properties": { @@ -18771,6 +19153,26 @@ } } }, + "v1.SqlAnalysisScatterChart": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "points": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.ScatterPoint" + } + }, + "x_info": { + "type": "string" + }, + "y_info": { + "type": "string" + } + } + }, "v1.SqlAverageExecutionTime": { "type": "object", "properties": { @@ -18975,6 +19377,38 @@ } } }, + "v1.SqlPerformanceInsights": { + "type": "object", + "properties": { + "lines": { + "description": "图表线条数据", + "type": "array", + "items": { + "$ref": "#/definitions/v1.Line" + } + }, + "message": { + "description": "提示信息", + "type": "string" + }, + "task_enable": { + "description": "是否启用任务", + "type": "boolean" + }, + "task_support": { + "description": "是否支持任务", + "type": "boolean" + }, + "x_info": { + "description": "X轴信息", + "type": "string" + }, + "y_info": { + "description": "Y轴信息", + "type": "string" + } + } + }, "v1.SqlVersionDetailResV1": { "type": "object", "properties": { @@ -19498,6 +19932,132 @@ } } }, + "v1.TransactionInfo": { + "type": "object", + "properties": { + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "transaction_duration": { + "description": "事务持续时间", + "type": "number" + }, + "transaction_end_time": { + "description": "事务结束时间", + "type": "string" + }, + "transaction_id": { + "description": "事务ID", + "type": "string" + }, + "transaction_start_time": { + "description": "事务开始时间", + "type": "string" + }, + "transaction_state": { + "description": "事务状态", + "type": "string", + "enum": [ + "RUNNING", + "COMPLETED" + ] + } + } + }, + "v1.TransactionLockInfo": { + "type": "object", + "properties": { + "create_lock_sql": { + "description": "创建锁的SQL语句", + "type": "string" + }, + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "table_name": { + "description": "表名", + "type": "string" + } + } + }, + "v1.TransactionSQL": { + "type": "object", + "properties": { + "execute_duration": { + "description": "执行时长", + "type": "number" + }, + "lock_type": { + "description": "锁类型", + "type": "string", + "enum": [ + "SHARED", + "EXCLUSIVE", + "INTENTION_SHARED", + "INTENTION_EXCLUSIVE", + "SHARED_INTENTION_EXCLUSIVE", + "ROW_LOCK", + "TABLE_LOCK", + "METADATA_LOCK" + ] + }, + "sql": { + "description": "SQL语句", + "type": "string" + } + } + }, + "v1.TransactionTimeline": { + "type": "object", + "properties": { + "current_step_index": { + "description": "当前步骤索引", + "type": "integer" + }, + "timeline": { + "description": "时间线项目列表", + "type": "array", + "items": { + "$ref": "#/definitions/v1.TransactionTimelineItem" + } + } + } + }, + "v1.TransactionTimelineItem": { + "type": "object", + "properties": { + "description": { + "description": "描述信息", + "type": "string" + }, + "start_time": { + "description": "开始时间", + "type": "string" + } + } + }, "v1.TriggerAuditPlanResV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 279f02582..e75fa86c4 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -739,6 +739,8 @@ definitions: type: string type: object type: array + status: + type: integer x: type: string "y": @@ -2742,6 +2744,45 @@ definitions: example: ok type: string type: object + v1.GetSqlPerformanceInsightsRelatedSQLResp: + properties: + code: + example: 0 + type: integer + data: + items: + $ref: '#/definitions/v1.RelatedSQLInfo' + type: array + message: + example: ok + type: string + total_nums: + type: integer + type: object + v1.GetSqlPerformanceInsightsRelatedTransactionResp: + properties: + code: + example: 0 + type: integer + data: + $ref: '#/definitions/v1.RelatedTransactionInfo' + type: object + message: + example: ok + type: string + type: object + v1.GetSqlPerformanceInsightsResp: + properties: + code: + example: 0 + type: integer + data: + $ref: '#/definitions/v1.SqlPerformanceInsights' + type: object + message: + example: ok + type: string + type: object v1.GetSqlVersionDetailResV1: properties: code: @@ -3470,6 +3511,17 @@ definitions: $ref: '#/definitions/v1.LicenseUsageItem' type: object type: object + v1.Line: + properties: + line_name: + description: 线条名称 + type: string + points: + description: 图表点数据 + items: + $ref: '#/definitions/v1.ChartPoint' + type: array + type: object v1.ListTableBySchemaResV1: properties: code: @@ -3834,6 +3886,56 @@ definitions: reason: type: string type: object + v1.RelatedSQLInfo: + properties: + execute_time_avg: + description: 平均执行时间(s) + type: number + execute_time_max: + description: 最大执行时间(s) + type: number + execute_time_min: + description: 最小执行时间(s) + type: number + execute_time_sum: + description: 总执行时间(s) + type: number + execution_time_trend: + $ref: '#/definitions/v1.SqlAnalysisScatterChart' + description: SQL 趋势图表 + type: object + lock_wait_time: + description: 锁等待时间(s) + type: number + source: + enum: + - workflow + - sql_manage + type: string + sql_fingerprint: + type: string + type: object + v1.RelatedTransactionInfo: + properties: + related_sql_info: + description: 相关SQL列表 + items: + $ref: '#/definitions/v1.TransactionSQL' + type: array + transaction_info: + $ref: '#/definitions/v1.TransactionInfo' + description: 事务信息 + type: object + transaction_lock_info: + description: 事务锁信息 + items: + $ref: '#/definitions/v1.TransactionLockInfo' + type: array + transaction_timeline: + $ref: '#/definitions/v1.TransactionTimeline' + description: 事务时间线 + type: object + type: object v1.ReleaseWorkflows: properties: target_release_instances: @@ -4287,6 +4389,31 @@ definitions: example: ok type: string type: object + v1.ScatterPoint: + properties: + execute_time: + description: 执行时间 + type: number + id: + description: SQL ID + type: integer + info: + description: 额外信息 + items: + additionalProperties: + type: string + type: object + type: array + is_in_transaction: + description: 是否在事务中 + type: boolean + sql: + description: SQL语句 + type: string + time: + description: 时间点 + type: string + type: object v1.ScheduleTaskDefaultOption: properties: default_selector: @@ -4373,6 +4500,19 @@ definitions: $ref: '#/definitions/v1.TableMeta' type: array type: object + v1.SqlAnalysisScatterChart: + properties: + message: + type: string + points: + items: + $ref: '#/definitions/v1.ScatterPoint' + type: array + x_info: + type: string + y_info: + type: string + type: object v1.SqlAverageExecutionTime: properties: average_execution_seconds: @@ -4512,6 +4652,29 @@ definitions: - SUB_TASK type: string type: object + v1.SqlPerformanceInsights: + properties: + lines: + description: 图表线条数据 + items: + $ref: '#/definitions/v1.Line' + type: array + message: + description: 提示信息 + type: string + task_enable: + description: 是否启用任务 + type: boolean + task_support: + description: 是否支持任务 + type: boolean + x_info: + description: X轴信息 + type: string + y_info: + description: Y轴信息 + type: string + type: object v1.SqlVersionDetailResV1: properties: desc: @@ -4861,6 +5024,101 @@ definitions: minute: type: integer type: object + v1.TransactionInfo: + properties: + lock_type: + description: 锁类型 + enum: + - SHARED + - EXCLUSIVE + - INTENTION_SHARED + - INTENTION_EXCLUSIVE + - SHARED_INTENTION_EXCLUSIVE + - ROW_LOCK + - TABLE_LOCK + - METADATA_LOCK + type: string + transaction_duration: + description: 事务持续时间 + type: number + transaction_end_time: + description: 事务结束时间 + type: string + transaction_id: + description: 事务ID + type: string + transaction_start_time: + description: 事务开始时间 + type: string + transaction_state: + description: 事务状态 + enum: + - RUNNING + - COMPLETED + type: string + type: object + v1.TransactionLockInfo: + properties: + create_lock_sql: + description: 创建锁的SQL语句 + type: string + lock_type: + description: 锁类型 + enum: + - SHARED + - EXCLUSIVE + - INTENTION_SHARED + - INTENTION_EXCLUSIVE + - SHARED_INTENTION_EXCLUSIVE + - ROW_LOCK + - TABLE_LOCK + - METADATA_LOCK + type: string + table_name: + description: 表名 + type: string + type: object + v1.TransactionSQL: + properties: + execute_duration: + description: 执行时长 + type: number + lock_type: + description: 锁类型 + enum: + - SHARED + - EXCLUSIVE + - INTENTION_SHARED + - INTENTION_EXCLUSIVE + - SHARED_INTENTION_EXCLUSIVE + - ROW_LOCK + - TABLE_LOCK + - METADATA_LOCK + type: string + sql: + description: SQL语句 + type: string + type: object + v1.TransactionTimeline: + properties: + current_step_index: + description: 当前步骤索引 + type: integer + timeline: + description: 时间线项目列表 + items: + $ref: '#/definitions/v1.TransactionTimelineItem' + type: array + type: object + v1.TransactionTimelineItem: + properties: + description: + description: 描述信息 + type: string + start_time: + description: 开始时间 + type: string + type: object v1.TriggerAuditPlanResV1: properties: code: @@ -10924,6 +11182,145 @@ paths: summary: 获取SQL优化语句详情 tags: - sql_optimization + /v1/projects/{project_name}/sql_performance_insights: + get: + description: get sql manage sql performance insights + operationId: GetSqlPerformanceInsights + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: metric name + enum: + - comprehensive_trend + - slow_sql_trend + - top_sql_trend + - active_session_trend + in: query + name: metric_name + required: true + type: string + - description: start time + in: query + name: start_time + required: true + type: string + - description: end time + in: query + name: end_time + required: true + type: string + - description: instance id + in: query + name: instance_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetSqlPerformanceInsightsResp' + security: + - ApiKeyAuth: [] + summary: 获取SQL管控SQL性能洞察图表数据 + tags: + - SqlInsight + /v1/projects/{project_name}/sql_performance_insights/related_sql: + get: + description: Get related SQL for the selected time range in SQL performance + insights + operationId: GetSqlPerformanceInsightsRelatedSQL + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: instance id + in: query + name: instance_id + required: true + type: string + - description: start time + in: query + name: start_time + required: true + type: string + - description: end time + in: query + name: end_time + required: true + type: string + - description: filter by SQL source + enum: + - workflow + - sql_manage + - workbench + in: query + name: filter_source + required: true + type: string + - description: order by field + in: query + name: order_by + type: string + - description: is ascending order + in: query + name: is_asc + type: boolean + - description: page index + in: query + name: page_index + required: true + type: integer + - description: size of per page + in: query + name: page_size + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetSqlPerformanceInsightsRelatedSQLResp' + security: + - ApiKeyAuth: [] + summary: 获取sql洞察 时间选区 的关联SQL + tags: + - SqlInsight + /v1/projects/{project_name}/sql_performance_insights/related_sql/related_transaction: + get: + description: Get related transaction for the selected SQL in SQL performance + insights + operationId: GetSqlPerformanceInsightsRelatedTransaction + parameters: + - description: project name + in: path + name: project_name + required: true + type: string + - description: instance id + in: query + name: instance_id + required: true + type: string + - description: sql id + in: query + name: sql_id + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetSqlPerformanceInsightsRelatedTransactionResp' + security: + - ApiKeyAuth: [] + summary: 获取sql洞察 相关SQL中具体一条SQL 的关联事务 + tags: + - SqlInsight /v1/projects/{project_name}/sql_versions: get: consumes: