mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 01:12:09 +08:00
Postgres/MySQL/MSSQL: Add setting to limit maximum amount of rows processed (#38986)
Adds a new setting dataproxy.row_limit that allows an operator to limit the amount of rows being processed/accepted in response to database queries originating from SQL data sources. Closes #38975 Ref #39095 Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
5b7dc16c06
commit
1c892a2fc4
@ -92,6 +92,7 @@ type DataPluginConfiguration struct {
|
||||
ConnectionString string
|
||||
TimeColumnNames []string
|
||||
MetricColumnTypes []string
|
||||
RowLimit int64
|
||||
}
|
||||
type DataSourceHandler struct {
|
||||
macroEngine SQLMacroEngine
|
||||
@ -101,6 +102,7 @@ type DataSourceHandler struct {
|
||||
metricColumnTypes []string
|
||||
log log.Logger
|
||||
dsInfo DataSourceInfo
|
||||
rowLimit int64
|
||||
}
|
||||
type QueryJson struct {
|
||||
RawSql string `json:"rawSql"`
|
||||
@ -133,6 +135,7 @@ func NewQueryDataHandler(config DataPluginConfiguration, queryResultTransformer
|
||||
timeColumnNames: []string{"time"},
|
||||
log: log,
|
||||
dsInfo: config.DSInfo,
|
||||
rowLimit: config.RowLimit,
|
||||
}
|
||||
|
||||
if len(config.TimeColumnNames) > 0 {
|
||||
@ -168,8 +171,6 @@ func NewQueryDataHandler(config DataPluginConfiguration, queryResultTransformer
|
||||
return &queryDataHandler, nil
|
||||
}
|
||||
|
||||
const rowLimit = 1000000
|
||||
|
||||
type DBDataResponse struct {
|
||||
dataResponse backend.DataResponse
|
||||
refID string
|
||||
@ -284,15 +285,17 @@ func (e *DataSourceHandler) executeQuery(query backend.DataQuery, wg *sync.WaitG
|
||||
|
||||
// Convert row.Rows to dataframe
|
||||
stringConverters := e.queryResultTransformer.GetConverterList()
|
||||
frame, err := sqlutil.FrameFromRows(rows.Rows, rowLimit, sqlutil.ToConverters(stringConverters...)...)
|
||||
frame, err := sqlutil.FrameFromRows(rows.Rows, e.rowLimit, sqlutil.ToConverters(stringConverters...)...)
|
||||
if err != nil {
|
||||
errAppendDebug("convert frame from rows error", err, interpolatedQuery)
|
||||
return
|
||||
}
|
||||
|
||||
frame.SetMeta(&data.FrameMeta{
|
||||
ExecutedQueryString: interpolatedQuery,
|
||||
})
|
||||
if frame.Meta == nil {
|
||||
frame.Meta = &data.FrameMeta{}
|
||||
}
|
||||
|
||||
frame.Meta.ExecutedQueryString = interpolatedQuery
|
||||
|
||||
// If no rows were returned, no point checking anything else.
|
||||
if frame.Rows() == 0 {
|
||||
|
Reference in New Issue
Block a user