Skip to content

Commit

Permalink
[Bugfix][Dashboard] Fix undefined logCount, errorCount UI crash (#13113)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfitton authored Dec 30, 2020
1 parent 42cd414 commit 25f7bdc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
8 changes: 4 additions & 4 deletions dashboard/client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type ProcessStats = {
export type Worker = {
pid: number;
workerId: string;
logCount: number;
errorCount: number;
logCount?: number;
errorCount?: number;
language: string;
jobId: string;
coreWorkerStats: CoreWorkerStats[];
Expand Down Expand Up @@ -167,8 +167,8 @@ type BaseNodeInfo = {
};
loadAvg: [[number, number, number], [number, number, number]];
net: [number, number]; // Sent and received network traffic in bytes / second
logCount: number;
errorCount: number;
logCount?: number;
errorCount?: number;
};

export type NodeInfoResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "./types";

const ClusterErrors: ClusterFeatureRenderFn = ({ nodes }) => {
const totalErrCount = sum(nodes.map((node) => node.errorCount));
const totalErrCount = sum(nodes.map((node) => node.errorCount ?? 0));
return totalErrCount === 0 ? (
<Typography color="textSecondary" component="span" variant="inherit">
No errors
Expand All @@ -29,26 +29,27 @@ const ClusterErrors: ClusterFeatureRenderFn = ({ nodes }) => {
const makeNodeErrors = (
setErrorDialog: (nodeIp: string, pid: number | null) => void,
): NodeFeatureRenderFn => ({ node }) => {
return node.errorCount === 0 ? (
const errorCount = node.errorCount ?? 0;
return errorCount === 0 ? (
<Typography color="textSecondary" component="span" variant="inherit">
No errors
</Typography>
) : (
<SpanButton onClick={() => setErrorDialog(node.ip, null)}>
View all errors ({node.errorCount.toLocaleString()})
View all errors ({errorCount.toLocaleString()})
</SpanButton>
);
};

const nodeErrorsAccessor: Accessor<NodeFeatureData> = ({ node }) =>
node.errorCount;
node.errorCount ?? 0;

const makeWorkerErrors = (
setErrorDialog: (nodeIp: string, pid: number | null) => void,
): WorkerFeatureRenderFn => ({ node, worker }) => {
return worker.errorCount !== 0 ? (
<SpanButton onClick={() => setErrorDialog(node.ip, worker.pid)}>
View errors ({worker.errorCount.toLocaleString()})
View errors ({worker.errorCount?.toLocaleString()})
</SpanButton>
) : (
<Typography color="textSecondary" component="span" variant="inherit">
Expand All @@ -58,7 +59,7 @@ const makeWorkerErrors = (
};

const workerErrorsAccessor: Accessor<WorkerFeatureData> = ({ worker }) =>
worker.errorCount;
worker.errorCount ?? 0;

const makeErrorsFeature = (
setErrorDialog: (nodeIp: string, pid: number | null) => void,
Expand Down
20 changes: 12 additions & 8 deletions dashboard/client/src/pages/dashboard/node-info/features/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "./types";

const ClusterLogs: ClusterFeatureRenderFn = ({ nodes }) => {
const totalLogCount = sum(nodes.map((n) => n.logCount));
const totalLogCount = sum(nodes.map((n) => n.logCount ?? 0));
return totalLogCount === 0 ? (
<Typography color="textSecondary" component="span" variant="inherit">
No logs
Expand All @@ -27,37 +27,41 @@ const ClusterLogs: ClusterFeatureRenderFn = ({ nodes }) => {

const makeNodeLogs = (
setLogDialog: (nodeIp: string, pid: number | null) => void,
): NodeFeatureRenderFn => ({ node }) =>
node.logCount === 0 ? (
): NodeFeatureRenderFn => ({ node }) => {
const logCount = node.logCount ?? 0;
return logCount === 0 ? (
<Typography color="textSecondary" component="span" variant="inherit">
No logs
</Typography>
) : (
<SpanButton onClick={() => setLogDialog(node.ip, null)}>
View all logs ({node.logCount.toLocaleString()}{" "}
View all logs ({logCount.toLocaleString()}{" "}
{node.logCount === 1 ? "line" : "lines"})
</SpanButton>
);
};

const nodeLogsAccessor: Accessor<NodeFeatureData> = ({ node }) =>
node.logCount ? sum(Object.values(node.logCount)) : 0;

const makeWorkerLogs = (
setLogDialog: (nodeIp: string, pid: number | null) => void,
): WorkerFeatureRenderFn => ({ worker, node }) =>
worker.logCount !== 0 ? (
): WorkerFeatureRenderFn => ({ worker, node }) => {
const logCount = worker.logCount ?? 0;
return logCount !== 0 ? (
<SpanButton onClick={() => setLogDialog(node.ip, worker.pid)}>
View log ({worker.logCount.toLocaleString()}{" "}
View log ({logCount.toLocaleString()}{" "}
{worker.logCount === 1 ? "line" : "lines"})
</SpanButton>
) : (
<Typography color="textSecondary" component="span" variant="inherit">
No logs
</Typography>
);
};

const workerLogsAccessor: Accessor<WorkerFeatureData> = ({ worker }) =>
worker.logCount;
worker.logCount ?? 0;

const makeLogsFeature = (
setLogDialog: (nodeIp: string, pid: number | null) => void,
Expand Down

0 comments on commit 25f7bdc

Please sign in to comment.