Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export slow queries #792

Merged
merged 16 commits into from
Nov 24, 2020
16 changes: 8 additions & 8 deletions pkg/apiserver/slowquery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ type SlowQuery struct {
}

type GetListRequest struct {
LogStartTS int64 `json:"logStartTS" form:"logStartTS"`
LogEndTS int64 `json:"logEndTS" form:"logEndTS"`
DB []string `json:"db" form:"db"`
Limit int `json:"limit" form:"limit"`
Text string `json:"text" form:"text"`
OrderBy string `json:"orderBy" form:"orderBy"`
DESC bool `json:"desc" form:"desc"`
BeginTime int `json:"begin_time" form:"begin_time"`
unbyte marked this conversation as resolved.
Show resolved Hide resolved
EndTime int `json:"end_time" form:"end_time"`
DB []string `json:"db" form:"db"`
Limit int `json:"limit" form:"limit"`
unbyte marked this conversation as resolved.
Show resolved Hide resolved
Text string `json:"text" form:"text"`
OrderBy string `json:"orderBy" form:"orderBy"`
DESC bool `json:"desc" form:"desc"`
unbyte marked this conversation as resolved.
Show resolved Hide resolved

// for showing slow queries in the statement detail page
Plans []string `json:"plans" form:"plans"`
Expand Down Expand Up @@ -183,7 +183,7 @@ func QuerySlowLogList(db *gorm.DB, req *GetListRequest) ([]SlowQuery, error) {
tx := db.
Table(SlowQueryTable).
Select(strings.Join(projections, ", ")).
Where("Time between from_unixtime(?) and from_unixtime(?)", req.LogStartTS, req.LogEndTS).
Where("Time between from_unixtime(?) and from_unixtime(?)", req.BeginTime, req.EndTime).
Limit(req.Limit)

if req.Text != "" {
Expand Down
5 changes: 3 additions & 2 deletions pkg/apiserver/slowquery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func (s *Service) downloadTokenHandler(c *gin.Context) {

// generate temp file that persist encrypted data
timeLayout := "0102150405"
currentTime := time.Now().Format(timeLayout)
beginTime := time.Unix(int64(req.BeginTime), 0).Format(timeLayout)
endTime := time.Unix(int64(req.EndTime), 0).Format(timeLayout)
token, err := utils.ExportCSV(csvData,
fmt.Sprintf("slowquery_%s_*.csv", currentTime),
fmt.Sprintf("slowquery_%s_%s_*.csv", beginTime, endTime),
"slowquery/download")

if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions ui/lib/apps/SlowQuery/utils/useSlowQueryTableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export default function useSlowQueryTableController(
const res = await client
.getInstance()
.slowQueryListGet(
queryTimeRange.beginTime,
queryOptions.schemas,
orderOptions.desc,
queryOptions.digest,
queryTimeRange.endTime,
selectedFields,
queryOptions.limit,
queryTimeRange.endTime,
queryTimeRange.beginTime,
orderOptions.orderBy,
queryOptions.plans,
queryOptions.searchText,
Expand Down Expand Up @@ -179,12 +179,11 @@ export default function useSlowQueryTableController(
db: queryOptions.schemas,
digest: queryOptions.digest,
text: queryOptions.searchText,
limit: queryOptions.limit,
unbyte marked this conversation as resolved.
Show resolved Hide resolved
plans: queryOptions.plans,
orderBy: orderOptions.orderBy,
desc: orderOptions.desc,
logEndTS: queryTimeRange.endTime,
logStartTS: queryTimeRange.beginTime,
end_time: queryTimeRange.endTime,
begin_time: queryTimeRange.beginTime,
})
const token = res.data
if (token) {
Expand Down