mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Various tiny code cleanups
Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
0cc6645c2d
commit
cdc4bf0ebc
|
@ -6,21 +6,15 @@ import classes from "./App.module.css";
|
||||||
import PrometheusLogo from "./images/prometheus-logo.svg";
|
import PrometheusLogo from "./images/prometheus-logo.svg";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ActionIcon,
|
|
||||||
Affix,
|
Affix,
|
||||||
Anchor,
|
|
||||||
AppShell,
|
AppShell,
|
||||||
Box,
|
Box,
|
||||||
Burger,
|
Burger,
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
|
||||||
Fieldset,
|
|
||||||
Group,
|
Group,
|
||||||
MantineProvider,
|
MantineProvider,
|
||||||
Menu,
|
Menu,
|
||||||
Popover,
|
|
||||||
Skeleton,
|
Skeleton,
|
||||||
Stack,
|
|
||||||
Text,
|
Text,
|
||||||
Transition,
|
Transition,
|
||||||
createTheme,
|
createTheme,
|
||||||
|
@ -28,7 +22,6 @@ import {
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useDisclosure, useWindowScroll } from "@mantine/hooks";
|
import { useDisclosure, useWindowScroll } from "@mantine/hooks";
|
||||||
import {
|
import {
|
||||||
IconAdjustments,
|
|
||||||
IconArrowUp,
|
IconArrowUp,
|
||||||
IconBellFilled,
|
IconBellFilled,
|
||||||
IconChevronDown,
|
IconChevronDown,
|
||||||
|
@ -41,7 +34,6 @@ import {
|
||||||
IconHeartRateMonitor,
|
IconHeartRateMonitor,
|
||||||
IconInfoCircle,
|
IconInfoCircle,
|
||||||
IconServerCog,
|
IconServerCog,
|
||||||
IconSettings,
|
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import {
|
import {
|
||||||
BrowserRouter,
|
BrowserRouter,
|
||||||
|
@ -53,7 +45,6 @@ import {
|
||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
import { IconTable } from "@tabler/icons-react";
|
import { IconTable } from "@tabler/icons-react";
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
// import { ReactQueryDevtools } from "react-query/devtools";
|
|
||||||
import QueryPage from "./pages/query/QueryPage";
|
import QueryPage from "./pages/query/QueryPage";
|
||||||
import AlertsPage from "./pages/AlertsPage";
|
import AlertsPage from "./pages/AlertsPage";
|
||||||
import RulesPage from "./pages/RulesPage";
|
import RulesPage from "./pages/RulesPage";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Anchor, Badge, Group } from "@mantine/core";
|
import { Anchor, Badge, Group } from "@mantine/core";
|
||||||
import React, { FC } from "react";
|
import { FC } from "react";
|
||||||
|
|
||||||
export interface EndpointLinkProps {
|
export interface EndpointLinkProps {
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { IconClockPause, IconClockPlay } from "@tabler/icons-react";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { formatPrometheusDuration } from "./lib/formatTime";
|
import { formatPrometheusDuration } from "./lib/formatTime";
|
||||||
import codeboxClasses from "./codebox.module.css";
|
import codeboxClasses from "./codebox.module.css";
|
||||||
import badgeClasses from "./Badge.module.css";
|
|
||||||
import { Rule } from "./api/responseTypes/rules";
|
import { Rule } from "./api/responseTypes/rules";
|
||||||
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
|
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
|
||||||
import { syntaxHighlighting } from "@codemirror/language";
|
import { syntaxHighlighting } from "@codemirror/language";
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
import { FC, useState } from "react";
|
import { FC } from "react";
|
||||||
import {
|
import {
|
||||||
Badge,
|
|
||||||
CheckIcon,
|
CheckIcon,
|
||||||
CloseButton,
|
|
||||||
Combobox,
|
Combobox,
|
||||||
ComboboxChevron,
|
ComboboxChevron,
|
||||||
ComboboxClearButton,
|
ComboboxClearButton,
|
||||||
Group,
|
Group,
|
||||||
Input,
|
|
||||||
MantineColor,
|
|
||||||
Pill,
|
Pill,
|
||||||
PillGroup,
|
|
||||||
PillsInput,
|
PillsInput,
|
||||||
useCombobox,
|
useCombobox,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { IconActivity, IconFilter } from "@tabler/icons-react";
|
import { IconActivity } from "@tabler/icons-react";
|
||||||
|
|
||||||
interface StatePillProps extends React.ComponentPropsWithoutRef<"div"> {
|
interface StatePillProps extends React.ComponentPropsWithoutRef<"div"> {
|
||||||
value: string;
|
value: string;
|
||||||
|
|
|
@ -7,12 +7,6 @@ import {
|
||||||
Badge,
|
Badge,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Box,
|
Box,
|
||||||
Divider,
|
|
||||||
Button,
|
|
||||||
Fieldset,
|
|
||||||
Checkbox,
|
|
||||||
MultiSelect,
|
|
||||||
Pill,
|
|
||||||
Stack,
|
Stack,
|
||||||
Input,
|
Input,
|
||||||
Alert,
|
Alert,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import {
|
||||||
Card,
|
Card,
|
||||||
Group,
|
Group,
|
||||||
Stack,
|
Stack,
|
||||||
Table,
|
|
||||||
Text,
|
Text,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
|
|
|
@ -12,7 +12,8 @@ const statusConfig: Record<
|
||||||
> = {
|
> = {
|
||||||
startTime: {
|
startTime: {
|
||||||
title: "Start time",
|
title: "Start time",
|
||||||
formatValue: (v: string) => formatTimestamp(new Date(v).valueOf() / 1000),
|
formatValue: (v: string) =>
|
||||||
|
formatTimestamp(new Date(v).valueOf() / 1000, false), // TODO: Set useLocalTime parameter correctly.
|
||||||
},
|
},
|
||||||
CWD: { title: "Working directory" },
|
CWD: { title: "Working directory" },
|
||||||
reloadConfigSuccess: {
|
reloadConfigSuccess: {
|
||||||
|
|
|
@ -2,9 +2,7 @@ import {
|
||||||
Accordion,
|
Accordion,
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
Alert,
|
Alert,
|
||||||
Anchor,
|
|
||||||
Badge,
|
Badge,
|
||||||
Card,
|
|
||||||
Group,
|
Group,
|
||||||
Input,
|
Input,
|
||||||
RingProgress,
|
RingProgress,
|
||||||
|
@ -27,7 +25,6 @@ import { Target, TargetsResult } from "../api/responseTypes/targets";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import badgeClasses from "../Badge.module.css";
|
import badgeClasses from "../Badge.module.css";
|
||||||
import {
|
import {
|
||||||
formatPrometheusDuration,
|
|
||||||
humanizeDurationRelative,
|
humanizeDurationRelative,
|
||||||
humanizeDuration,
|
humanizeDuration,
|
||||||
now,
|
now,
|
||||||
|
|
|
@ -38,8 +38,6 @@ const Graph: FC<GraphProps> = ({
|
||||||
endTime,
|
endTime,
|
||||||
range,
|
range,
|
||||||
resolution,
|
resolution,
|
||||||
showExemplars,
|
|
||||||
displayMode,
|
|
||||||
retriggerIdx,
|
retriggerIdx,
|
||||||
}) => {
|
}) => {
|
||||||
const realEndTime = (endTime !== null ? endTime : Date.now()) / 1000;
|
const realEndTime = (endTime !== null ? endTime : Date.now()) / 1000;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import { Alert, Box, Button, Notification, Stack, rem } from "@mantine/core";
|
import { Alert, Box, Button, Stack, rem } from "@mantine/core";
|
||||||
import {
|
import {
|
||||||
IconAlertCircle,
|
IconAlertCircle,
|
||||||
IconAlertTriangle,
|
IconAlertTriangle,
|
||||||
IconPlus,
|
IconPlus,
|
||||||
IconX,
|
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { useAppDispatch, useAppSelector } from "../../state/hooks";
|
import { useAppDispatch, useAppSelector } from "../../state/hooks";
|
||||||
import { addPanel } from "../../state/queryPageSlice";
|
import { addPanel } from "../../state/queryPageSlice";
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
|
||||||
import { ErrorAPIResponse, SuccessAPIResponse } from "../api/api";
|
|
||||||
import { InstantQueryResult } from "../api/responseTypes/query";
|
|
||||||
|
|
||||||
// Define a service using a base URL and expected endpoints
|
|
||||||
export const prometheusApi = createApi({
|
|
||||||
reducerPath: "prometheusApi",
|
|
||||||
baseQuery: fetchBaseQuery({ baseUrl: "/api/v1/" }),
|
|
||||||
keepUnusedDataFor: 0, // Turn off caching.
|
|
||||||
endpoints: (builder) => ({
|
|
||||||
instantQuery: builder.query<
|
|
||||||
SuccessAPIResponse<InstantQueryResult>,
|
|
||||||
{ query: string; time: number }
|
|
||||||
>({
|
|
||||||
query: ({ query, time }) => {
|
|
||||||
return {
|
|
||||||
url: `query`,
|
|
||||||
params: {
|
|
||||||
query,
|
|
||||||
time,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
//`query?query=${encodeURIComponent(query)}&time=${time}`,
|
|
||||||
},
|
|
||||||
transformErrorResponse: (error): string => {
|
|
||||||
if (!error.data) {
|
|
||||||
return "Failed to fetch data";
|
|
||||||
}
|
|
||||||
|
|
||||||
return (error.data as ErrorAPIResponse).error;
|
|
||||||
},
|
|
||||||
// transformResponse: (
|
|
||||||
// response: APIResponse<InstantQueryResult>
|
|
||||||
// ): SuccessAPIResponse<InstantQueryResult> => {
|
|
||||||
// if (!response.status) {
|
|
||||||
// throw new Error("Invalid response");
|
|
||||||
// }
|
|
||||||
// if (response.status === "error") {
|
|
||||||
// throw new Error(response.error);
|
|
||||||
// }
|
|
||||||
// return response;
|
|
||||||
// },
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Export hooks for usage in functional components, which are
|
|
||||||
// auto-generated based on the defined endpoints
|
|
||||||
export const { useInstantQueryQuery, useLazyInstantQueryQuery } = prometheusApi;
|
|
|
@ -40,7 +40,6 @@ const newDefaultPanel = (): Panel => ({
|
||||||
visualizer: {
|
visualizer: {
|
||||||
activeTab: "table",
|
activeTab: "table",
|
||||||
endTime: null,
|
endTime: null,
|
||||||
// endTime: 1709414194000,
|
|
||||||
range: 3600 * 1000,
|
range: 3600 * 1000,
|
||||||
resolution: null,
|
resolution: null,
|
||||||
displayMode: GraphDisplayMode.Lines,
|
displayMode: GraphDisplayMode.Lines,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { configureStore } from "@reduxjs/toolkit";
|
import { configureStore } from "@reduxjs/toolkit";
|
||||||
import queryPageSlice from "./queryPageSlice";
|
import queryPageSlice from "./queryPageSlice";
|
||||||
import { prometheusApi } from "./api";
|
|
||||||
import settingsSlice from "./settingsSlice";
|
import settingsSlice from "./settingsSlice";
|
||||||
import targetsPageSlice from "./targetsPageSlice";
|
import targetsPageSlice from "./targetsPageSlice";
|
||||||
import alertsPageSlice from "./alertsPageSlice";
|
import alertsPageSlice from "./alertsPageSlice";
|
||||||
|
@ -12,12 +11,9 @@ const store = configureStore({
|
||||||
queryPage: queryPageSlice,
|
queryPage: queryPageSlice,
|
||||||
targetsPage: targetsPageSlice,
|
targetsPage: targetsPageSlice,
|
||||||
alertsPage: alertsPageSlice,
|
alertsPage: alertsPageSlice,
|
||||||
[prometheusApi.reducerPath]: prometheusApi.reducer,
|
|
||||||
},
|
},
|
||||||
middleware: (getDefaultMiddleware) =>
|
middleware: (getDefaultMiddleware) =>
|
||||||
getDefaultMiddleware()
|
getDefaultMiddleware().prepend(localStorageMiddleware.middleware),
|
||||||
.prepend(localStorageMiddleware.middleware)
|
|
||||||
.concat(prometheusApi.middleware),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Infer the `RootState` and `AppDispatch` types from the store itself
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||||
|
|
Loading…
Reference in a new issue