Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: add Transaction and Statement fingerprint id #85464

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ICollectedStatementStatistics =
cockroach.server.serverpb.StatementsResponse.ICollectedStatementStatistics;
export interface StatementsSummaryData {
statementFingerprintID: string;
statementFingerprintHexID: string;
statement: string;
statementSummary: string;
aggregatedTs: number;
Expand Down Expand Up @@ -175,6 +176,8 @@ export const selectStatements = createSelector(
if (!(key in statsByStatementKey)) {
statsByStatementKey[key] = {
statementFingerprintID: stmt.statement_fingerprint_id?.toString(),
statementFingerprintHexID:
stmt.statement_fingerprint_id?.toString(16),
statement: stmt.statement,
statementSummary: stmt.statement_summary,
aggregatedTs: stmt.aggregated_ts,
Expand All @@ -192,6 +195,7 @@ export const selectStatements = createSelector(
const stmt = statsByStatementKey[key];
return {
aggregatedFingerprintID: stmt.statementFingerprintID,
aggregatedFingerprintHexID: stmt.statementFingerprintHexID,
label: stmt.statement,
summary: stmt.statementSummary,
aggregatedTs: stmt.aggregatedTs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("StatementsPage", () => {

const statement: AggregateStatistics = {
aggregatedFingerprintID: "",
aggregatedFingerprintHexID: "",
aggregatedTs: 0,
aggregationInterval: 0,
database: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,21 @@ export function filterBySearchQuery(
search: string,
): boolean {
const matchString = statement.label.toLowerCase();
const matchFingerPrintId = statement.aggregatedFingerprintHexID;

// If search term is wrapped by quotes, do the exact search term.
if (search.startsWith('"') && search.endsWith('"')) {
search = search.substring(1, search.length - 1);
return matchString.includes(search);

return matchString.includes(search) || matchFingerPrintId.includes(search);
}

return search
.toLowerCase()
.split(" ")
.every(val => matchString.includes(val));
.every(
val => matchString.includes(val) || matchFingerPrintId.includes(val),
);
}

export class StatementsPage extends React.Component<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@ function makeCommonColumns(
TimestampToNumber(stmt.stats.last_exec_timestamp),
showByDefault: false,
},
{
name: "statementFingerprintId",
title: statisticsTableTitles.statementFingerprintId(statType),
cell: (stmt: AggregateStatistics) => stmt.aggregatedFingerprintHexID,
sort: (stmt: AggregateStatistics) => stmt.aggregatedFingerprintHexID,
showByDefault: false,
},
];
}

export interface AggregateStatistics {
aggregatedFingerprintID: string;
aggregatedFingerprintHexID: string;
// label is either shortStatement (StatementsPage) or nodeId (StatementDetails).
label: string;
// summary exists only for SELECT/INSERT/UPSERT/UPDATE statements, and is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const statisticsColumnLabels = {
transactions: "Transactions",
workloadPct: "% of All Runtime",
lastExecTimestamp: "Last Execution Time (UTC)",
statementFingerprintId: "Statement Fingerprint ID",
transactionFingerprintId: "Transaction Fingerprint ID",
};

export const contentModifiers = {
Expand Down Expand Up @@ -242,6 +244,32 @@ export const statisticsTableTitles: StatisticTableTitleType = {
</Tooltip>
);
},
statementFingerprintId: () => {
return (
<Tooltip
style="tableTitle"
placement="bottom"
content={
"The statement fingerprint id is the combination of the statement fingerprint, the database it was executed on, the transaction type (implicit or explicit) and whether execution has failed (true or false)."
}
>
{getLabel("statementFingerprintId")}
</Tooltip>
);
},
transactionFingerprintId: () => {
return (
<Tooltip
style="tableTitle"
placement="bottom"
content={
"The transaction fingerprint id represents the list of statement fingerprint ids in order of execution within that transaction."
}
>
{getLabel("transactionFingerprintId")}
</Tooltip>
);
},
actions: () => {
return (
<Tooltip
Expand Down
33 changes: 22 additions & 11 deletions pkg/ui/workspaces/cluster-ui/src/transactionsPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const aggregateStatements = (
if (!(key in statsKey)) {
statsKey[key] = {
aggregatedFingerprintID: s.statement_fingerprint_id?.toString(),
aggregatedFingerprintHexID: s.statement_fingerprint_id.toString(16),
label: s.statement,
summary: s.statement_summary,
aggregatedTs: s.aggregated_ts,
Expand Down Expand Up @@ -129,19 +130,29 @@ export const searchTransactionsData = (
searchTerms = [search.substring(1, search.length - 1)];
}

if (!search) {
return transactions;
}

return transactions.filter((t: Transaction) =>
search
? searchTerms.every(val =>
collectStatementsText(
getStatementsByFingerprintId(
t.stats_data.statement_fingerprint_ids,
statements,
),
)
.toLowerCase()
.includes(val.toLowerCase()),
searchTerms.every(val => {
if (
collectStatementsText(
getStatementsByFingerprintId(
t.stats_data.statement_fingerprint_ids,
statements,
),
)
: true,
.toLowerCase()
.includes(val.toLowerCase())
) {
return true;
}

return t.stats_data.transaction_fingerprint_id
?.toString(16)
?.includes(val);
}),
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ export function makeTransactionsColumns(
sort: (item: TransactionInfo) =>
item.stats_data.statement_fingerprint_ids.length,
},
{
name: "transactionFingerprintId",
title: statisticsTableTitles.transactionFingerprintId(statType),
cell: (item: TransactionInfo) =>
item.stats_data?.transaction_fingerprint_id.toString(16),
sort: (item: TransactionInfo) =>
item.stats_data?.transaction_fingerprint_id.toString(16),
showByDefault: false,
},
].filter(c => !(isTenant && c.hideIfTenant));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type StatementStatistics = util.StatementStatistics;

interface StatementsSummaryData {
statementFingerprintID: string;
statementFingerprintHexID: string;
statement: string;
statementSummary: string;
aggregatedTs: number;
Expand Down Expand Up @@ -140,6 +141,8 @@ export const selectStatements = createSelector(
if (!(key in statsByStatementKey)) {
statsByStatementKey[key] = {
statementFingerprintID: stmt.statement_fingerprint_id?.toString(),
statementFingerprintHexID:
stmt.statement_fingerprint_id?.toString(16),
statement: stmt.statement,
statementSummary: stmt.statement_summary,
aggregatedTs: stmt.aggregated_ts,
Expand All @@ -157,6 +160,7 @@ export const selectStatements = createSelector(
const stmt = statsByStatementKey[key];
return {
aggregatedFingerprintID: stmt.statementFingerprintID,
aggregatedFingerprintHexID: stmt.statementFingerprintHexID,
label: stmt.statement,
summary: stmt.statementSummary,
aggregatedTs: stmt.aggregatedTs,
Expand Down