Skip to content

Commit

Permalink
ui: txn insights v2
Browse files Browse the repository at this point in the history
Closes #91696

For the next version of txn insights, we want to show
the insights of the stmts involved in the txn. This
commit aggregates stmt insights to show at the txn
level on the txn insights overview page and the details
page.

Previously, the txn insights only showed contention
information, which we pull from a different source
(contention registry over insights system). To preserve
the information we were already showing, the aggregated
stmt insights were merged with the previous data.

Some considerations to be addressed in future PRs:
1. We don't currently track txn start and end time
in the insights system. Since there is no guarantee that
a txn in the contention registry has an entry in the insights
system, there is currently a gap in execution details for
txn contention insights being displayed.

2. For insights we only display the most recent txn execution
for a txn fingerprint that has an insight. Since the insights
system does not track txn end time, we can't know which
executed more recently when we have a txn from the contention
response and one from the insights response with the same
fingerprint, so for now we default to showing the contention
insight.

Release note (ui change): Txn insights pages now show insights
about slow execution with unknown causes, index recommendations,
and failed executions. The following fields have also been added
on the details page, but are not available for txns where the
insight is 'High Contention':
- User name
- Session ID
- rows processed
- rows read
- rows written
- retries
- last retry reason
- Full scan
- Transaction priority
  • Loading branch information
xinhaoz committed Nov 14, 2022
1 parent c6aadeb commit a2c3d54
Show file tree
Hide file tree
Showing 36 changed files with 1,257 additions and 1,029 deletions.
424 changes: 239 additions & 185 deletions pkg/ui/workspaces/cluster-ui/src/api/insightsApi.ts

Large diffs are not rendered by default.

118 changes: 88 additions & 30 deletions pkg/ui/workspaces/cluster-ui/src/insights/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ export enum InsightExecEnum {
STATEMENT = "statement",
}

export type TransactionInsightEvent = {
// What we store in redux for txn contention insight events in
// the overview page. It is missing information such as the
// blocking txn information.
export type TxnContentionInsightEvent = {
transactionID: string;
fingerprintID: string;
transactionFingerprintID: string;
queries: string[];
insights: Insight[];
startTime: Moment;
Expand All @@ -38,10 +41,11 @@ export type TransactionInsightEvent = {
execType: InsightExecEnum;
};

// Information about the blocking transaction and schema.
export type BlockedContentionDetails = {
collectionTimeStamp: Moment;
blockingExecutionID: string;
blockingFingerprintID: string;
blockingTxnFingerprintID: string;
blockingQueries: string[];
contendedKey: string;
schemaName: string;
Expand All @@ -51,56 +55,108 @@ export type BlockedContentionDetails = {
contentionTimeMs: number;
};

export type TransactionInsightEventDetails = {
executionID: string;
// TODO (xinhaoz) these fields should be placed into TxnInsightEvent
// once they are available for contention insights. MergedTxnInsightEvent,
// (which marks these fields as optional) can then be deleted.
type UnavailableForTxnContention = {
databaseName: string;
username: string;
priority: string;
retries: number;
implicitTxn: boolean;
sessionID: string;
};

export type TxnInsightEvent = UnavailableForTxnContention & {
transactionExecutionID: string;
transactionFingerprintID: string;
application: string;
lastRetryReason?: string;
contention?: moment.Duration;

// The full list of statements in this txn, with their stmt
// level insights (not all stmts in the txn may have one).
// Ordered by startTime.
statementInsights: StatementInsightEvent[];

insights: Insight[]; // De-duplicated list of insights from statement level.
queries: string[]; // We bubble this up from statementinsights for easy access, since txn contention details dont have stmt insights.
startTime?: Moment; // TODO (xinhaoz) not currently available
elapsedTimeMillis?: number; // TODO (xinhaoz) not currently available
endTime?: Moment; // TODO (xinhaoz) not currently available
};

export type MergedTxnInsightEvent = Omit<
TxnInsightEvent,
keyof UnavailableForTxnContention
> &
Partial<UnavailableForTxnContention>;

export type TxnContentionInsightDetails = {
transactionExecutionID: string;
queries: string[];
insights: Insight[];
startTime: Moment;
totalContentionTime: number;
totalContentionTimeMs: number;
contentionThreshold: number;
application: string;
fingerprintID: string;
transactionFingerprintID: string;
blockingContentionDetails: BlockedContentionDetails[];
execType: InsightExecEnum;
insightName: string;
};

export type TxnInsightDetails = Omit<MergedTxnInsightEvent, "contention"> & {
totalContentionTimeMs?: number;
contentionThreshold?: number;
blockingContentionDetails?: BlockedContentionDetails[];
execType: InsightExecEnum;
};

// Does not contain transaction information.
// This is what is stored at the transaction insight level, shown
// on the txn insights overview page.
export type StatementInsightEvent = {
// Some of these can be moved to a common InsightEvent type if txn query is updated.
statementID: string;
transactionID: string;
statementExecutionID: string;
statementFingerprintID: string;
transactionFingerprintID: string;
implicitTxn: boolean;
startTime: Moment;
isFullScan: boolean;
elapsedTimeMillis: number;
sessionID: string;
timeSpentWaiting?: moment.Duration;
isFullScan: boolean;
endTime: Moment;
databaseName: string;
username: string;
rowsRead: number;
rowsWritten: number;
lastRetryReason?: string;
priority: string;
retries: number;
causes: string[];
problem: string;
query: string;
application: string;
insights: Insight[];
indexRecommendations: string[];
planGist: string;
};

// StatementInsightEvent with their transaction level information.
// What we show in the stmt insights overview and details pages.
export type FlattenedStmtInsightEvent = StatementInsightEvent & {
transactionExecutionID: string;
transactionFingerprintID: string;
implicitTxn: boolean;
sessionID: string;
databaseName: string;
username: string;
lastRetryReason?: string;
priority: string;
retries: number;
application: string;
};

export type Insight = {
name: InsightNameEnum;
label: string;
description: string;
tooltipDescription: string;
};

export type EventExecution = {
export type ContentionEvent = {
executionID: string;
fingerprintID: string;
queries: string[];
Expand All @@ -114,7 +170,7 @@ export type EventExecution = {
};

const highContentionInsight = (
execType: InsightExecEnum = InsightExecEnum.TRANSACTION,
execType: InsightExecEnum,
latencyThreshold?: number,
contentionDuration?: number,
): Insight => {
Expand Down Expand Up @@ -213,9 +269,7 @@ const failedExecutionInsight = (execType: InsightExecEnum): Insight => {
};
};

export const InsightTypes = [highContentionInsight]; // only used by getTransactionInsights to iterate over txn insights

export const getInsightFromProblem = (
export const getInsightFromCause = (
cause: string,
execOption: InsightExecEnum,
latencyThreshold?: number,
Expand Down Expand Up @@ -270,7 +324,7 @@ export interface InsightRecommendation {
database?: string;
query?: string;
indexDetails?: indexDetails;
execution?: executionDetails;
execution?: ExecutionDetails;
details?: insightDetails;
}

Expand All @@ -281,13 +335,17 @@ export interface indexDetails {
lastUsed?: string;
}

export interface executionDetails {
statement?: string;
summary?: string;
// These are the fields used for workload insight recommendations.
export interface ExecutionDetails {
databaseName?: string;
elapsedTimeMillis?: number;
contentionTime?: number;
fingerprintID?: string;
implicit?: boolean;
retries?: number;
indexRecommendations?: string[];
retries?: number;
statement?: string;
summary?: string;
}

export interface insightDetails {
Expand Down
Loading

0 comments on commit a2c3d54

Please sign in to comment.