Skip to content

Commit 9d0aa6f

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. - Replicas of one cluster that share a name, such as a scheduled cluster's refreshes, share one toggle, color, status row and tooltip section. A past blue-green deployment's replicas keep their own. A time's memory bars split only among the replicas reporting then, and a CPU reading with no neighbor draws as a dot. - Processes: when a replica's size runs more than one process, a Processes button on the CPU chart opens a drawer with a tab per such replica. Each tab compares processes by their latest reading, their peak (the default) or their average, and names the busiest process for CPU and for memory by that reading against the others. One CPU and one memory chart draw every process as its own line. A table lists each process's latest, peak and average readings, with a checkbox per row and one in the header to pick which lines are drawn. Readings are shares of one process's allocation over the card's window up to 24h, and the drawer says so when the card's window is longer. It reads each process's samples from a SUBSCRIBE that is open only while the drawer is. Wide windows merge neighboring buckets, keeping each metric's peak, so bars stay at least 10px wide for as many replicas as report at once. The time axis matches the classic graphs. The mark layers are memoized, so hovering only redraws the cursor and tooltip.
1 parent bddd20b commit 9d0aa6f

23 files changed

Lines changed: 5073 additions & 25 deletions

‎console/src/api/materialize/cluster/replicaUtilizationBinning.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,11 @@ export function toReplicaUtilizationGraphData(
395395
size,
396396
offlineEvents,
397397
name,
398+
clusterId,
398399
}) => ({
399400
id: replicaId,
400401
name,
402+
clusterId,
401403
bucketEnd: bucketEnd.getTime(),
402404
bucketStart: bucketStart.getTime(),
403405
cpuPercent: maxCpu?.percent ? maxCpu.percent * 100 : null,

‎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

‎console/src/platform/clusters/ClusterOverview/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export type GraphDataKey =
1717
export interface DataPoint {
1818
id: string;
1919
name: string;
20+
/**
21+
* The replica's cluster, which is a past blue-green deployment's for a
22+
* replica charted through the cluster's lineage.
23+
*/
24+
clusterId?: string;
2025
size: string | null;
2126
bucketStart: number;
2227
bucketEnd: number;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 { screen } from "@testing-library/react";
11+
import React from "react";
12+
import { Route, Routes } from "react-router-dom";
13+
14+
import { Cluster } from "~/api/materialize/cluster/clusterList";
15+
import { ErrorCode } from "~/api/materialize/types";
16+
import { getStore } from "~/jotai";
17+
import { CLUSTERS_FETCH_ERROR_MESSAGE } from "~/platform/clusters/constants";
18+
import { allClusters } from "~/store/allClusters";
19+
import { mockSubscribeState } from "~/test/mockSubscribe";
20+
import { renderComponent } from "~/test/utils";
21+
22+
import { ClusterMetrics } from "./ClusterMetrics";
23+
24+
describe("ClusterMetrics", () => {
25+
it("shows an error when the clusters subscribe fails before its snapshot", async () => {
26+
getStore().set(
27+
allClusters,
28+
mockSubscribeState<Cluster>({
29+
snapshotComplete: false,
30+
error: {
31+
code: ErrorCode.INTERNAL_ERROR,
32+
message: "Something went wrong",
33+
},
34+
}),
35+
);
36+
await renderComponent(
37+
<Routes>
38+
<Route path=":clusterId/:clusterName" element={<ClusterMetrics />} />
39+
</Routes>,
40+
{ initialRouterEntries: ["/u1/default"] },
41+
);
42+
43+
expect(await screen.findByText(CLUSTERS_FETCH_ERROR_MESSAGE)).toBeVisible();
44+
});
45+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 ErrorBox from "~/components/ErrorBox";
15+
import { LoadingContainer } from "~/components/LoadingContainer";
16+
import { useFlags } from "~/hooks/useFlags";
17+
import { MainContentContainer } from "~/layouts/BaseLayout";
18+
import { ClusterInfoBox } from "~/platform/clusters/ClusterOverview";
19+
import ClusterFreshness from "~/platform/clusters/ClusterOverview/ClusterFreshness";
20+
import { ClusterParams } from "~/platform/clusters/ClusterRoutes";
21+
import { CLUSTERS_FETCH_ERROR_MESSAGE } from "~/platform/clusters/constants";
22+
import LargestMaintainedQueries from "~/platform/clusters/LargestMaintainedQueries";
23+
import { useAllClusters } from "~/store/allClusters";
24+
import { assert } from "~/util";
25+
26+
import { ResourceUsage } from "./ResourceUsage/ResourceUsage";
27+
28+
export const ClusterMetrics = () => {
29+
const { clusterId } = useParams<ClusterParams>();
30+
assert(clusterId);
31+
const { getClusterById, isError } = useAllClusters();
32+
const cluster = getClusterById(clusterId);
33+
const flags = useFlags();
34+
35+
// `ClusterRoutes` redirects away from a cluster that doesn't exist, so a
36+
// missing one is still loading, unless the subscribe failed first.
37+
if (!cluster) {
38+
return isError ? (
39+
<ErrorBox message={CLUSTERS_FETCH_ERROR_MESSAGE} />
40+
) : (
41+
<LoadingContainer />
42+
);
43+
}
44+
45+
return (
46+
<MainContentContainer mt="10">
47+
<VStack spacing="6">
48+
<ClusterInfoBox cluster={cluster} />
49+
<ResourceUsage cluster={cluster} />
50+
<Box width="100%">
51+
<LargestMaintainedQueries
52+
clusterId={cluster.id}
53+
clusterName={cluster.name}
54+
/>
55+
</Box>
56+
{flags["console-freshness-2855"] && (
57+
<ClusterFreshness clusterId={clusterId} />
58+
)}
59+
</VStack>
60+
</MainContentContainer>
61+
);
62+
};

‎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)