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 cf53c67
Showing
38 changed files
with
1,542 additions
and
10 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,82 @@ | ||
// 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 } from "./sqlApi"; | ||
import { InsightExecEnum, TransactionInsight } from "../insights"; | ||
import moment from "moment"; | ||
|
||
// TO-DO: Add StatementInsight API | ||
|
||
export type TransactionInsightState = Omit<TransactionInsight, "insights">; | ||
|
||
type TransactionInsightResponseColumns = { | ||
blocking_txn_id: string; | ||
blocking_queries: string; | ||
collection_ts: string; | ||
contention_duration: string; | ||
app_name: string; | ||
}; | ||
|
||
export type TransactionInsightsResponse = TransactionInsightState[]; | ||
|
||
export function getTransactionInsightState(): Promise<TransactionInsightsResponse> { | ||
const request: SqlExecutionRequest = { | ||
statements: [ | ||
{ | ||
sql: `SELECT | ||
blocking_txn_id, | ||
blocking_queries, | ||
collection_ts, | ||
contention_duration, | ||
app_name | ||
FROM | ||
crdb_internal.transaction_contention_events 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 | ||
`, | ||
}, | ||
], | ||
execute: true, | ||
}; | ||
return executeSql<TransactionInsightResponseColumns>(request).then(result => { | ||
if (!result.execution.txn_results[0].rows) { | ||
// No data. | ||
return []; | ||
} | ||
|
||
const contentionEvents: Record<string, TransactionInsightState> = {}; | ||
result.execution.txn_results[0].rows.forEach(row => { | ||
const key = row.blocking_txn_id; | ||
if (!contentionEvents[key]) { | ||
contentionEvents[key] = { | ||
executionID: row.blocking_txn_id, | ||
query: row.blocking_queries, | ||
startTime: moment(row.collection_ts), | ||
elapsedTime: moment | ||
.duration(row.contention_duration) | ||
.asMilliseconds(), | ||
application: row.app_name, | ||
execType: InsightExecEnum.TRANSACTION, | ||
}; | ||
} | ||
}); | ||
|
||
return Object.values(contentionEvents); | ||
}); | ||
} |
Oops, something went wrong.