2022-01-31 07:57:14 +01:00
|
|
|
import React from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2022-07-20 12:50:08 -04:00
|
|
|
import { Stack } from '@grafana/ui';
|
2022-01-31 07:57:14 +01:00
|
|
|
import { OperationExplainedBox } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationExplainedBox';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { OperationListExplained } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationListExplained';
|
2022-06-02 13:50:58 +02:00
|
|
|
import { RawQuery } from 'app/plugins/datasource/prometheus/querybuilder/shared/RawQuery';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2022-06-02 13:50:58 +02:00
|
|
|
import { lokiGrammar } from '../../syntax';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { lokiQueryModeller } from '../LokiQueryModeller';
|
2022-04-14 10:59:39 +02:00
|
|
|
import { buildVisualQueryFromString } from '../parsing';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { LokiVisualQuery } from '../types';
|
2022-01-31 07:57:14 +01:00
|
|
|
|
|
|
|
|
export interface Props {
|
2022-04-14 10:59:39 +02:00
|
|
|
query: string;
|
2022-01-31 07:57:14 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 13:50:58 +02:00
|
|
|
export const LokiQueryBuilderExplained = React.memo<Props>(({ query }) => {
|
2022-04-14 10:59:39 +02:00
|
|
|
const visQuery = buildVisualQueryFromString(query || '').query;
|
2022-06-02 13:50:58 +02:00
|
|
|
const lang = { grammar: lokiGrammar, name: 'lokiql' };
|
2022-04-14 10:59:39 +02:00
|
|
|
|
2022-01-31 07:57:14 +01:00
|
|
|
return (
|
|
|
|
|
<Stack gap={0} direction="column">
|
2022-06-02 13:50:58 +02:00
|
|
|
<OperationExplainedBox>
|
|
|
|
|
<RawQuery query={query} lang={lang} />
|
|
|
|
|
</OperationExplainedBox>
|
|
|
|
|
<OperationExplainedBox
|
|
|
|
|
stepNumber={1}
|
|
|
|
|
title={<RawQuery query={`${lokiQueryModeller.renderLabels(visQuery.labels)}`} lang={lang} />}
|
|
|
|
|
>
|
2022-01-31 07:57:14 +01:00
|
|
|
Fetch all log lines matching label filters.
|
|
|
|
|
</OperationExplainedBox>
|
2022-06-02 13:50:58 +02:00
|
|
|
<OperationListExplained<LokiVisualQuery>
|
|
|
|
|
stepNumber={2}
|
|
|
|
|
queryModeller={lokiQueryModeller}
|
|
|
|
|
query={visQuery}
|
|
|
|
|
lang={lang}
|
|
|
|
|
/>
|
2022-01-31 07:57:14 +01:00
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LokiQueryBuilderExplained.displayName = 'LokiQueryBuilderExplained';
|