diff --git a/pkg/tsdb/influxdb/flux/executor.go b/pkg/tsdb/influxdb/flux/executor.go index 7154dcc5e6b..ccd3a465df2 100644 --- a/pkg/tsdb/influxdb/flux/executor.go +++ b/pkg/tsdb/influxdb/flux/executor.go @@ -29,8 +29,13 @@ func executeQuery(ctx context.Context, logger log.Logger, query queryModel, runn logger.Warn("Flux query failed", "err", err, "query", flux) dr.Error = err } else { - // we only enforce a larger number than maxDataPoints - maxPointsEnforced := int(float64(query.MaxDataPoints) * maxPointsEnforceFactor) + maxPointsEnforced := int(query.MaxDataPoints) + // The default value of MaxDataPoints is 100 when it is not set + // See https://github.com/grafana/grafana/blob/d69b19e431bfe31ff904a48826593e6fa79b7a5b/pkg/services/query/query.go#L322 + // So if the default value is being used we fall back to the old logic. + if query.MaxDataPoints == 100 { + maxPointsEnforced *= int(maxPointsEnforceFactor) + } dr = readDataFrames(logger, tables, maxPointsEnforced, maxSeries) diff --git a/pkg/tsdb/influxdb/flux/executor_test.go b/pkg/tsdb/influxdb/flux/executor_test.go index 4e72c5dde7c..935c03f69e8 100644 --- a/pkg/tsdb/influxdb/flux/executor_test.go +++ b/pkg/tsdb/influxdb/flux/executor_test.go @@ -250,8 +250,8 @@ func TestMaxDataPointsExceededNoAggregate(t *testing.T) { dr := executeMockedQuery(t, "max_data_points_exceeded", queryModel{MaxDataPoints: 2}) // it should contain the error-message - require.EqualError(t, dr.Error, "A query returned too many datapoints and the results have been truncated at 21 points to prevent memory issues. At the current graph size, Grafana can only draw 2. Try using the aggregateWindow() function in your query to reduce the number of points returned.") - assertDataResponseDimensions(t, dr, 2, 21) + require.EqualError(t, dr.Error, "A query returned too many datapoints and the results have been truncated at 3 points to prevent memory issues. At the current graph size, Grafana can only draw 2. Try using the aggregateWindow() function in your query to reduce the number of points returned.") + assertDataResponseDimensions(t, dr, 2, 3) } func TestMaxDataPointsExceededWithAggregate(t *testing.T) { @@ -261,8 +261,8 @@ func TestMaxDataPointsExceededWithAggregate(t *testing.T) { dr := executeMockedQuery(t, "max_data_points_exceeded", queryModel{RawQuery: "aggregateWindow()", MaxDataPoints: 2}) // it should contain the error-message - require.EqualError(t, dr.Error, "A query returned too many datapoints and the results have been truncated at 21 points to prevent memory issues. At the current graph size, Grafana can only draw 2.") - assertDataResponseDimensions(t, dr, 2, 21) + require.EqualError(t, dr.Error, "A query returned too many datapoints and the results have been truncated at 3 points to prevent memory issues. At the current graph size, Grafana can only draw 2.") + assertDataResponseDimensions(t, dr, 2, 3) } func TestMultivalue(t *testing.T) { diff --git a/public/app/plugins/datasource/influxdb/components/editor/variable/VariableQueryEditor.tsx b/public/app/plugins/datasource/influxdb/components/editor/variable/VariableQueryEditor.tsx index dd1bc42d73a..9de9f8f216f 100644 --- a/public/app/plugins/datasource/influxdb/components/editor/variable/VariableQueryEditor.tsx +++ b/public/app/plugins/datasource/influxdb/components/editor/variable/VariableQueryEditor.tsx @@ -1,72 +1,83 @@ import React from 'react'; import { QueryEditorProps } from '@grafana/data'; -import { Field, FieldSet, InlineFieldRow, TextArea } from '@grafana/ui'; +import { InlineFieldRow, Input, TextArea } from '@grafana/ui'; import { InlineField } from '@grafana/ui/'; import InfluxDatasource from '../../../datasource'; import { InfluxOptions, InfluxQuery, InfluxVariableQuery, InfluxVersion } from '../../../types'; import { FluxQueryEditor } from '../query/flux/FluxQueryEditor'; -export type Props = QueryEditorProps; +type Props = QueryEditorProps; const refId = 'InfluxVariableQueryEditor-VariableQuery'; -const useVariableQuery = (query: InfluxVariableQuery | string): InfluxVariableQuery => { - // in legacy variable support query can be only a string - // in new variable support query can be an object and hold more information - // to be able to support old version we check the query here - if (typeof query === 'string') { - return { - refId, - query, - }; - } else { - return { - refId, - query: query.query ?? '', - }; - } -}; - export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) => { - const varQuery = useVariableQuery(query); + const getFluxVariableQuery = (q: InfluxVariableQuery | string) => { + // in legacy variable support query can be only a string + // in new variable support query can be an object and hold more information + // to be able to support old version we check the query here + if (typeof q !== 'string') { + return q; + } - const onChangeHandler = (q: InfluxQuery) => { - onChange({ refId, query: q.query || '' }); - }; - - const onBlurHandler = (e: React.FocusEvent) => { - onChange({ refId, query: e.currentTarget.value }); + return { + refId, + query: q, + maxDataPoints: 1000, + }; }; switch (datasource.version) { case InfluxVersion.Flux: - return ; - case InfluxVersion.SQL: return ( -
- -