import { FC } from "react"; import { Alert, Text, Anchor, Card, Divider } from "@mantine/core"; import ASTNode, { nodeType } from "../../../promql/ast"; // import AggregationExplainView from "./Aggregation"; // import BinaryExprExplainView from "./BinaryExpr/BinaryExpr"; // import SelectorExplainView from "./Selector"; import funcDocs from "../../../promql/functionDocs"; import { escapeString } from "../../../promql/utils"; import { formatPrometheusDuration } from "../../../lib/formatTime"; import classes from "./ExplainView.module.css"; import SelectorExplainView from "./Selector"; import AggregationExplainView from "./Aggregation"; import BinaryExprExplainView from "./BinaryExpr/BinaryExpr"; import { IconInfoCircle } from "@tabler/icons-react"; interface ExplainViewProps { node: ASTNode | null; treeShown: boolean; showTree: () => void; } const ExplainView: FC = ({ node, treeShown, showTree: setShowTree, }) => { if (node === null) { return ( }> This tab can help you understand the behavior of individual components of a query.

To use the Explain view,{" "} {!treeShown && ( <> enable the query tree view {" "} (also available via the expression input menu) and then )}{" "} select a node in the tree above.
); } switch (node.type) { case nodeType.aggregation: return ; case nodeType.binaryExpr: return ; case nodeType.call: return ( Function call This node calls the{" "} {node.func.name}() {" "} function{node.args.length > 0 ? " on the provided inputs" : ""}. {/* TODO: Some docs, like x_over_time, have relative links pointing back to the Prometheus docs, make sure to modify those links in the docs extraction so they work from the explain view */} {funcDocs[node.func.name]} ); case nodeType.matrixSelector: return ; case nodeType.subquery: return ( Subquery This node evaluates the passed expression as a subquery over the last{" "} {formatPrometheusDuration(node.range)} {" "} at a query resolution{" "} {node.step > 0 ? ( <> of{" "} {formatPrometheusDuration(node.step)} ) : ( "equal to the default rule evaluation interval" )} {node.timestamp !== null ? ( <> , evaluated relative to an absolute evaluation timestamp of{" "} {(node.timestamp / 1000).toFixed(3)} ) : node.startOrEnd !== null ? ( <> , evaluated relative to the {node.startOrEnd} of the query range ) : ( <> )} {node.offset === 0 ? ( <> ) : node.offset > 0 ? ( <> , time-shifted{" "} {formatPrometheusDuration(node.offset)} {" "} into the past ) : ( <> , time-shifted{" "} {formatPrometheusDuration(-node.offset)} {" "} into the future )} . ); case nodeType.numberLiteral: return ( Number literal A scalar number literal with the value{" "} {node.val}. ); case nodeType.parenExpr: return ( Parentheses Parentheses that contain a sub-expression to be evaluated. ); case nodeType.stringLiteral: return ( String literal A string literal with the value{" "} "{escapeString(node.val)}" . ); case nodeType.unaryExpr: return ( Unary expression A unary expression that{" "} {node.op === "+" ? "does not affect the expression it is applied to" : "changes the sign of the expression it is applied to"} . ); case nodeType.vectorSelector: return ; default: throw new Error("invalid node type"); } }; export default ExplainView;