-
Notifications
You must be signed in to change notification settings - Fork 26
/
statementsTable.tsx
264 lines (250 loc) · 8.21 KB
/
statementsTable.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import React from "react";
import classNames from "classnames/bind";
import Long from "long";
import { FixLong, StatementSummary, StatementStatistics } from "src/util";
import {
countBarChart,
rowsReadBarChart,
bytesReadBarChart,
latencyBarChart,
contentionBarChart,
maxMemUsageBarChart,
networkBytesBarChart,
retryBarChart,
workloadPctBarChart,
} from "src/barCharts";
import { ActivateDiagnosticsModalRef } from "src/statementsDiagnostics";
import { ColumnDescriptor, SortedTable } from "src/sortedtable";
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import {
StatementTableTitle,
StatementTableCell,
NodeNames,
} from "./statementsTableContent";
type IStatementDiagnosticsReport = cockroach.server.serverpb.IStatementDiagnosticsReport;
type ICollectedStatementStatistics = cockroach.server.serverpb.StatementsResponse.ICollectedStatementStatistics;
import styles from "./statementsTable.module.scss";
const cx = classNames.bind(styles);
const longToInt = (d: number | Long) => Number(FixLong(d));
function makeCommonColumns(
statements: AggregateStatistics[],
totalWorkload: number,
displayColumns?: string,
): ColumnDescriptor<AggregateStatistics>[] {
const defaultBarChartOptions = {
classes: {
root: cx("statements-table__col--bar-chart"),
label: cx("statements-table__col--bar-chart__label"),
},
};
const sampledExecStatsBarChartOptions = {
classes: defaultBarChartOptions.classes,
displayNoSamples: (d: ICollectedStatementStatistics) => {
return longToInt(d.stats.exec_stats?.count) == 0;
},
};
const countBar = countBarChart(statements, defaultBarChartOptions);
const rowsReadBar = rowsReadBarChart(statements, defaultBarChartOptions);
const bytesReadBar = bytesReadBarChart(statements, defaultBarChartOptions);
const latencyBar = latencyBarChart(statements, defaultBarChartOptions);
const contentionBar = contentionBarChart(
statements,
sampledExecStatsBarChartOptions,
);
const maxMemUsageBar = maxMemUsageBarChart(
statements,
sampledExecStatsBarChartOptions,
);
const networkBytesBar = networkBytesBarChart(
statements,
sampledExecStatsBarChartOptions,
);
const retryBar = retryBarChart(statements, defaultBarChartOptions);
// If adding new columns, also add it to src/statementsPage/statementsPage.tsx
// and if the column should be hidden by default add it to ignoreColumnsOnDefault
// on that same file.
const columns = [
{
name: "executionCount",
title: StatementTableTitle.executionCount,
className: cx("statements-table__col-count"),
cell: countBar,
sort: (stmt: AggregateStatistics) => FixLong(Number(stmt.stats.count)),
},
{
name: "database",
title: StatementTableTitle.database,
className: cx("statements-table__col-database"),
cell: (stmt: AggregateStatistics) => stmt.database,
sort: (stmt: AggregateStatistics) => FixLong(Number(stmt.database)),
},
{
name: "rowsRead",
title: StatementTableTitle.rowsRead,
className: cx("statements-table__col-rows-read"),
cell: rowsReadBar,
sort: (stmt: AggregateStatistics) =>
FixLong(Number(stmt.stats.rows_read.mean)),
},
{
name: "bytesRead",
title: StatementTableTitle.bytesRead,
cell: bytesReadBar,
sort: (stmt: AggregateStatistics) =>
FixLong(Number(stmt.stats.bytes_read.mean)),
},
{
name: "latency",
title: StatementTableTitle.statementTime,
className: cx("statements-table__col-latency"),
cell: latencyBar,
sort: (stmt: AggregateStatistics) => stmt.stats.service_lat.mean,
},
{
name: "contention",
title: StatementTableTitle.contention,
cell: contentionBar,
sort: (stmt: AggregateStatistics) =>
FixLong(Number(stmt.stats.exec_stats.contention_time.mean)),
},
{
name: "maxMemoryUsage",
title: StatementTableTitle.maxMemUsage,
cell: maxMemUsageBar,
sort: (stmt: AggregateStatistics) =>
FixLong(Number(stmt.stats.exec_stats.max_mem_usage.mean)),
},
{
name: "networkBytes",
title: StatementTableTitle.networkBytes,
cell: networkBytesBar,
sort: (stmt: AggregateStatistics) =>
FixLong(Number(stmt.stats.exec_stats.network_bytes.mean)),
},
{
name: "retries",
title: StatementTableTitle.retries,
className: cx("statements-table__col-retries"),
cell: retryBar,
sort: (stmt: AggregateStatistics) =>
longToInt(stmt.stats.count) - longToInt(stmt.stats.first_attempt_count),
},
{
name: "workloadPct",
title: StatementTableTitle.workloadPct,
cell: workloadPctBarChart(
statements,
defaultBarChartOptions,
totalWorkload,
),
sort: (stmt: AggregateStatistics) =>
(stmt.stats.service_lat.mean * longToInt(stmt.stats.count)) /
totalWorkload,
},
];
if (
displayColumns == undefined ||
displayColumns == "" ||
displayColumns == "default"
)
return columns;
return columns.filter(option => {
return displayColumns.split(",").includes(option.name);
});
}
export interface AggregateStatistics {
// label is either shortStatement (StatementsPage) or nodeId (StatementDetails).
label: string;
implicitTxn: boolean;
fullScan: boolean;
database: string;
stats: StatementStatistics;
drawer?: boolean;
firstCellBordered?: boolean;
diagnosticsReports?: cockroach.server.serverpb.IStatementDiagnosticsReport[];
// totalWorkload is the sum of service latency of all statements listed on the table.
totalWorkload?: Long;
}
export class StatementsSortedTable extends SortedTable<AggregateStatistics> {}
export function shortStatement(summary: StatementSummary, original: string) {
switch (summary.statement) {
case "update":
return "UPDATE " + summary.table;
case "insert":
return "INSERT INTO " + summary.table;
case "select":
return "SELECT FROM " + summary.table;
case "delete":
return "DELETE FROM " + summary.table;
case "create":
return "CREATE TABLE " + summary.table;
case "set":
return "SET " + summary.table;
default:
return original;
}
}
export function makeStatementsColumns(
statements: AggregateStatistics[],
selectedApp: string,
// totalWorkload is the sum of service latency of all statements listed on the table.
totalWorkload: number,
displayColumns?: string,
search?: string,
activateDiagnosticsRef?: React.RefObject<ActivateDiagnosticsModalRef>,
onDiagnosticsDownload?: (report: IStatementDiagnosticsReport) => void,
onStatementClick?: (statement: string) => void,
): ColumnDescriptor<AggregateStatistics>[] {
const columns: ColumnDescriptor<AggregateStatistics>[] = [
{
name: "statements",
title: StatementTableTitle.statements,
className: cx("cl-table__col-query-text"),
cell: StatementTableCell.statements(
search,
selectedApp,
onStatementClick,
),
sort: stmt => stmt.label,
},
];
columns.push(...makeCommonColumns(statements, totalWorkload, displayColumns));
if (activateDiagnosticsRef) {
const diagnosticsColumn: ColumnDescriptor<AggregateStatistics> = {
name: "diagnostics",
title: StatementTableTitle.diagnostics,
cell: StatementTableCell.diagnostics(
activateDiagnosticsRef,
onDiagnosticsDownload,
),
sort: stmt => {
if (stmt.diagnosticsReports?.length > 0) {
// Perform sorting by first diagnostics report as only
// this one can be either in ready or waiting status.
return stmt.diagnosticsReports[0].completed ? "READY" : "WAITING";
}
return null;
},
titleAlign: "right",
};
columns.push(diagnosticsColumn);
}
return columns;
}
export function makeNodesColumns(
statements: AggregateStatistics[],
nodeNames: NodeNames,
totalWorkload: number,
displayColumns?: string,
): ColumnDescriptor<AggregateStatistics>[] {
const original: ColumnDescriptor<AggregateStatistics>[] = [
{
name: "nodes",
title: null,
cell: StatementTableCell.nodeLink(nodeNames),
},
];
return original.concat(
makeCommonColumns(statements, totalWorkload, displayColumns),
);
}