Skip to content

Commit

Permalink
ui: fix infinite re-render on the key visualizer page
Browse files Browse the repository at this point in the history
Since #101258, the TimeScaleDropdownWithSearchParams
can cause infinite re-renders. The exact cause of the bug
is not yet diagnosed, but it occurs on the key visualizer page,
and seems to be related to the custom duration options. This
is tracked in #106395.

This commit removes the dependency on TimeScaleDropdownWithSearchParams
from the key visualizer, and replaces it with the vanilla TimeScaleDropdown.
The custom duration options are still present.

Informs: #106395
Epic: none
Release note: None
  • Loading branch information
zachlite committed Jul 7, 2023
1 parent 821ee3a commit db1d589
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 65 deletions.
58 changes: 54 additions & 4 deletions pkg/ui/workspaces/db-console/src/views/keyVisualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,64 @@ import {
SampleBucket,
} from "src/views/keyVisualizer/interfaces";
import { CanvasHeight, XAxisPadding } from "./constants";
import { KeyVisualizerTimeWindow } from "src/views/keyVisualizer/timeWindow";
import { AdminUIState } from "src/redux/state";
import { connect } from "react-redux";
import { TimeScale, util } from "@cockroachlabs/cluster-ui";
import {
TimeScale,
TimeScaleDropdown,
TimeScaleOptions,
util,
} from "@cockroachlabs/cluster-ui";
import { selectClusterSettings } from "src/redux/clusterSettings";
import { selectTimeScale } from "src/redux/timeScale";
import { selectTimeScale, setTimeScale } from "src/redux/timeScale";
import { refreshSettings } from "src/redux/apiReducers";
import KeyVisSamplesRequest = cockroach.server.serverpb.KeyVisSamplesRequest;
import KeyVisSamplesResponse = cockroach.server.serverpb.KeyVisSamplesResponse;
import { BackToAdvanceDebug } from "../reports/containers/util";
import { RouteComponentProps } from "react-router-dom";
import moment from "moment-timezone";

const EnabledSetting = "keyvisualizer.enabled";
const IntervalSetting = "keyvisualizer.sample_interval";

const timeScaleOptions: TimeScaleOptions = {
"Past 30 Minutes": {
windowSize: moment.duration(30, "minutes"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past Hour": {
windowSize: moment.duration(1, "hour"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past 6 Hours": {
windowSize: moment.duration(6, "hours"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past Day": {
windowSize: moment.duration(1, "day"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past 2 Days": {
windowSize: moment.duration(2, "day"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past 3 Days": {
windowSize: moment.duration(3, "day"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
"Past Week": {
windowSize: moment.duration(7, "days"),
windowValid: moment.duration(15, "minutes"),
sampleSize: moment.duration(1, "minutes"),
},
};

export function getRequestsAsNumber(requests: number | Long | null): number {
if (typeof requests === "number") {
return requests;
Expand Down Expand Up @@ -135,6 +178,7 @@ function buildKeyVisualizerProps(
interface KeyVisualizerContainerProps {
refreshInterval: number;
timeScale: TimeScale;
setTimeScale: typeof setTimeScale;
}

class KeyVisualizerContainer extends React.Component<
Expand Down Expand Up @@ -184,7 +228,11 @@ class KeyVisualizerContainer extends React.Component<
<>
<BackToAdvanceDebug history={this.props.history} />
<div style={{ position: "relative" }}>
<KeyVisualizerTimeWindow />
<TimeScaleDropdown
options={timeScaleOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.setTimeScale}
/>
<KeyVisualizer
samples={samples}
yOffsetsForKey={yOffsetsForKey}
Expand All @@ -202,6 +250,7 @@ interface KeyVisualizerPageProps {
[key: string]: cockroach.server.serverpb.SettingsResponse.IValue;
};
refreshSettings: typeof refreshSettings;
setTimeScale: typeof setTimeScale;
timeScale: TimeScale;
}

Expand Down Expand Up @@ -245,5 +294,6 @@ export default connect(
}),
{
refreshSettings,
setTimeScale,
},
)(KeyVisualizerPage);

This file was deleted.

0 comments on commit db1d589

Please sign in to comment.