Skip to content

Commit 2488ee4

Browse files
committed
console: add resource usage charts to the redesigned cluster page
Third in the cluster details redesign stack. The Metrics tab gets a resource usage card: CPU, memory and replica status share one time axis and one hover tooltip, with a toggle per replica. - CPU: a line per replica, as a share of the replica's CPU allocation. Readings past 100% extend the axis, with a dashed line marking the allocation. - Memory: a bar per replica as a share of the heap limit (RAM plus swap), on a fixed 0 to 100% axis so swap-heavy sizes don't stretch it. On 26.44 and later the bar splits into RAM and swap, and the legend gives the RAM and heap limits in bytes. Earlier environments show heap alone. Where no sample has a heap limit, the labels say the bars are a share of the memory allocation. - Replica status: a row per replica, including one offline the whole window. Running, finished hydration and offline stretches, a marker for each out-of-memory kill, and a badge with the count of objects still hydrating. A window with no usage still shows the status rows. - Dotted markers where an index or materialized view was created on the cluster. Wide windows merge neighboring buckets, keeping each metric's peak, so bars stay at least 10px wide. The time axis matches the classic graphs. The mark layers are memoized, so hovering only redraws the cursor and tooltip.
1 parent 6d357be commit 2488ee4

14 files changed

Lines changed: 2622 additions & 21 deletions

‎console/src/hooks/useChartLegend.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function useChartLegend({
3535

3636
const toggleLegendItem = (
3737
key: string,
38-
event: React.MouseEvent<HTMLDivElement>,
38+
event: Pick<React.MouseEvent, "metaKey" | "ctrlKey">,
3939
) => {
4040
const isModifierPressed = event.metaKey || event.ctrlKey;
4141

‎console/src/mz-doc-urls.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@
434434
"/docs/sql/subscribe/": "https://materialize.com/docs/sql/subscribe/",
435435
"/docs/sql/functions/substring/": "https://materialize.com/docs/sql/functions/substring/",
436436
"/docs/support/": "https://materialize.com/docs/support/",
437+
"/docs/clusters/troubleshoot-clusters/memory-spike/": "https://materialize.com/docs/clusters/troubleshoot-clusters/memory-spike/",
438+
"/docs/clusters/troubleshoot-clusters/hydration-failures/": "https://materialize.com/docs/clusters/troubleshoot-clusters/hydration-failures/",
437439
"/docs/sql/system-catalog/": "https://materialize.com/docs/sql/system-catalog/",
438440
"/docs/sql/system-clusters/": "https://materialize.com/docs/sql/system-clusters/",
439441
"/docs/sql/table/": "https://materialize.com/docs/sql/table/",

‎console/src/platform/clusters/ClusterDetail.test.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ vi.mock("~/platform/clusters/ClusterOverview", () => ({
3333
return <div>ClusterOverview component</div>;
3434
},
3535
}));
36+
vi.mock("~/platform/clusters/ClusterPage/ClusterMetrics", () => ({
37+
ClusterMetrics: () => <div>ClusterMetrics component</div>,
38+
}));
3639
vi.mock("~/platform/clusters/ClusterReplicas", () => ({
3740
default: () => <div>ClusterReplicas component</div>,
3841
}));
@@ -154,7 +157,7 @@ describe("ClusterDetail redesign preview", () => {
154157
expect(
155158
screen.queryByRole("link", { name: "Materialized Views" }),
156159
).not.toBeInTheDocument();
157-
expect(screen.getByText("ClusterOverview component")).toBeVisible();
160+
expect(screen.getByText("ClusterMetrics component")).toBeVisible();
158161
});
159162

160163
it("opens the Objects tab on its first object type", async () => {
@@ -189,9 +192,7 @@ describe("ClusterDetail redesign preview", () => {
189192
await user.click(await screen.findByRole("link", { name: "Metrics" }));
190193

191194
await expectPathname("/u1/default");
192-
expect(
193-
await screen.findByText("ClusterOverview component"),
194-
).toBeVisible();
195+
expect(await screen.findByText("ClusterMetrics component")).toBeVisible();
195196
});
196197

197198
it("redirects classic tab URLs into the Objects tab", async () => {

‎console/src/platform/clusters/ClusterOverview.tsx‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { useParams } from "react-router-dom";
2626

2727
import { MZ_PROBE_CLUSTER } from "~/api/materialize";
2828
import { Cluster } from "~/api/materialize/cluster/clusterList";
29+
import { hasNoUtilizationMetrics } from "~/api/materialize/cluster/replicaUtilizationBinning";
2930
import Alert from "~/components/Alert";
3031
import ErrorBox from "~/components/ErrorBox";
3132
import { EventEmitterProvider } from "~/components/EventEmitter";
@@ -50,6 +51,7 @@ import { ClusterParams } from "./ClusterRoutes";
5051
import {
5152
CLUSTER_METRICS_UNAVAILABLE_MESSAGE,
5253
CLUSTERS_FETCH_ERROR_MESSAGE,
54+
MIN_BUCKET_SIZE_MS,
5355
} from "./constants";
5456
import LargestMaintainedQueries from "./LargestMaintainedQueries";
5557
import { useReplicaUtilizationHistory } from "./queries";
@@ -59,9 +61,6 @@ export interface ReplicaData {
5961
data: DataPoint[];
6062
}
6163

62-
// because the data is sampled on 60s intervals, we don't want to show more granular data than this.
63-
const MIN_BUCKET_SIZE_MS = 60 * 1000;
64-
6564
const GRAPH_SPACING = 24;
6665

6766
const ClusterOverview = () => {
@@ -134,14 +133,7 @@ const ClusterOverview = () => {
134133
// If there are no metrics at all (rows are all zeros/nulls),
135134
// the cluster may be misconfigured (issue with metrics collection),
136135
// so we show an error message in that case.
137-
const clusterHasNoMetrics =
138-
(graphData ?? []).length &&
139-
graphData?.every((d) =>
140-
d.data.every(
141-
(point) =>
142-
!point.cpuPercent && !point.memoryPercent && !point.diskPercent,
143-
),
144-
);
136+
const clusterHasNoMetrics = hasNoUtilizationMetrics(graphData ?? []);
145137

146138
return (
147139
<MainContentContainer mt="10">
@@ -277,7 +269,7 @@ const ClusterOverview = () => {
277269
);
278270
};
279271

280-
const ClusterInfoBox = ({ cluster }: { cluster: Cluster }) => {
272+
export const ClusterInfoBox = ({ cluster }: { cluster: Cluster }) => {
281273
const appConfig = useAppConfig();
282274
let message = null;
283275

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright Materialize, Inc. and contributors. All rights reserved.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the LICENSE file.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0.
9+
10+
import { Box, VStack } from "@chakra-ui/react";
11+
import React from "react";
12+
import { useParams } from "react-router-dom";
13+
14+
import { LoadingContainer } from "~/components/LoadingContainer";
15+
import { useFlags } from "~/hooks/useFlags";
16+
import { MainContentContainer } from "~/layouts/BaseLayout";
17+
import { ClusterInfoBox } from "~/platform/clusters/ClusterOverview";
18+
import ClusterFreshness from "~/platform/clusters/ClusterOverview/ClusterFreshness";
19+
import { ClusterParams } from "~/platform/clusters/ClusterRoutes";
20+
import LargestMaintainedQueries from "~/platform/clusters/LargestMaintainedQueries";
21+
import { useAllClusters } from "~/store/allClusters";
22+
import { assert } from "~/util";
23+
24+
import { ResourceUsage } from "./ResourceUsage/ResourceUsage";
25+
26+
export const ClusterMetrics = () => {
27+
const { clusterId } = useParams<ClusterParams>();
28+
assert(clusterId);
29+
const { getClusterById } = useAllClusters();
30+
const cluster = getClusterById(clusterId);
31+
const flags = useFlags();
32+
33+
// `ClusterRoutes` redirects away from a cluster that doesn't exist, so a
34+
// missing one is still loading.
35+
if (!cluster) return <LoadingContainer />;
36+
37+
return (
38+
<MainContentContainer mt="10">
39+
<VStack spacing="6">
40+
<ClusterInfoBox cluster={cluster} />
41+
<ResourceUsage cluster={cluster} />
42+
<Box width="100%">
43+
<LargestMaintainedQueries
44+
clusterId={cluster.id}
45+
clusterName={cluster.name}
46+
/>
47+
</Box>
48+
{flags["console-freshness-2855"] && (
49+
<ClusterFreshness clusterId={clusterId} />
50+
)}
51+
</VStack>
52+
</MainContentContainer>
53+
);
54+
};

‎console/src/platform/clusters/ClusterPage/ClusterPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import {
2020
Tab,
2121
} from "~/layouts/BaseLayout";
2222
import { ClusterDetailBreadcrumbs } from "~/platform/clusters/ClusterDetailBreadcrumbs";
23-
import ClusterOverview from "~/platform/clusters/ClusterOverview";
2423
import ClusterReplicas from "~/platform/clusters/ClusterReplicas";
2524
import { ClusterParams } from "~/platform/clusters/ClusterRoutes";
2625
import { SentryRoutes } from "~/sentry";
2726
import { useAllClusters } from "~/store/allClusters";
27+
import { useSubscribeToAllObjectsCollection } from "~/store/allObjectsCollection";
2828
import { assert, pluralize } from "~/util";
2929

30+
import { ClusterMetrics } from "./ClusterMetrics";
3031
import { ClusterObjects } from "./ClusterObjects";
3132
import { CLUSTER_OBJECT_TYPES } from "./clusterObjectTypes";
3233

@@ -67,6 +68,7 @@ const ClusterPage = () => {
6768
assert(clusterName);
6869
const { getClusterById } = useAllClusters();
6970
const cluster = getClusterById(clusterId);
71+
useSubscribeToAllObjectsCollection();
7072

7173
const breadcrumbs: Breadcrumb[] = React.useMemo(
7274
() => [
@@ -88,7 +90,7 @@ const ClusterPage = () => {
8890
</VStack>
8991
</PageHeader>
9092
<SentryRoutes>
91-
<Route index element={<ClusterOverview key={clusterName} />} />
93+
<Route index element={<ClusterMetrics key={clusterName} />} />
9294
<Route
9395
path="objects"
9496
element={<Navigate to={CLUSTER_OBJECT_TYPES[0].path} replace />}

0 commit comments

Comments
 (0)