2022-01-31 14:57:14 +08:00
|
|
|
import React from 'react';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2023-11-07 00:15:52 +08:00
|
|
|
import { Stack } from '@grafana/ui';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2022-06-02 19:50:58 +08:00
|
|
|
import promqlGrammar from '../../promql';
|
2022-01-31 14:57:14 +08:00
|
|
|
import { promQueryModeller } from '../PromQueryModeller';
|
2022-02-10 23:55:44 +08:00
|
|
|
import { buildVisualQueryFromString } from '../parsing';
|
2022-04-22 21:33:13 +08:00
|
|
|
import { OperationExplainedBox } from '../shared/OperationExplainedBox';
|
|
|
|
import { OperationListExplained } from '../shared/OperationListExplained';
|
2022-06-02 19:50:58 +08:00
|
|
|
import { RawQuery } from '../shared/RawQuery';
|
2022-04-22 21:33:13 +08:00
|
|
|
import { PromVisualQuery } from '../types';
|
2022-01-31 14:57:14 +08:00
|
|
|
|
2022-08-03 21:48:16 +08:00
|
|
|
export const EXPLAIN_LABEL_FILTER_CONTENT = 'Fetch all series matching metric name and label filters.';
|
|
|
|
|
2022-01-31 14:57:14 +08:00
|
|
|
export interface Props {
|
2022-02-10 23:55:44 +08:00
|
|
|
query: string;
|
2022-01-31 14:57:14 +08:00
|
|
|
}
|
|
|
|
|
2022-06-02 19:50:58 +08:00
|
|
|
export const PromQueryBuilderExplained = React.memo<Props>(({ query }) => {
|
2022-02-10 23:55:44 +08:00
|
|
|
const visQuery = buildVisualQueryFromString(query || '').query;
|
2022-06-02 19:50:58 +08:00
|
|
|
const lang = { grammar: promqlGrammar, name: 'promql' };
|
2022-02-10 23:55:44 +08:00
|
|
|
|
2022-01-31 14:57:14 +08:00
|
|
|
return (
|
2022-06-02 19:50:58 +08:00
|
|
|
<Stack gap={0.5} direction="column">
|
2022-02-10 23:55:44 +08:00
|
|
|
<OperationExplainedBox
|
|
|
|
stepNumber={1}
|
2022-06-02 19:50:58 +08:00
|
|
|
title={<RawQuery query={`${visQuery.metric} ${promQueryModeller.renderLabels(visQuery.labels)}`} lang={lang} />}
|
2022-02-10 23:55:44 +08:00
|
|
|
>
|
2022-08-03 21:48:16 +08:00
|
|
|
{EXPLAIN_LABEL_FILTER_CONTENT}
|
2022-01-31 14:57:14 +08:00
|
|
|
</OperationExplainedBox>
|
2022-06-02 19:50:58 +08:00
|
|
|
<OperationListExplained<PromVisualQuery>
|
|
|
|
stepNumber={2}
|
|
|
|
queryModeller={promQueryModeller}
|
|
|
|
query={visQuery}
|
|
|
|
lang={lang}
|
|
|
|
/>
|
2022-01-31 14:57:14 +08:00
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
PromQueryBuilderExplained.displayName = 'PromQueryBuilderExplained';
|