Make query warning/info notice display configurable

Fixes https://github.com/prometheus/prometheus/issues/16888

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2025-07-21 13:03:46 +02:00
parent b09cf6be8d
commit 1354bb90be
5 changed files with 87 additions and 40 deletions

View File

@ -21,6 +21,8 @@ const SettingsMenu: FC = () => {
enableSyntaxHighlighting, enableSyntaxHighlighting,
enableLinter, enableLinter,
showAnnotations, showAnnotations,
showQueryWarnings,
showQueryInfoNotices,
ruleGroupsPerPage, ruleGroupsPerPage,
alertGroupsPerPage, alertGroupsPerPage,
} = useSettings(); } = useSettings();
@ -101,6 +103,28 @@ const SettingsMenu: FC = () => {
) )
} }
/> />
<Checkbox
checked={showQueryWarnings}
label="Show query warnings"
onChange={(event) =>
dispatch(
updateSettings({
showQueryWarnings: event.currentTarget.checked,
})
)
}
/>
<Checkbox
checked={showQueryInfoNotices}
label="Show query info notices"
onChange={(event) =>
dispatch(
updateSettings({
showQueryInfoNotices: event.currentTarget.checked,
})
)
}
/>
</Stack> </Stack>
</Fieldset> </Fieldset>
</Stack> </Stack>

View File

@ -15,6 +15,7 @@ import { useElementSize } from "@mantine/hooks";
import UPlotChart, { UPlotChartRange } from "./UPlotChart"; import UPlotChart, { UPlotChartRange } from "./UPlotChart";
import ASTNode, { nodeType } from "../../promql/ast"; import ASTNode, { nodeType } from "../../promql/ast";
import serializeNode from "../../promql/serialize"; import serializeNode from "../../promql/serialize";
import { useSettings } from "../../state/settingsSlice";
export interface GraphProps { export interface GraphProps {
expr: string; expr: string;
@ -41,6 +42,7 @@ const Graph: FC<GraphProps> = ({
}) => { }) => {
const { ref, width } = useElementSize(); const { ref, width } = useElementSize();
const [rerender, setRerender] = useState(true); const [rerender, setRerender] = useState(true);
const { showQueryWarnings, showQueryInfoNotices } = useSettings();
const effectiveExpr = const effectiveExpr =
node === null node === null
@ -88,26 +90,28 @@ const Graph: FC<GraphProps> = ({
const renderAlerts = (warnings?: string[], infos?: string[]) => { const renderAlerts = (warnings?: string[], infos?: string[]) => {
return ( return (
<> <>
{warnings?.map((w, idx) => ( {showQueryWarnings &&
<Alert warnings?.map((w, idx) => (
key={idx} <Alert
color="red" key={idx}
title="Query warning" color="red"
icon={<IconAlertTriangle />} title="Query warning"
> icon={<IconAlertTriangle />}
{w} >
</Alert> {w}
))} </Alert>
{infos?.map((w, idx) => ( ))}
<Alert {showQueryInfoNotices &&
key={idx} infos?.map((w, idx) => (
color="yellow" <Alert
title="Query notice" key={idx}
icon={<IconInfoCircle />} color="yellow"
> title="Query notice"
{w} icon={<IconInfoCircle />}
</Alert> >
))} {w}
</Alert>
))}
</> </>
); );
}; };

View File

@ -10,6 +10,7 @@ import { setVisualizer } from "../../state/queryPageSlice";
import TimeInput from "./TimeInput"; import TimeInput from "./TimeInput";
import DataTable from "./DataTable"; import DataTable from "./DataTable";
import QueryStatsDisplay from "./QueryStatsDisplay"; import QueryStatsDisplay from "./QueryStatsDisplay";
import { useSettings } from "../../state/settingsSlice";
dayjs.extend(timezone); dayjs.extend(timezone);
export interface TableTabProps { export interface TableTabProps {
@ -26,6 +27,7 @@ const TableTab: FC<TableTabProps> = ({ panelIdx, retriggerIdx, expr }) => {
(state) => state.queryPage.panels[panelIdx] (state) => state.queryPage.panels[panelIdx]
); );
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { showQueryWarnings, showQueryInfoNotices } = useSettings();
const { endTime, range } = visualizer; const { endTime, range } = visualizer;
@ -99,27 +101,29 @@ const TableTab: FC<TableTabProps> = ({ panelIdx, retriggerIdx, expr }) => {
</Alert> </Alert>
)} )}
{data.warnings?.map((w, idx) => ( {showQueryWarnings &&
<Alert data.warnings?.map((w, idx) => (
key={idx} <Alert
color="red" key={idx}
title="Query warning" color="red"
icon={<IconAlertTriangle />} title="Query warning"
> icon={<IconAlertTriangle />}
{w} >
</Alert> {w}
))} </Alert>
))}
{data.infos?.map((w, idx) => ( {showQueryInfoNotices &&
<Alert data.infos?.map((w, idx) => (
key={idx} <Alert
color="yellow" key={idx}
title="Query notice" color="yellow"
icon={<IconInfoCircle />} title="Query notice"
> icon={<IconInfoCircle />}
{w} >
</Alert> {w}
))} </Alert>
))}
<DataTable <DataTable
data={data.data} data={data.data}
limitResults={limitResults} limitResults={limitResults}

View File

@ -63,6 +63,8 @@ startAppListening({
case "enableSyntaxHighlighting": case "enableSyntaxHighlighting":
case "enableLinter": case "enableLinter":
case "showAnnotations": case "showAnnotations":
case "showQueryWarnings":
case "showQueryInfoNotices":
case "alertGroupsPerPage": case "alertGroupsPerPage":
case "ruleGroupsPerPage": case "ruleGroupsPerPage":
return persistToLocalStorage(`settings.${key}`, value); return persistToLocalStorage(`settings.${key}`, value);

View File

@ -14,6 +14,8 @@ interface Settings {
enableSyntaxHighlighting: boolean; enableSyntaxHighlighting: boolean;
enableLinter: boolean; enableLinter: boolean;
showAnnotations: boolean; showAnnotations: boolean;
showQueryWarnings: boolean;
showQueryInfoNotices: boolean;
ruleGroupsPerPage: number; ruleGroupsPerPage: number;
alertGroupsPerPage: number; alertGroupsPerPage: number;
} }
@ -31,6 +33,9 @@ export const localStorageKeyEnableSyntaxHighlighting =
"settings.enableSyntaxHighlighting"; "settings.enableSyntaxHighlighting";
export const localStorageKeyEnableLinter = "settings.enableLinter"; export const localStorageKeyEnableLinter = "settings.enableLinter";
export const localStorageKeyShowAnnotations = "settings.showAnnotations"; export const localStorageKeyShowAnnotations = "settings.showAnnotations";
export const localStorageKeyShowQueryWarnings = "settings.showQueryWarnings";
export const localStorageKeyShowQueryInfoNotices =
"settings.showQueryInfoNotices";
export const localStorageKeyRuleGroupsPerPage = "settings.ruleGroupsPerPage"; export const localStorageKeyRuleGroupsPerPage = "settings.ruleGroupsPerPage";
export const localStorageKeyAlertGroupsPerPage = "settings.alertGroupsPerPage"; export const localStorageKeyAlertGroupsPerPage = "settings.alertGroupsPerPage";
@ -99,6 +104,14 @@ export const initialState: Settings = {
localStorageKeyShowAnnotations, localStorageKeyShowAnnotations,
true true
), ),
showQueryWarnings: initializeFromLocalStorage<boolean>(
localStorageKeyShowQueryWarnings,
true
),
showQueryInfoNotices: initializeFromLocalStorage<boolean>(
localStorageKeyShowQueryInfoNotices,
true
),
ruleGroupsPerPage: initializeFromLocalStorage<number>( ruleGroupsPerPage: initializeFromLocalStorage<number>(
localStorageKeyRuleGroupsPerPage, localStorageKeyRuleGroupsPerPage,
10 10