Skip to content

Commit abf3f0c

Browse files
authored
Merge pull request #3021 from actiontech/2321-commits
feat(api): get instance overview statistics
2 parents 240fec7 + 831c075 commit abf3f0c

File tree

7 files changed

+222
-1
lines changed

7 files changed

+222
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ etc
1313
bin/
1414
ui/
1515
static/
16-
.vscode/
16+
.vscode/
17+
jdk/

sqle/api/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
152152
v1Router.POST("/configurations/git/test", v1.TestGitConnectionV1, sqleMiddleware.OpGlobalAllowed())
153153

154154
// statistic
155+
v1Router.GET("/statistic/instances/resource_overview_statistics", v1.GetInstanceOverviewStatistics)
155156
v1Router.GET("/statistic/instances/type_percent", v1.GetInstancesTypePercentV1, sqleMiddleware.ViewGlobalAllowed())
156157
v1Router.GET("/statistic/instances/sql_average_execution_time", v1.GetSqlAverageExecutionTimeV1, sqleMiddleware.ViewGlobalAllowed())
157158
v1Router.GET("/statistic/license/usage", v1.GetLicenseUsageV1, sqleMiddleware.ViewGlobalAllowed())

sqle/api/controller/v1/statistic.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,3 +1019,32 @@ func GetInstanceHealthV1(c echo.Context) error {
10191019
Data: dBTypeHealth,
10201020
})
10211021
}
1022+
1023+
type GetInstanceOverviewStatisticsReq struct {
1024+
FilterByDBServiceIds []string `query:"filter_by_db_service_ids" params:"filter_by_db_service_ids" json:"filter_by_db_service_ids"`
1025+
}
1026+
1027+
type GetInstanceOverviewStatisticsRes struct {
1028+
controller.BaseRes
1029+
Data []InstanceOverviewStatistics `json:"data"`
1030+
}
1031+
1032+
type InstanceOverviewStatistics struct {
1033+
InstanceID string `json:"instance_id"`
1034+
AvgScore float32 `json:"avg_score"`
1035+
HighPrioritySQLCount int32 `json:"high_priority_sql_count"`
1036+
PendingWorkflowCount int32 `json:"pending_workflow_count"`
1037+
}
1038+
1039+
// GetInstanceOverviewStatistics
1040+
// @Summary 获取实例概览统计信息
1041+
// @Description get instance overview statistics including average score, high priority SQL count and pending workflow count
1042+
// @Tags statistic
1043+
// @Id getInstanceOverviewStatisticsV1
1044+
// @Security ApiKeyAuth
1045+
// @Param filter_by_db_service_ids query []string false "filter by db service ids"
1046+
// @Success 200 {object} v1.GetInstanceOverviewStatisticsRes
1047+
// @router /v1/statistic/instances/resource_overview_statistics [get]
1048+
func GetInstanceOverviewStatistics(c echo.Context) error {
1049+
return getInstanceOverviewStatistics(c)
1050+
}

sqle/api/controller/v1/statistic_ce.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ func getSqlAverageExecutionTimeV1(c echo.Context) error {
5656
func getSqlExecutionFailPercentV1(c echo.Context) error {
5757
return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportStatistic)
5858
}
59+
60+
func getInstanceOverviewStatistics(c echo.Context) error {
61+
return controller.JSONBaseErrorReq(c, errCommunityEditionDoesNotSupportStatistic)
62+
}

sqle/docs/docs.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9144,6 +9144,40 @@ var doc = `{
91449144
}
91459145
}
91469146
},
9147+
"/v1/statistic/instances/resource_overview_statistics": {
9148+
"get": {
9149+
"security": [
9150+
{
9151+
"ApiKeyAuth": []
9152+
}
9153+
],
9154+
"description": "get instance overview statistics including average score, high priority SQL count and pending workflow count",
9155+
"tags": [
9156+
"statistic"
9157+
],
9158+
"summary": "获取实例概览统计信息",
9159+
"operationId": "getInstanceOverviewStatisticsV1",
9160+
"parameters": [
9161+
{
9162+
"type": "array",
9163+
"items": {
9164+
"type": "string"
9165+
},
9166+
"description": "filter by db service ids",
9167+
"name": "filter_by_db_service_ids",
9168+
"in": "query"
9169+
}
9170+
],
9171+
"responses": {
9172+
"200": {
9173+
"description": "OK",
9174+
"schema": {
9175+
"$ref": "#/definitions/v1.GetInstanceOverviewStatisticsRes"
9176+
}
9177+
}
9178+
}
9179+
}
9180+
},
91479181
"/v1/statistic/instances/sql_average_execution_time": {
91489182
"get": {
91499183
"security": [
@@ -15250,6 +15284,25 @@ var doc = `{
1525015284
}
1525115285
}
1525215286
},
15287+
"v1.GetInstanceOverviewStatisticsRes": {
15288+
"type": "object",
15289+
"properties": {
15290+
"code": {
15291+
"type": "integer",
15292+
"example": 0
15293+
},
15294+
"data": {
15295+
"type": "array",
15296+
"items": {
15297+
"$ref": "#/definitions/v1.InstanceOverviewStatistics"
15298+
}
15299+
},
15300+
"message": {
15301+
"type": "string",
15302+
"example": "ok"
15303+
}
15304+
}
15305+
},
1525315306
"v1.GetInstanceSchemaResV1": {
1525415307
"type": "object",
1525515308
"properties": {
@@ -16991,6 +17044,23 @@ var doc = `{
1699117044
}
1699217045
}
1699317046
},
17047+
"v1.InstanceOverviewStatistics": {
17048+
"type": "object",
17049+
"properties": {
17050+
"avg_score": {
17051+
"type": "number"
17052+
},
17053+
"high_priority_sql_count": {
17054+
"type": "integer"
17055+
},
17056+
"instance_id": {
17057+
"type": "string"
17058+
},
17059+
"pending_workflow_count": {
17060+
"type": "integer"
17061+
}
17062+
}
17063+
},
1699417064
"v1.InstanceSchemaResV1": {
1699517065
"type": "object",
1699617066
"properties": {

sqle/docs/swagger.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9128,6 +9128,40 @@
91289128
}
91299129
}
91309130
},
9131+
"/v1/statistic/instances/resource_overview_statistics": {
9132+
"get": {
9133+
"security": [
9134+
{
9135+
"ApiKeyAuth": []
9136+
}
9137+
],
9138+
"description": "get instance overview statistics including average score, high priority SQL count and pending workflow count",
9139+
"tags": [
9140+
"statistic"
9141+
],
9142+
"summary": "获取实例概览统计信息",
9143+
"operationId": "getInstanceOverviewStatisticsV1",
9144+
"parameters": [
9145+
{
9146+
"type": "array",
9147+
"items": {
9148+
"type": "string"
9149+
},
9150+
"description": "filter by db service ids",
9151+
"name": "filter_by_db_service_ids",
9152+
"in": "query"
9153+
}
9154+
],
9155+
"responses": {
9156+
"200": {
9157+
"description": "OK",
9158+
"schema": {
9159+
"$ref": "#/definitions/v1.GetInstanceOverviewStatisticsRes"
9160+
}
9161+
}
9162+
}
9163+
}
9164+
},
91319165
"/v1/statistic/instances/sql_average_execution_time": {
91329166
"get": {
91339167
"security": [
@@ -15234,6 +15268,25 @@
1523415268
}
1523515269
}
1523615270
},
15271+
"v1.GetInstanceOverviewStatisticsRes": {
15272+
"type": "object",
15273+
"properties": {
15274+
"code": {
15275+
"type": "integer",
15276+
"example": 0
15277+
},
15278+
"data": {
15279+
"type": "array",
15280+
"items": {
15281+
"$ref": "#/definitions/v1.InstanceOverviewStatistics"
15282+
}
15283+
},
15284+
"message": {
15285+
"type": "string",
15286+
"example": "ok"
15287+
}
15288+
}
15289+
},
1523715290
"v1.GetInstanceSchemaResV1": {
1523815291
"type": "object",
1523915292
"properties": {
@@ -16975,6 +17028,23 @@
1697517028
}
1697617029
}
1697717030
},
17031+
"v1.InstanceOverviewStatistics": {
17032+
"type": "object",
17033+
"properties": {
17034+
"avg_score": {
17035+
"type": "number"
17036+
},
17037+
"high_priority_sql_count": {
17038+
"type": "integer"
17039+
},
17040+
"instance_id": {
17041+
"type": "string"
17042+
},
17043+
"pending_workflow_count": {
17044+
"type": "integer"
17045+
}
17046+
}
17047+
},
1697817048
"v1.InstanceSchemaResV1": {
1697917049
"type": "object",
1698017050
"properties": {

sqle/docs/swagger.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,19 @@ definitions:
20682068
example: ok
20692069
type: string
20702070
type: object
2071+
v1.GetInstanceOverviewStatisticsRes:
2072+
properties:
2073+
code:
2074+
example: 0
2075+
type: integer
2076+
data:
2077+
items:
2078+
$ref: '#/definitions/v1.InstanceOverviewStatistics'
2079+
type: array
2080+
message:
2081+
example: ok
2082+
type: string
2083+
type: object
20712084
v1.GetInstanceSchemaResV1:
20722085
properties:
20732086
code:
@@ -3273,6 +3286,17 @@ definitions:
32733286
instance_name:
32743287
type: string
32753288
type: object
3289+
v1.InstanceOverviewStatistics:
3290+
properties:
3291+
avg_score:
3292+
type: number
3293+
high_priority_sql_count:
3294+
type: integer
3295+
instance_id:
3296+
type: string
3297+
pending_workflow_count:
3298+
type: integer
3299+
type: object
32763300
v1.InstanceSchemaResV1:
32773301
properties:
32783302
schema_name_list:
@@ -12748,6 +12772,28 @@ paths:
1274812772
summary: 直接审核SQL
1274912773
tags:
1275012774
- sql_audit
12775+
/v1/statistic/instances/resource_overview_statistics:
12776+
get:
12777+
description: get instance overview statistics including average score, high
12778+
priority SQL count and pending workflow count
12779+
operationId: getInstanceOverviewStatisticsV1
12780+
parameters:
12781+
- description: filter by db service ids
12782+
in: query
12783+
items:
12784+
type: string
12785+
name: filter_by_db_service_ids
12786+
type: array
12787+
responses:
12788+
"200":
12789+
description: OK
12790+
schema:
12791+
$ref: '#/definitions/v1.GetInstanceOverviewStatisticsRes'
12792+
security:
12793+
- ApiKeyAuth: []
12794+
summary: 获取实例概览统计信息
12795+
tags:
12796+
- statistic
1275112797
/v1/statistic/instances/sql_average_execution_time:
1275212798
get:
1275312799
description: get average execution time of sql

0 commit comments

Comments
 (0)