forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the v1 Insights page to the DB Console, via the cluster-ui package. The v1 Insights page only includes a Transactions Insights overview page, populated with information served a new "endpoint" built on top of the SQL-over-HTTP API. Note this PR is dependent on the changes in cockroachdb#84617 and xinhaoz/cockroach@c069738.. Release note (ui change): Added new Insights page to DB Console
- Loading branch information
1 parent
f650c14
commit d202d7b
Showing
40 changed files
with
1,702 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { | ||
executeSql, | ||
SqlExecutionRequest, | ||
SqlExecutionResponse, | ||
} from "./sqlApi"; | ||
import { InsightEvent, InsightExecEnum, InsightNameEnum } from "src/insights"; | ||
import moment from "moment"; | ||
|
||
export type InsightEventState = Omit<InsightEvent, "insights"> & { | ||
insightName: string; | ||
}; | ||
|
||
export type InsightEventsResponse = InsightEventState[]; | ||
|
||
type InsightQuery<ResponseColumnType> = { | ||
name: InsightNameEnum; | ||
query: string; | ||
toState: ( | ||
response: SqlExecutionResponse<ResponseColumnType>, | ||
results: Record<string, InsightEventState>, | ||
) => InsightEventState[]; | ||
}; | ||
|
||
export const HIGH_WAIT_CONTENTION_THRESHOLD = moment.duration( | ||
2, | ||
"milliseconds", | ||
); | ||
|
||
type TransactionContentionResponseColumns = { | ||
blocking_txn_id: string; | ||
blocking_queries: string[]; | ||
collection_ts: string; | ||
contention_duration: string; | ||
app_name: string; | ||
}; | ||
|
||
function transactionContentionResultsToEventState( | ||
response: SqlExecutionResponse<TransactionContentionResponseColumns>, | ||
results: Record<string, InsightEventState>, | ||
): InsightEventState[] { | ||
response.execution.txn_results[0].rows.forEach(row => { | ||
const key = row.blocking_txn_id; | ||
if (!results[key]) { | ||
results[key] = { | ||
executionID: row.blocking_txn_id, | ||
queries: row.blocking_queries, | ||
startTime: moment(row.collection_ts), | ||
elapsedTime: moment.duration(row.contention_duration).asMilliseconds(), | ||
application: row.app_name, | ||
insightName: highWaitTimeQuery.name, | ||
execType: InsightExecEnum.TRANSACTION, | ||
}; | ||
} | ||
}); | ||
|
||
return Object.values(results); | ||
} | ||
|
||
const highWaitTimeQuery: InsightQuery<TransactionContentionResponseColumns> = { | ||
name: InsightNameEnum.highWaitTime, | ||
query: `SELECT | ||
blocking_txn_id, | ||
blocking_queries, | ||
collection_ts, | ||
contention_duration, | ||
app_name | ||
FROM | ||
( | ||
SELECT | ||
blocking_txn_id, | ||
blocking_txn_fingerprint_id, | ||
collection_ts, | ||
contention_duration | ||
FROM | ||
crdb_internal.transaction_contention_events | ||
WHERE | ||
contention_duration > INTERVAL '${HIGH_WAIT_CONTENTION_THRESHOLD.toISOString()}' | ||
) AS tce | ||
JOIN ( | ||
SELECT | ||
transaction_fingerprint_id, | ||
app_name, | ||
array_agg(metadata ->> 'query') AS blocking_queries | ||
FROM | ||
crdb_internal.statement_statistics | ||
GROUP BY | ||
transaction_fingerprint_id, | ||
app_name | ||
) AS bqs ON bqs.transaction_fingerprint_id = tce.blocking_txn_fingerprint_id`, | ||
toState: transactionContentionResultsToEventState, | ||
}; | ||
|
||
// getInsightEventState is currently hardcoded to use a single insight type and execution event type | ||
export function getInsightEventState(): Promise<InsightEventsResponse> { | ||
const request: SqlExecutionRequest = { | ||
statements: [ | ||
{ | ||
sql: `${highWaitTimeQuery.query}`, | ||
}, | ||
], | ||
execute: true, | ||
}; | ||
return executeSql<TransactionContentionResponseColumns>(request).then( | ||
result => { | ||
if (!result.execution.txn_results[0].rows) { | ||
// No data. | ||
return []; | ||
} | ||
|
||
const results: Record<string, InsightEventState> = {}; | ||
return highWaitTimeQuery.toState(result, results); | ||
}, | ||
); | ||
} |
Oops, something went wrong.