Skip to content

Commit

Permalink
fix(slow-query): fix cannot show RU in slow query detail page (#1695)
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
nolouch and ti-chi-bot[bot] authored Jun 25, 2024
1 parent c30f979 commit 223739f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
14 changes: 11 additions & 3 deletions pkg/apiserver/slowquery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ func QuerySlowLogList(req *GetListRequest, sysSchema *utils.SysSchema, db *gorm.
return results, nil
}

func QuerySlowLogDetail(req *GetDetailRequest, db *gorm.DB) (*Model, error) {
func QuerySlowLogDetail(req *GetDetailRequest, sysSchema *utils.SysSchema, db *gorm.DB) (*Model, error) {
var result Model
err := db.
Select("*, (UNIX_TIMESTAMP(Time) + 0E0) AS timestamp").
slowQueryColumns, err := sysSchema.GetTableColumnNames(db, SlowQueryTable)
if err != nil {
return nil, err
}
selectStmt, err := genSelectStmt(slowQueryColumns, []string{"*"})
if err != nil {
return nil, err
}
err = db.
Select(selectStmt).
Where("Digest = ?", req.Digest).
Where("Time = FROM_UNIXTIME(?)", req.Timestamp).
Where("Conn_id = ?", req.ConnectID).
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/slowquery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (s *Service) getDetails(c *gin.Context) {
}

db := utils.GetTiDBConnection(c)
result, err := QuerySlowLogDetail(&req, db.Table(SlowQueryTable))
result, err := QuerySlowLogDetail(&req, s.params.SysSchema, db.Table(SlowQueryTable))
if err != nil {
rest.Error(c, err)
return
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slowquery/mock_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *testMockDBSuite) mustQuerySlowLogList(req *slowquery.GetListRequest) []
}

func (s *testMockDBSuite) mustQuerySlowLogDetail(req *slowquery.GetDetailRequest) (*slowquery.Model, error) {
d, err := slowquery.QuerySlowLogDetail(req, s.mockDBSession())
d, err := slowquery.QuerySlowLogDetail(req, s.sysSchema, s.mockDBSession())
return d, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ slow_query:
ru_tooltip: request units
resource_group: Resource Group
resource_group_tooltip: The resource group that the query belongs to
time_queued_by_rc: Time Queued by RC
time_queued_by_rc_tooltip: The wait time spent in the resource queue
time_queued_by_rc: The total time queued by RC
time_queued_by_rc_tooltip: 'The total wait time spent in the resource queue (note: {{distro.tikv}} executes requests in parallel so that t this is not a wall time)'

common:
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ slow_query:
ru_tooltip: 资源单位(RU)
resource_group: 资源组
resource_group_tooltip: SQL 语句所属的资源组
time_queued_by_rc: RC 等待耗时
time_queued_by_rc_tooltip: SQL 语句在资源组队列中等待的时间
time_queued_by_rc: RC 等待累积耗时
time_queued_by_rc_tooltip: SQL 语句在资源组队列中等待的累积时间(注:{{distro.tikv}} 会并行等待任务,因此该时间不是自然流逝时间)

common:
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ statement:
sum_ru: Total RU
sum_ru_tooltip: The total number of request units (RU) consumed by the statement
avg_time_queued_by_rc: Mean RC Wait Time in Queue
avg_time_queued_by_rc_tooltip: The average time that the query waits in the resource control's queue
avg_time_queued_by_rc_tooltip: The average time that the query waits in the resource control's queue (not a wall time)
max_time_queued_by_rc: Max RC Wait Time in Queue
max_time_queued_by_rc_tooltip: The maximum time that the query waits in the resource control's queue
rc_wait_time: Wait Time in Resource Control
max_time_queued_by_rc_tooltip: The maximum time that the query waits in the resource control's queue (not a wall time)
rc_wait_time_tooltip: 'The total wait time spent in the resource queue (note: {{distro.tikv}} executes requests in parallel so that t this is not a wall time)'
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ statement:
sum_ru: 累积 RU
sum_ru_tooltip: 该 Statement 的 RU 累积值
avg_time_queued_by_rc: RC 平均等待耗时
avg_time_queued_by_rc_tooltip: SQL 语句在资源组控制队列中平均等待的时间 (Resource Control)
avg_time_queued_by_rc_tooltip: SQL 语句在资源组控制队列中平均等待的时间 (Resource Control)(注:{{distro.tikv}} 会并行处理任务,因此该时间不是自然流逝时间)
max_time_queued_by_rc: RC 最大等待耗时
max_time_queued_by_rc_tooltip: SQL 语句在资源组控制队列中最大等待的时间 (Resource Control)
rc_wait_time: RC 资源控制等待耗时
max_time_queued_by_rc_tooltip: SQL 语句在资源组控制队列中最大等待的时间 (Resource Control)(注:{{distro.tikv}} 会并行处理任务,因此该时间不是自然流逝时间)
rc_wait_time: RC 资源控制等待累积耗时
rc_wait_time_tooltip: SQL 语句在资源组队列中等待的累积时间(注:{{distro.tikv}} 会并行等待任务,因此该时间不是自然流逝时间)

0 comments on commit 223739f

Please sign in to comment.