mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Add option to issue forward queries (#91181)
* Loki: Add option to issue forward queries * Loki: Fix spelling of "backward"/"forward"
This commit is contained in:
parent
b2314dfb55
commit
14db32cc9f
@ -9,7 +9,7 @@ import { config } from '@grafana/runtime';
|
|||||||
import { InlineFormLabel, RadioButtonGroup, InlineField, Input, Select, Stack } from '@grafana/ui';
|
import { InlineFormLabel, RadioButtonGroup, InlineField, Input, Select, Stack } from '@grafana/ui';
|
||||||
|
|
||||||
import { getLokiQueryType } from '../queryUtils';
|
import { getLokiQueryType } from '../queryUtils';
|
||||||
import { LokiQuery, LokiQueryType } from '../types';
|
import { LokiQuery, LokiQueryDirection, LokiQueryType } from '../types';
|
||||||
|
|
||||||
export interface LokiOptionFieldsProps {
|
export interface LokiOptionFieldsProps {
|
||||||
lineLimitValue: string;
|
lineLimitValue: string;
|
||||||
@ -29,6 +29,15 @@ export const queryTypeOptions: Array<SelectableValue<LokiQueryType>> = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const queryDirections: Array<SelectableValue<LokiQueryDirection>> = [
|
||||||
|
{ value: LokiQueryDirection.Backward, label: 'Backward', description: 'Search in backward direction.' },
|
||||||
|
{
|
||||||
|
value: LokiQueryDirection.Forward,
|
||||||
|
label: 'Forward',
|
||||||
|
description: 'Search in forward direction.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
if (config.featureToggles.lokiExperimentalStreaming) {
|
if (config.featureToggles.lokiExperimentalStreaming) {
|
||||||
queryTypeOptions.push({
|
queryTypeOptions.push({
|
||||||
value: LokiQueryType.Stream,
|
value: LokiQueryType.Stream,
|
||||||
|
@ -7,9 +7,14 @@ import { EditorField, EditorRow, QueryOptionGroup } from '@grafana/experimental'
|
|||||||
import { config, reportInteraction } from '@grafana/runtime';
|
import { config, reportInteraction } from '@grafana/runtime';
|
||||||
import { Alert, AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
|
import { Alert, AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
|
||||||
|
|
||||||
import { preprocessMaxLines, queryTypeOptions, RESOLUTION_OPTIONS } from '../../components/LokiOptionFields';
|
import {
|
||||||
|
preprocessMaxLines,
|
||||||
|
queryDirections,
|
||||||
|
queryTypeOptions,
|
||||||
|
RESOLUTION_OPTIONS,
|
||||||
|
} from '../../components/LokiOptionFields';
|
||||||
import { getLokiQueryType, isLogsQuery } from '../../queryUtils';
|
import { getLokiQueryType, isLogsQuery } from '../../queryUtils';
|
||||||
import { LokiQuery, LokiQueryType, QueryStats } from '../../types';
|
import { LokiQuery, LokiQueryDirection, LokiQueryType, QueryStats } from '../../types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
query: LokiQuery;
|
query: LokiQuery;
|
||||||
@ -29,6 +34,11 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
|||||||
onRunQuery();
|
onRunQuery();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onQueryDirectionChange = (value: LokiQueryDirection) => {
|
||||||
|
onChange({ ...query, direction: value });
|
||||||
|
onRunQuery();
|
||||||
|
};
|
||||||
|
|
||||||
const onResolutionChange = (option: SelectableValue<number>) => {
|
const onResolutionChange = (option: SelectableValue<number>) => {
|
||||||
reportInteraction('grafana_loki_resolution_clicked', {
|
reportInteraction('grafana_loki_resolution_clicked', {
|
||||||
app,
|
app,
|
||||||
@ -73,6 +83,8 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
|||||||
? queryTypeOptions.filter((o) => o.value !== LokiQueryType.Instant)
|
? queryTypeOptions.filter((o) => o.value !== LokiQueryType.Instant)
|
||||||
: queryTypeOptions;
|
: queryTypeOptions;
|
||||||
|
|
||||||
|
const queryDirection = query.direction ?? LokiQueryDirection.Backward;
|
||||||
|
|
||||||
// if the state's queryType is still Instant, trigger a change to range for log queries
|
// if the state's queryType is still Instant, trigger a change to range for log queries
|
||||||
if (isLogQuery && queryType === LokiQueryType.Instant) {
|
if (isLogQuery && queryType === LokiQueryType.Instant) {
|
||||||
onChange({ ...query, queryType: LokiQueryType.Range });
|
onChange({ ...query, queryType: LokiQueryType.Range });
|
||||||
@ -111,16 +123,21 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
|||||||
</EditorField>
|
</EditorField>
|
||||||
)}
|
)}
|
||||||
{isLogQuery && (
|
{isLogQuery && (
|
||||||
<EditorField label="Line limit" tooltip="Upper limit for number of log lines returned by query.">
|
<>
|
||||||
<AutoSizeInput
|
<EditorField label="Line limit" tooltip="Upper limit for number of log lines returned by query.">
|
||||||
className="width-4"
|
<AutoSizeInput
|
||||||
placeholder={maxLines.toString()}
|
className="width-4"
|
||||||
type="number"
|
placeholder={maxLines.toString()}
|
||||||
min={0}
|
type="number"
|
||||||
defaultValue={query.maxLines?.toString() ?? ''}
|
min={0}
|
||||||
onCommitChange={onMaxLinesChange}
|
defaultValue={query.maxLines?.toString() ?? ''}
|
||||||
/>
|
onCommitChange={onMaxLinesChange}
|
||||||
</EditorField>
|
/>
|
||||||
|
</EditorField>
|
||||||
|
<EditorField label="Direction" tooltip="Direction to search for logs.">
|
||||||
|
<RadioButtonGroup options={queryDirections} value={queryDirection} onChange={onQueryDirectionChange} />
|
||||||
|
</EditorField>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{!isLogQuery && (
|
{!isLogQuery && (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user