Skip to content

Commit

Permalink
ui: add search, filter and time picker on index details
Browse files Browse the repository at this point in the history
Fixes cockroachdb#93087

This commit adds search, filters and time picker for the
list of fingerprints most used per index, on the Index
Details page.

It also limits to 20 fingerprints until we can make
improvements to use pagination on our calls with
sql-over-http.

Release note (ui change): Add search, filter and time picker
for the list of most used statement fingerprints on the
Index Details page.
  • Loading branch information
maryliag committed Jan 31, 2023
1 parent 5f0c56e commit 632bd2f
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 157 deletions.
42 changes: 24 additions & 18 deletions pkg/ui/workspaces/cluster-ui/src/api/indexDetailsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
convertStatementRawFormatToAggregatedStatistics,
executeInternalSql,
fetchData,
LARGE_RESULT_SIZE,
sqlApiErrorMessage,
SqlExecutionRequest,
sqlResultsAreEmpty,
StatementRawFormat,
Expand Down Expand Up @@ -81,50 +83,54 @@ export function StatementsListRequestFromDetails(
return { table, index, database, start, end };
}

export function getStatementsUsingIndex({
export async function getStatementsUsingIndex({
table,
index,
database,
start,
end,
}: StatementsUsingIndexRequest): Promise<AggregateStatistics[]> {
const args: any = [`"${table}@${index}"`];
let placeholder = 2;
let whereClause = "";
if (start) {
args.push(start);
whereClause = `${whereClause} AND aggregated_ts >= $${placeholder}`;
placeholder++;
whereClause = `${whereClause} AND aggregated_ts >= '${start.toISOString()}'`;
}
if (end) {
args.push(end);
whereClause = `${whereClause} AND aggregated_ts <= $${placeholder}`;
placeholder++;
whereClause = `${whereClause} AND aggregated_ts <= '${end.toISOString()}'`;
}

const selectStatements = {
sql: `SELECT * FROM system.statement_statistics
WHERE $1::jsonb <@ indexes_usage
AND app_name NOT LIKE '${INTERNAL_APP_NAME_PREFIX}%'
${whereClause};`,
${whereClause}
ORDER BY (statistics -> 'statistics' ->> 'cnt')::INT DESC
LIMIT 20;`,
arguments: args,
};

const req: SqlExecutionRequest = {
execute: true,
statements: [selectStatements],
database: database,
max_result_size: LARGE_RESULT_SIZE,
};

return executeInternalSql<StatementRawFormat>(req).then(res => {
if (res.error || sqlResultsAreEmpty(res)) {
return [];
}
const result = await executeInternalSql<StatementRawFormat>(req);
if (result.error) {
throw new Error(
`Error while retrieving list of statements: ${sqlApiErrorMessage(
result.error.message,
)}`,
);
}
if (sqlResultsAreEmpty(result)) {
return [];
}

const statements: AggregateStatistics[] = [];
res.execution.txn_results[0].rows.forEach(s => {
statements.push(convertStatementRawFormatToAggregatedStatistics(s));
});
return statements;
const statements: AggregateStatistics[] = [];
result.execution.txn_results[0].rows.forEach(s => {
statements.push(convertStatementRawFormatToAggregatedStatistics(s));
});
return statements;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { BreadcrumbItem } from "../breadcrumbs";
import { RecommendationType as RecType } from "./indexDetailsPage";
import { nodeRegionsByIDSelector } from "../store/nodes";
import { selectTimeScale } from "src/store/utils/selectors";
const { RecommendationType } = cockroach.sql.IndexRecommendation;

export const selectIndexDetails = createSelector(
Expand All @@ -47,6 +48,7 @@ export const selectIndexDetails = createSelector(
(state: AppState) => selectHasViewActivityRedactedRole(state),
(state: AppState) => nodeRegionsByIDSelector(state),
(state: AppState) => selectHasAdminRole(state),
(state: AppState) => selectTimeScale(state),
(
database,
schema,
Expand All @@ -57,6 +59,7 @@ export const selectIndexDetails = createSelector(
hasViewActivityRedactedRole,
nodeRegions,
hasAdminRole,
timeScale,
): IndexDetailsPageData => {
const stats = indexStats[generateTableID(database, table)];
const details = stats?.data?.statistics.filter(
Expand Down Expand Up @@ -89,6 +92,7 @@ export const selectIndexDetails = createSelector(
index,
),
isTenant: isTenant,
timeScale: timeScale,
hasViewActivityRedactedRole: hasViewActivityRedactedRole,
hasAdminRole: hasAdminRole,
nodeRegions: nodeRegions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { connect } from "react-redux";
import { actions as indexStatsActions } from "src/store/indexStats/indexStats.reducer";
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import { actions as nodesActions } from "../store/nodes";
import { TimeScale } from "../timeScaleDropdown";
import { actions as sqlStatsActions } from "../store/sqlStats";

const mapStateToProps = (state: AppState, props: RouteComponentProps) => {
return selectIndexDetails(state, props);
Expand All @@ -43,6 +45,13 @@ const mapDispatchToProps = (dispatch: Dispatch): IndexDetailPageActions => ({
},
refreshNodes: () => dispatch(nodesActions.refresh()),
refreshUserSQLRoles: () => dispatch(uiConfigActions.refreshUserSQLRoles()),
onTimeScaleChange: (ts: TimeScale) => {
dispatch(
sqlStatsActions.updateTimeScale({
ts: ts,
}),
);
},
});

export const ConnectedIndexDetailsPage = withRouter<any, any>(
Expand Down
Loading

0 comments on commit 632bd2f

Please sign in to comment.