Skip to content

Commit

Permalink
ui: fix timescale for rolling window
Browse files Browse the repository at this point in the history
The change introduced on #105157 had an undesired
change on the Metrics page. We want to show the end period
of the select, but when the fixed window end for that this
caused the Metrics page to stop loading new data.
We want the metrics page to keep updating when any of the
rolling windows is selected, and we also want to know
the time a time period was requested, so it can be used
to provide more information on SQL Activity pages.

This commit remove the setting of the fixedWindowEnd, since
that was not the best approach and instead creates a new
parameter for requestTime, that can be used to create
the label for the timescale, without interferring on
Metrics page (or any other that have an automatic update).

Epic: none

Release note (bug fix): Fix the Metrics page that was not
updating automatically on rolling window options.
  • Loading branch information
maryliag committed Jul 11, 2023
1 parent 92d5d0e commit 3b74bb6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ export const getStatementDetailsPropsFixture = (
sampleSize: moment.duration(5, "minutes"),
fixedWindowEnd: moment.utc("2021.12.12"),
key: "Custom",
requestTime: false,
},
statementFingerprintID: "4705782015019656142",
statementDetails: withData ? statementDetailsData : statementDetailsNoData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class StatementDetails extends React.Component<

changeTimeScale = (ts: TimeScale): void => {
if (ts.key !== "Custom") {
ts.fixedWindowEnd = moment();
ts.requestTime = moment();
}
if (this.props.onTimeScaleChange) {
this.props.onTimeScaleChange(ts);
Expand Down Expand Up @@ -701,7 +701,7 @@ export class StatementDetails extends React.Component<
<TimeScaleDropdown
options={timeScale1hMinOptions}
currentScale={this.props.timeScale}
setTimeScale={this.props.onTimeScaleChange}
setTimeScale={this.changeTimeScale}
/>
</PageConfigItem>
</PageConfig>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ const statementsPagePropsFixture: StatementsPageProps = {
sampleSize: moment.duration(5, "minutes"),
fixedWindowEnd: moment.utc("2021.12.12"),
key: "Custom",
requestTime: false,
},
columns: null,
isTenant: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class StatementsPage extends React.Component<

changeTimeScale = (ts: TimeScale): void => {
if (ts.key !== "Custom") {
ts.fixedWindowEnd = moment();
ts.requestTime = moment();
}
this.setState(prevState => ({
...prevState,
Expand All @@ -280,7 +280,7 @@ export class StatementsPage extends React.Component<
this.props.onChangeReqSort(this.state.reqSortSetting);
}

// Force an update on TimeScale to update the fixedWindowEnd
// Force an update on TimeScale to update the requestTime.
this.changeTimeScale(this.state.timeScale);
if (this.props.timeScale !== this.state.timeScale) {
this.props.onTimeScaleChange(this.state.timeScale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const FormattedTimescale = (props: { ts: TimeScale }) => {
omitDayFormat || startEndOnSameDay ? "" : endTz.format(dateFormat);
const timeStart = startTz.format(timeFormat);
const timeEnd =
props.ts.key !== "Custom" && props.ts.fixedWindowEnd
? props.ts.fixedWindowEnd.tz(timezone).format(timeFormat)
props.ts.key !== "Custom" && props.ts.requestTime
? props.ts.requestTime.tz(timezone).format(timeFormat)
: endTz.format(timeFormat);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface TimeScale {
* It is unclear if there are legitimate reasons for the two being out of sync.
*/
fixedWindowEnd: moment.Moment | false;
// For cases where the value is not custom and we want to clarify the time a request was made,
// because we're pausing the rolling window.
requestTime: moment.Moment | false;
}

export class TimeScaleState {
Expand All @@ -56,7 +59,7 @@ export class TimeScaleState {
}
}

export type TimeScaleOption = Omit<TimeScale, "fixedWindowEnd">;
export type TimeScaleOption = Omit<TimeScale, "fixedWindowEnd" | "requestTime">;

export interface TimeScaleOptions {
[key: string]: TimeScaleOption;
Expand Down
2 changes: 2 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/timeScaleDropdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const defaultTimeScaleSelected: TimeScale = {
...defaultTimeScaleOptions["Past Hour"],
key: "Past Hour",
fixedWindowEnd: false,
requestTime: false,
};

// toDateRange returns the actual value of start and end date, based on
Expand Down Expand Up @@ -172,6 +173,7 @@ export const createTimeScaleFromDateRange = (
windowSize: moment.duration(end.diff(start)),
fixedWindowEnd: end,
key: "Custom",
requestTime: false,
};

return timeScale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class TransactionDetails extends React.Component<

changeTimeScale = (ts: TimeScale): void => {
if (ts.key !== "Custom") {
ts.fixedWindowEnd = moment();
ts.requestTime = moment();
}
if (this.props.onTimeScaleChange) {
this.props.onTimeScaleChange(ts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export class TransactionsPage extends React.Component<

changeTimeScale = (ts: TimeScale): void => {
if (ts.key !== "Custom") {
ts.fixedWindowEnd = moment();
ts.requestTime = moment();
}
this.setState(prevState => ({ ...prevState, timeScale: ts }));
};
Expand All @@ -408,7 +408,7 @@ export class TransactionsPage extends React.Component<
this.props.onChangeReqSort(this.state.reqSortSetting);
}

// Force an update on TimeScale to update the fixedWindowEnd
// Force an update on TimeScale to update the requestTime
this.changeTimeScale(this.state.timeScale);
if (this.props.timeScale !== this.state.timeScale) {
this.props.onTimeScaleChange(this.state.timeScale);
Expand Down

0 comments on commit 3b74bb6

Please sign in to comment.