import { Alert, Box, Button, Stack, rem } from "@mantine/core"; import { IconAlertCircle, IconAlertTriangle, IconPlus, } from "@tabler/icons-react"; import { useAppDispatch, useAppSelector } from "../../state/hooks"; import { addPanel } from "../../state/queryPageSlice"; import Panel from "./QueryPanel"; import { LabelValuesResult } from "../../api/responseTypes/labelValues"; import { useAPIQuery } from "../../api/api"; import { useEffect, useState } from "react"; import { InstantQueryResult } from "../../api/responseTypes/query"; import { humanizeDuration } from "../../lib/formatTime"; export default function QueryPage() { const panels = useAppSelector((state) => state.queryPage.panels); const dispatch = useAppDispatch(); const [timeDelta, setTimeDelta] = useState(0); const { data: metricNamesResult, error: metricNamesError } = useAPIQuery({ path: "/label/__name__/values", }); const { data: timeResult, error: timeError } = useAPIQuery({ path: "/query", params: { query: "time()", }, }); useEffect(() => { if (timeResult) { if (timeResult.data.resultType !== "scalar") { throw new Error("Unexpected result type from time query"); } const browserTime = new Date().getTime() / 1000; const serverTime = timeResult.data.result[0]; setTimeDelta(Math.abs(browserTime - serverTime)); } }, [timeResult]); return ( {metricNamesError && ( } color="red" title="Error fetching metrics list" withCloseButton > Unable to fetch list of metric names: {metricNamesError.message} )} {timeError && ( } color="red" title="Error fetching server time" withCloseButton > {timeError.message} )} {timeDelta > 30 && ( } onClose={() => setTimeDelta(0)} > Detected a time difference of{" "} {humanizeDuration(timeDelta * 1000)} between your browser and the server. You may see unexpected time-shifted query results due to the time drift. )} {panels.map((p, idx) => ( ))} ); }