Skip to content

Commit a444987

Browse files
ui: fix statement activity timepicker for sub-hour ranges
This commit fixes a bug where the statement activity time picker wasn't working correctly with time ranges less than an hour when sql.stats.aggregation.interval is set to values smaller than 1h. The issue was that API calls were using toRoundedDateRange() which rounds timestamps to hour boundaries instead of toDateRange() which uses the exact selected time range. This prevented sub-hour time ranges from working properly even when the aggregation interval supported them. Changed the following components to use toDateRange(): - StatementsPage - TransactionsPage - TransactionDetails - StatementDetails selectors - IndexDetails API Fixes #145430 Epic: None Release note (bug fix): Fixed statement activity page time picker to work correctly with time ranges less than an hour when sql.stats.aggregation.interval is configured to sub-hour values. Previously, selecting a 10-minute window would query for a full hour of data instead of the precise selected range.
1 parent bbe6bc6 commit a444987

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

pkg/ui/workspaces/cluster-ui/src/api/indexDetailsApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
import { INTERNAL_APP_NAME_PREFIX } from "../activeExecutions/activeStatementUtils";
2222
import { AggregateStatistics } from "../statementsTable";
23-
import { TimeScale, toRoundedDateRange } from "../timeScaleDropdown";
23+
import { TimeScale, toDateRange } from "../timeScaleDropdown";
2424

2525
export type TableIndexStatsRequest =
2626
cockroach.server.serverpb.TableIndexStatsRequest;
@@ -77,7 +77,7 @@ export function StatementsListRequestFromDetails(
7777
ts: TimeScale,
7878
): StatementsUsingIndexRequest {
7979
if (ts === null) return { table, index, database };
80-
const [start, end] = toRoundedDateRange(ts);
80+
const [start, end] = toDateRange(ts);
8181
return { table, index, database, start, end };
8282
}
8383

pkg/ui/workspaces/cluster-ui/src/searchCriteria/searchCriteria.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
// included in the /LICENSE file.
55

66
import { CaretDown } from "@cockroachlabs/icons";
7+
import { InlineAlert } from "@cockroachlabs/ui-components";
78
import { Menu, Dropdown } from "antd";
89
import classNames from "classnames/bind";
10+
import moment from "moment-timezone";
911
import { MenuClickEventHandler } from "rc-menu/es/interface";
1012
import React from "react";
1113

@@ -17,6 +19,7 @@ import {
1719
TimeScale,
1820
timeScale1hMinOptions,
1921
TimeScaleDropdown,
22+
toDateRange,
2023
} from "src/timeScaleDropdown";
2124

2225
import { applyBtn } from "../queryFilter/filterClasses";
@@ -60,6 +63,11 @@ export function SearchCriteria(props: SearchCriteriaProps): React.ReactElement {
6063
onChangeBy,
6164
onChangeTimeScale,
6265
} = props;
66+
67+
// Check if selected time range is less than 1 hour
68+
const [start, end] = toDateRange(currentScale);
69+
const duration = moment.duration(end.diff(start));
70+
const isSubHourRange = duration.asHours() < 1;
6371
const sortOptions: SortOption[] =
6472
searchType === "Statement" ? stmtRequestSortOptions : txnRequestSortOptions;
6573
const sortMoreOptions: SortOption[] =
@@ -119,6 +127,14 @@ export function SearchCriteria(props: SearchCriteriaProps): React.ReactElement {
119127
return (
120128
<div className={cx("search-area")}>
121129
<h5 className={commonStyles("base-heading")}>Search Criteria</h5>
130+
{isSubHourRange && (
131+
<div style={{ marginBottom: "16px" }}>
132+
<InlineAlert
133+
intent="warning"
134+
title="Sub-hour time range selected: Statement statistics are aggregated hourly by default. You may not see data for time ranges less than 1 hour if the aggregation interval has not elapsed yet. Adjust the sql.stats.aggregation.interval cluster setting if you need finer granularity."
135+
/>
136+
</div>
137+
)}
122138
<PageConfig className={cx("top-area")}>
123139
<PageConfigItem>
124140
<label>

pkg/ui/workspaces/cluster-ui/src/statementDetails/statementDetails.selectors.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { RouteComponentProps } from "react-router-dom";
1111

1212
import { AppState } from "../store";
1313
import { selectTimeScale } from "../store/utils/selectors";
14-
import { TimeScale, toRoundedDateRange } from "../timeScaleDropdown";
14+
import { TimeScale, toDateRange } from "../timeScaleDropdown";
1515
import {
1616
appNamesAttr,
1717
statementAttr,
@@ -41,12 +41,10 @@ export const selectStatementDetails = createSelector(
4141
lastError: Error;
4242
lastUpdated: moment.Moment | null;
4343
} => {
44-
// Since the aggregation interval is 1h, we want to round the selected timeScale to include
45-
// the full hour. If a timeScale is between 14:32 - 15:17 we want to search for values
46-
// between 14:00 - 16:00. We don't encourage the aggregation interval to be modified, but
47-
// in case that changes in the future we might consider changing this function to use the
48-
// cluster settings value for the rounding function.
49-
const [start, end] = toRoundedDateRange(timeScale);
44+
// Use the exact time range selected by the user, not rounded to hour boundaries.
45+
// This allows for more granular time ranges when sql.stats.aggregation.interval
46+
// is set to a value smaller than 1 hour.
47+
const [start, end] = toDateRange(timeScale);
5048
const key = generateStmtDetailsToID(
5149
fingerprintID,
5250
appNames,

pkg/ui/workspaces/cluster-ui/src/statementsPage/statementsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ import {
8888
getValidOption,
8989
TimeScale,
9090
timeScale1hMinOptions,
91-
toRoundedDateRange,
91+
toDateRange,
9292
} from "../timeScaleDropdown";
9393
import timeScaleStyles from "../timeScaleDropdown/timeScale.module.scss";
9494

@@ -175,7 +175,7 @@ type RequestParams = Pick<
175175
>;
176176

177177
function stmtsRequestFromParams(params: RequestParams): StatementsRequest {
178-
const [start, end] = toRoundedDateRange(params.timeScale);
178+
const [start, end] = toDateRange(params.timeScale);
179179
return createCombinedStmtsRequest({
180180
start,
181181
end,

pkg/ui/workspaces/cluster-ui/src/transactionDetails/transactionDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {
7979
timeScale1hMinOptions,
8080
TimeScaleDropdown,
8181
timeScaleRangeToObj,
82-
toRoundedDateRange,
82+
toDateRange,
8383
} from "../timeScaleDropdown";
8484
import timeScaleStyles from "../timeScaleDropdown/timeScale.module.scss";
8585
import { baseHeadingClasses } from "../transactionsPage/transactionsPageClasses";
@@ -143,7 +143,7 @@ interface TState {
143143
function statementsRequestFromProps(
144144
props: TransactionDetailsProps,
145145
): StatementsRequest {
146-
const [start, end] = toRoundedDateRange(props.timeScale);
146+
const [start, end] = toDateRange(props.timeScale);
147147
return createCombinedStmtsRequest({
148148
start,
149149
end,

pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import {
6666
TimeScale,
6767
timeScale1hMinOptions,
6868
getValidOption,
69-
toRoundedDateRange,
69+
toDateRange,
7070
} from "../timeScaleDropdown";
7171
import timeScaleStyles from "../timeScaleDropdown/timeScale.module.scss";
7272
import {
@@ -140,7 +140,7 @@ export type TransactionsPageProps = TransactionsPageStateProps &
140140
type RequestParams = Pick<TState, "timeScale" | "limit" | "reqSortSetting">;
141141

142142
function stmtsRequestFromParams(params: RequestParams): StatementsRequest {
143-
const [start, end] = toRoundedDateRange(params.timeScale);
143+
const [start, end] = toDateRange(params.timeScale);
144144
return createCombinedStmtsRequest({
145145
start,
146146
end,

0 commit comments

Comments
 (0)