Skip to content

Commit

Permalink
cluster-ui: update crdb-protobuf-client
Browse files Browse the repository at this point in the history
  • Loading branch information
asubiotto committed Feb 25, 2021
1 parent 9d18a57 commit 7dc8376
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 129 deletions.
2 changes: 1 addition & 1 deletion packages/cluster-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.13",
"@cockroachlabs/crdb-protobuf-client": "^0.0.6",
"@cockroachlabs/crdb-protobuf-client": "^0.0.7",
"@cockroachlabs/icons": "0.3.0",
"@cockroachlabs/ui-components": "0.2.14-alpha.0",
"@popperjs/core": "^2.4.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/cluster-ui/src/barCharts/barCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ const latencyBars = [
];

const maxMemUsageBars = [
bar("max-mem-usage", (d: StatementStatistics) => d.stats.max_mem_usage?.mean),
bar(
"max-mem-usage",
(d: StatementStatistics) => d.stats.exec_stats.max_mem_usage?.mean,
),
];

const networkBytesBars = [
bar(
"network-bytes",
(d: StatementStatistics) => d.stats.bytes_sent_over_network?.mean,
(d: StatementStatistics) => d.stats.exec_stats.network_bytes?.mean,
),
];

Expand All @@ -66,15 +69,12 @@ const latencyStdDev = bar(
const maxMemUsageStdDev = bar(
cx("max-mem-usage-dev"),
(d: StatementStatistics) =>
stdDevLong(d.stats.max_mem_usage, d.stats.exec_stat_collection_count),
stdDevLong(d.stats.exec_stats.max_mem_usage, d.stats.exec_stats.count),
);
const networkBytesStdDev = bar(
cx("network-bytes-dev"),
(d: StatementStatistics) =>
stdDevLong(
d.stats.bytes_sent_over_network,
d.stats.exec_stat_collection_count,
),
stdDevLong(d.stats.exec_stats.network_bytes, d.stats.exec_stats.count),
);

export const countBarChart = barChartFactory("grey", countBars, approximify);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,34 @@ import Long from "long";
import { createMemoryHistory } from "history";
import { noop } from "lodash";
import { StatementDetailsProps } from "./statementDetails";
import { ExecStats } from "../util";

const history = createMemoryHistory({ initialEntries: ["/statements"] });

const execStats: Required<ExecStats> = {
count: Long.fromNumber(1),
network_bytes: {
mean: 4160407,
squared_diffs: 47880000000000,
},
max_mem_usage: {
mean: 4160407,
squared_diffs: 47880000000000,
},
contention_time: {
mean: 4160407,
squared_diffs: 47880000000000,
},
network_messages: {
mean: 4160407,
squared_diffs: 47880000000000,
},
max_disk_usage: {
mean: 4160407,
squared_diffs: 47880000000000,
},
};

const statementStats: any = {
count: Long.fromNumber(36958),
first_attempt_count: Long.fromNumber(36958),
Expand Down Expand Up @@ -73,15 +98,7 @@ const statementStats: any = {
],
},
},
bytes_sent_over_network: {
mean: 4160407,
squared_diffs: 47880000000000,
},
max_mem_usage: {
mean: 4160407,
squared_diffs: 47880000000000,
},
exec_stat_collection_count: 1,
exec_stats: execStats,
};

export const getStatementDetailsPropsFixture = (): StatementDetailsProps => ({
Expand Down
10 changes: 5 additions & 5 deletions packages/cluster-ui/src/statementDetails/statementDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class StatementDetails extends React.Component<
<Text type="body-strong">Max memory usage</Text>
<Text>
{formatNumberForDisplay(
stats.max_mem_usage.mean,
stats.exec_stats.max_mem_usage.mean,
Bytes,
)}
</Text>
Expand All @@ -488,7 +488,7 @@ export class StatementDetails extends React.Component<
<Text type="body-strong">Network usage</Text>
<Text>
{formatNumberForDisplay(
stats.bytes_sent_over_network.mean,
stats.exec_stats.network_bytes.mean,
Bytes,
)}
</Text>
Expand Down Expand Up @@ -663,10 +663,10 @@ export class StatementDetails extends React.Component<
},
{
name: "Network Bytes Sent",
value: stats.bytes_sent_over_network,
value: stats.exec_stats.network_bytes,
bar: genericBarChart(
stats.bytes_sent_over_network,
stats.count,
stats.exec_stats.network_bytes,
stats.exec_stats.count,
Bytes,
),
format: Bytes,
Expand Down
55 changes: 37 additions & 18 deletions packages/cluster-ui/src/statementsPage/statementsPage.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,44 @@ import { RequestError } from "src/util";

type IStatementDiagnosticsReport = cockroach.server.serverpb.IStatementDiagnosticsReport;
type IStatementStatistics = protos.cockroach.sql.IStatementStatistics;
type IExecStats = protos.cockroach.sql.IExecStats;

const history = createMemoryHistory({ initialEntries: ["/statements"]});

const statementStats: IStatementStatistics = {
const execStats: Required<IExecStats> = {
"count": Long.fromNumber(180),
"network_bytes": {
"mean": 80,
"squared_diffs": 0.01,
},
"max_mem_usage": {
"mean": 80,
"squared_diffs": 0.01,
},
"contention_time": {
"mean": 80,
"squared_diffs": 0.01,
},
"network_messages": {
"mean": 80,
"squared_diffs": 0.01,
},
"max_disk_usage": {
"mean": 80,
"squared_diffs": 0.01,
},
};

const statementStats: Required<IStatementStatistics> = {
"count": Long.fromNumber(180000),
"first_attempt_count": Long.fromNumber(50000),
"max_retries": Long.fromNumber(10),
"num_rows": {
"mean": 1,
"squared_diffs": 0,
},
"legacy_last_err": "",
"legacy_last_err_redacted": "",
"parse_lat": {
"mean": 0,
"squared_diffs": 0,
Expand All @@ -40,6 +67,15 @@ const statementStats: IStatementStatistics = {
"mean": 0.00006233333333333315,
"squared_diffs": 5.786666666666667e-10,
},
"bytes_read": {
"mean": 80,
"squared_diffs": 0.01,
},
"rows_read": {
"mean": 10,
"squared_diffs": 1,
},
exec_stats: execStats,
"sensitive_info": {
"last_err": "",
"most_recent_plan_description": {
Expand Down Expand Up @@ -148,23 +184,6 @@ const statementStats: IStatementStatistics = {
],
},
},
"bytes_read": {
"mean": 80,
"squared_diffs": 0.01,
},
"rows_read": {
"mean": 10,
"squared_diffs": 1,
},
"bytes_sent_over_network": {
"mean": 80,
"squared_diffs": 0.01,
},
"max_mem_usage": {
"mean": 80,
"squared_diffs": 0.01,
},
"exec_stat_collection_count": Long.fromNumber(180),
};

const diagnosticsReports: IStatementDiagnosticsReport[] = [
Expand Down
4 changes: 2 additions & 2 deletions packages/cluster-ui/src/statementsTable/statementsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ function makeCommonColumns(
title: StatementTableTitle.maxMemUsage,
className: cx("statements-table__col-max-mem-usage"),
cell: maxMemUsageBar,
sort: stmt => FixLong(Number(stmt.stats.max_mem_usage.mean)),
sort: stmt => FixLong(Number(stmt.stats.exec_stats.max_mem_usage.mean)),
},
{
name: "networkBytes",
title: StatementTableTitle.networkBytes,
className: cx("statements-table__col-network-bytes"),
cell: networkBytesBar,
sort: stmt => FixLong(Number(stmt.stats.bytes_sent_over_network.mean)),
sort: stmt => FixLong(Number(stmt.stats.exec_stats.network_bytes.mean)),
},
{
name: "retries",
Expand Down
42 changes: 1 addition & 41 deletions packages/cluster-ui/src/transactionsPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SelectOptions } from "./filter";
import { AggregateStatistics } from "../statementsTable";
import Long from "long";
import _ from "lodash";
import { aggregateNumericStats, FixLong } from "../util";
import { addExecStats, aggregateNumericStats, FixLong } from "../util";

type Statement = protos.cockroach.server.serverpb.StatementsResponse.ICollectedStatementStatistics;
type TransactionStats = protos.cockroach.sql.ITransactionStatistics;
Expand Down Expand Up @@ -125,46 +125,6 @@ const withFingerprint = function(
};
};

function addExecStats(a: ExecStats, b: ExecStats): Required<ExecStats> {
let execStatCountA = FixLong(a.count).toInt();
const execStatCountB = FixLong(b.count).toInt();
if (execStatCountA === 0 && execStatCountB === 0) {
// If both counts are zero, artificially set the one count to one to avoid
// division by zero when calculating the mean in addNumericStats.
execStatCountA = 1;
}
return {
count: a.count.add(b.count),
network_bytes:
a.network_bytes && b.network_bytes
? aggregateNumericStats(
a.network_bytes,
b.network_bytes,
execStatCountA,
execStatCountB,
)
: null,
max_mem_usage:
a.max_mem_usage && b.max_mem_usage
? aggregateNumericStats(
a.max_mem_usage,
b.max_mem_usage,
execStatCountA,
execStatCountB,
)
: null,
contention_time:
a.contention_time && b.contention_time
? aggregateNumericStats(
a.contention_time,
b.contention_time,
execStatCountA,
execStatCountB,
)
: null,
};
}

// addTransactionStats adds together two stat objects into one using their counts to compute a new
// average for the numeric statistics. It's modeled after the similar `addStatementStats` function
function addTransactionStats(
Expand Down
18 changes: 13 additions & 5 deletions packages/cluster-ui/src/util/appStats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NumericStat,
flattenStatementStats,
StatementStatistics,
ExecStats,
combineStatementStats,
} from "./appStats";
import IExplainTreePlanNode = protos.cockroach.sql.IExplainTreePlanNode;
Expand Down Expand Up @@ -159,14 +160,24 @@ function randomStat(scale = 1): NumericStat {
};
}

function randomExecStats(count = 10): Required<ExecStats> {
return {
count: Long.fromNumber(randomInt(count)),
network_bytes: randomStat(),
max_mem_usage: randomStat(),
contention_time: randomStat(),
network_messages: randomStat(),
max_disk_usage: randomStat(),
};
}

function randomStats(
sensitiveInfo?: ISensitiveInfo,
): Required<StatementStatistics> {
const count = randomInt(1000);
// tslint:disable:variable-name
const first_attempt_count = randomInt(count);
const max_retries = randomInt(count - first_attempt_count);
const exec_stat_collection_count = randomInt(count);
// tslint:enable:variable-name

return {
Expand All @@ -184,10 +195,7 @@ function randomStats(
sensitive_info: sensitiveInfo || makeSensitiveInfo(null, null),
legacy_last_err: "",
legacy_last_err_redacted: "",
bytes_sent_over_network: randomStat(),
max_mem_usage: randomStat(),
exec_stat_collection_count: Long.fromNumber(exec_stat_collection_count),
contention_time: randomStat(),
exec_stats: randomExecStats(count),
};
}

Expand Down
Loading

0 comments on commit 7dc8376

Please sign in to comment.