2024-04-03 05:48:59 -07:00
|
|
|
import { Badge, Box, Card, Group, useComputedColorScheme } from "@mantine/core";
|
2024-03-07 04:16:54 -08:00
|
|
|
import { IconClockPause, IconClockPlay } from "@tabler/icons-react";
|
2024-02-23 08:37:56 -08:00
|
|
|
import { FC } from "react";
|
2024-04-09 03:36:53 -07:00
|
|
|
import { formatPrometheusDuration } from "../lib/formatTime";
|
|
|
|
import codeboxClasses from "./RuleDefinition.module.css";
|
|
|
|
import { Rule } from "../api/responseTypes/rules";
|
2024-02-23 08:37:56 -08:00
|
|
|
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
|
|
|
|
import { syntaxHighlighting } from "@codemirror/language";
|
|
|
|
import {
|
|
|
|
baseTheme,
|
|
|
|
darkPromqlHighlighter,
|
|
|
|
lightTheme,
|
|
|
|
promqlHighlighter,
|
2024-04-09 03:36:53 -07:00
|
|
|
} from "../codemirror/theme";
|
2024-02-23 08:37:56 -08:00
|
|
|
import { PromQLExtension } from "@prometheus-io/codemirror-promql";
|
2024-04-03 05:48:59 -07:00
|
|
|
import { LabelBadges } from "./LabelBadges";
|
2024-02-23 08:37:56 -08:00
|
|
|
|
|
|
|
const promqlExtension = new PromQLExtension();
|
|
|
|
|
|
|
|
const RuleDefinition: FC<{ rule: Rule }> = ({ rule }) => {
|
|
|
|
const theme = useComputedColorScheme();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-03-14 04:19:41 -07:00
|
|
|
<Card p="xs" className={codeboxClasses.codebox} shadow="xs">
|
2024-02-23 08:37:56 -08:00
|
|
|
<CodeMirror
|
|
|
|
basicSetup={false}
|
|
|
|
value={rule.query}
|
|
|
|
editable={false}
|
|
|
|
extensions={[
|
|
|
|
baseTheme,
|
|
|
|
lightTheme,
|
|
|
|
syntaxHighlighting(
|
|
|
|
theme === "light" ? promqlHighlighter : darkPromqlHighlighter
|
|
|
|
),
|
|
|
|
promqlExtension.asExtension(),
|
|
|
|
EditorView.lineWrapping,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
{rule.type === "alerting" && (
|
|
|
|
<Group mt="md" gap="xs">
|
|
|
|
{rule.duration && (
|
|
|
|
<Badge
|
|
|
|
variant="light"
|
|
|
|
styles={{ label: { textTransform: "none" } }}
|
|
|
|
leftSection={<IconClockPause size={12} />}
|
|
|
|
>
|
2024-04-03 05:48:59 -07:00
|
|
|
for: {formatPrometheusDuration(rule.duration * 1000)}
|
2024-02-23 08:37:56 -08:00
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
{rule.keepFiringFor && (
|
|
|
|
<Badge
|
|
|
|
variant="light"
|
|
|
|
styles={{ label: { textTransform: "none" } }}
|
|
|
|
leftSection={<IconClockPlay size={12} />}
|
|
|
|
>
|
2024-04-03 05:48:59 -07:00
|
|
|
keep_firing_for: {formatPrometheusDuration(rule.duration * 1000)}
|
2024-02-23 08:37:56 -08:00
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
</Group>
|
|
|
|
)}
|
|
|
|
{rule.labels && Object.keys(rule.labels).length > 0 && (
|
2024-04-03 05:48:59 -07:00
|
|
|
<Box mt="md">
|
|
|
|
<LabelBadges labels={rule.labels} />
|
|
|
|
</Box>
|
2024-02-23 08:37:56 -08:00
|
|
|
)}
|
|
|
|
{/* {Object.keys(r.annotations).length > 0 && (
|
|
|
|
<Group mt="md" gap="xs">
|
|
|
|
{Object.entries(r.annotations).map(([k, v]) => (
|
|
|
|
<Badge
|
|
|
|
variant="light"
|
|
|
|
color="orange.9"
|
|
|
|
styles={{ label: { textTransform: "none" } }}
|
|
|
|
key={k}
|
|
|
|
>
|
|
|
|
{k}: {v}
|
|
|
|
</Badge>
|
|
|
|
))}
|
|
|
|
</Group>
|
|
|
|
)} */}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RuleDefinition;
|