diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 30d551e4b8..b12d3bbd9e 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -1870,14 +1870,18 @@ func (r *ClickHouseReader) GetTopOperations(ctx context.Context, queryParams *mo if errStatus != nil { return nil, errStatus } - query += " GROUP BY name ORDER BY p99 DESC LIMIT 10" + query += " GROUP BY name ORDER BY p99 DESC" + if queryParams.Limit > 0 { + query += " LIMIT @limit" + args = append(args, clickhouse.Named("limit", queryParams.Limit)) + } err := r.db.Select(ctx, &topOperationsItems, query, args...) zap.S().Debug(query) if err != nil { zap.S().Error("Error in processing sql query: ", err) - return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("Error in processing sql query")} + return nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf("error in processing sql query")} } if topOperationsItems == nil { diff --git a/pkg/query-service/model/queryParams.go b/pkg/query-service/model/queryParams.go index a94f57ad02..429471616f 100644 --- a/pkg/query-service/model/queryParams.go +++ b/pkg/query-service/model/queryParams.go @@ -160,6 +160,7 @@ type GetTopOperationsParams struct { Start *time.Time End *time.Time Tags []TagQueryParam `json:"tags"` + Limit int `json:"limit"` } type GetUsageParams struct {