mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Add option to define chunk duration per query (#64834)
* add query option to configure chunk ranges * remove `isValidDuration` check * Update public/app/plugins/datasource/loki/querybuilder/components/LokiQueryBuilderOptions.tsx Co-authored-by: Matias Chomicki <matyax@gmail.com> * change to `chunkDuration` added tests * no need to call `toString` --------- Co-authored-by: Matias Chomicki <matyax@gmail.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { usePrevious } from 'react-use';
|
||||
|
||||
import { CoreApp, SelectableValue } from '@grafana/data';
|
||||
import { CoreApp, isValidDuration, SelectableValue } from '@grafana/data';
|
||||
import { EditorField, EditorRow } from '@grafana/experimental';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
import { RadioButtonGroup, Select, AutoSizeInput } from '@grafana/ui';
|
||||
import { config, reportInteraction } from '@grafana/runtime';
|
||||
import { AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
|
||||
import { QueryOptionGroup } from 'app/plugins/datasource/prometheus/querybuilder/shared/QueryOptionGroup';
|
||||
|
||||
import { preprocessMaxLines, queryTypeOptions, RESOLUTION_OPTIONS } from '../../components/LokiOptionFields';
|
||||
@@ -24,6 +24,7 @@ export interface Props {
|
||||
export const LokiQueryBuilderOptions = React.memo<Props>(
|
||||
({ app, query, onChange, onRunQuery, maxLines, datasource }) => {
|
||||
const [queryStats, setQueryStats] = useState<QueryStats>();
|
||||
const [chunkRangeValid, setChunkRangeValid] = useState(true);
|
||||
const prevQuery = usePrevious(query);
|
||||
|
||||
const onQueryTypeChange = (value: LokiQueryType) => {
|
||||
@@ -40,6 +41,17 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
||||
onRunQuery();
|
||||
};
|
||||
|
||||
const onChunkRangeChange = (evt: React.FormEvent<HTMLInputElement>) => {
|
||||
const value = evt.currentTarget.value;
|
||||
if (!isValidDuration(value)) {
|
||||
setChunkRangeValid(false);
|
||||
return;
|
||||
}
|
||||
setChunkRangeValid(true);
|
||||
onChange({ ...query, chunkDuration: value });
|
||||
onRunQuery();
|
||||
};
|
||||
|
||||
const onLegendFormatChanged = (evt: React.FormEvent<HTMLInputElement>) => {
|
||||
onChange({ ...query, legendFormat: evt.currentTarget.value });
|
||||
onRunQuery();
|
||||
@@ -119,6 +131,21 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
||||
aria-label="Select resolution"
|
||||
/>
|
||||
</EditorField>
|
||||
{config.featureToggles.lokiQuerySplitting && (
|
||||
<EditorField
|
||||
label="Chunk Duration"
|
||||
tooltip="Defines the duration of a single query chunk when query chunking is used."
|
||||
>
|
||||
<AutoSizeInput
|
||||
minWidth={14}
|
||||
type="string"
|
||||
min={0}
|
||||
defaultValue={query.chunkDuration ?? '1d'}
|
||||
onCommitChange={onChunkRangeChange}
|
||||
invalid={!chunkRangeValid}
|
||||
/>
|
||||
</EditorField>
|
||||
)}
|
||||
</QueryOptionGroup>
|
||||
</EditorRow>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user