-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
db-console: statement details component #162
Merged
koorosh
merged 1 commit into
cockroachdb:master
from
koorosh:db-console--statement-details-extraction
Jan 13, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
101 changes: 101 additions & 0 deletions
101
packages/admin-ui-components/src/barCharts/genericBarChart.tsx
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,101 @@ | ||
import React from "react"; | ||
import classNames from "classnames/bind"; | ||
import { scaleLinear } from "d3-scale"; | ||
import { format as d3Format } from "d3-format"; | ||
|
||
import { stdDevLong } from "src/util/appStats"; | ||
import { Tooltip } from "src/tooltip"; | ||
import { NumericStat } from "../util"; | ||
import { clamp, longToInt, normalizeClosedDomain } from "./utils"; | ||
import styles from "./barCharts.module.scss"; | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
function renderNumericStatLegend( | ||
count: number | Long, | ||
stat: number, | ||
sd: number, | ||
formatter: (d: number) => string, | ||
) { | ||
return ( | ||
<table className={cx("numeric-stat-legend")}> | ||
<tbody> | ||
<tr> | ||
<th> | ||
<div | ||
className={cx( | ||
"numeric-stat-legend__bar", | ||
"numeric-stat-legend__bar--mean", | ||
)} | ||
/> | ||
Mean | ||
</th> | ||
<td>{formatter(stat)}</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
<div | ||
className={cx( | ||
"numeric-stat-legend__bar", | ||
"numeric-stat-legend__bar--dev", | ||
)} | ||
/> | ||
Standard Deviation | ||
</th> | ||
<td>{longToInt(count) < 2 ? "-" : sd ? formatter(sd) : "0"}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
|
||
export function genericBarChart( | ||
s: NumericStat, | ||
count: number | Long, | ||
format?: (v: number) => string, | ||
) { | ||
if (!s) { | ||
return () => <div />; | ||
} | ||
const mean = s.mean; | ||
const sd = stdDevLong(s, count); | ||
|
||
const max = mean + sd; | ||
const scale = scaleLinear() | ||
.domain(normalizeClosedDomain([0, max])) | ||
.range([0, 100]); | ||
if (!format) { | ||
format = d3Format(".2f"); | ||
} | ||
return function MakeGenericBarChart() { | ||
const width = scale(clamp(mean - sd)); | ||
const right = scale(mean); | ||
const spread = scale(sd + (sd > mean ? mean : sd)); | ||
const title = renderNumericStatLegend(count, mean, sd, format); | ||
return ( | ||
<Tooltip text={title} short> | ||
<div className={cx("bar-chart", "bar-chart--breakdown")}> | ||
<div className={cx("bar-chart__label")}>{format(mean)}</div> | ||
<div className={cx("bar-chart__multiplebars")}> | ||
<div | ||
className={cx("bar-chart__parse", "bar-chart__bar")} | ||
style={{ width: right + "%", position: "absolute", left: 0 }} | ||
/> | ||
<div | ||
className={cx( | ||
"bar-chart__parse-dev", | ||
"bar-chart__bar", | ||
"bar-chart__bar--dev", | ||
)} | ||
style={{ | ||
width: spread + "%", | ||
position: "absolute", | ||
left: width + "%", | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</Tooltip> | ||
); | ||
}; | ||
} |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from "./barCharts"; | ||
export * from "./rowsBreakdown"; | ||
export * from "./utils"; | ||
export * from "./latencyBreakdown"; | ||
export * from "./genericBarChart"; |
File renamed without changes.
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
87 changes: 87 additions & 0 deletions
87
packages/admin-ui-components/src/downloadFile/downloadFile.tsx
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,87 @@ | ||
// Copyright 2020 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 React, { | ||
useRef, | ||
useEffect, | ||
forwardRef, | ||
useImperativeHandle, | ||
} from "react"; | ||
|
||
type FileTypes = "text/plain" | "application/json"; | ||
|
||
export interface DownloadAsFileProps { | ||
fileName?: string; | ||
fileType?: FileTypes; | ||
content?: string; | ||
} | ||
|
||
export interface DownloadFileRef { | ||
download: (name: string, type: FileTypes, body: string) => void; | ||
} | ||
|
||
/* | ||
* DownloadFile can download file in two modes `default` and `imperative`. | ||
* `Default` mode - when DownloadFile wraps component which should trigger | ||
* downloading and can work only if content of file is already available. | ||
* | ||
* For example: | ||
* ``` | ||
* <DownloadFile fileName="example.txt" fileType="text/plain" content="Some text"> | ||
* <button>Download</download> | ||
* </DownloadFile> | ||
* ``` | ||
* | ||
* `Imperative` mode allows initiate file download in async way, and trigger | ||
* download manually. | ||
* | ||
* For example: | ||
* ``` | ||
* downloadRef = React.createRef<DownloadFileRef>(); | ||
* | ||
* fetchData = () => { | ||
* Promise.resolve().then((someText) => | ||
* this.downloadRef.current.download("example.txt", "text/plain", someText)) | ||
* } | ||
* | ||
* <DownloadFile ref={downloadRef} /> | ||
* <button onClick={fetchData}>Download</button> | ||
* ``` | ||
* */ | ||
// tslint:disable-next-line:variable-name | ||
export const DownloadFile = forwardRef<DownloadFileRef, DownloadAsFileProps>( | ||
(props, ref) => { | ||
const { children, fileName, fileType, content } = props; | ||
const anchorRef = useRef<HTMLAnchorElement>(); | ||
|
||
const bootstrapFile = (name: string, type: FileTypes, body: string) => { | ||
const anchorElement = anchorRef.current; | ||
const file = new Blob([body], { type }); | ||
anchorElement.href = URL.createObjectURL(file); | ||
anchorElement.download = name; | ||
}; | ||
|
||
useEffect(() => { | ||
if (content === undefined) { | ||
return; | ||
} | ||
bootstrapFile(fileName, fileType, content); | ||
}, [fileName, fileType, content]); | ||
|
||
useImperativeHandle(ref, () => ({ | ||
download: (name: string, type: FileTypes, body: string) => { | ||
bootstrapFile(name, type, body); | ||
anchorRef.current.click(); | ||
}, | ||
})); | ||
|
||
return <a ref={anchorRef}>{children}</a>; | ||
}, | ||
); |
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,11 @@ | ||
// Copyright 2020 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. | ||
|
||
export * from "./downloadFile"; |
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,8 @@ | ||
import moment from "moment"; | ||
|
||
export interface Identity { | ||
nodeID: number; | ||
address: string; | ||
locality?: string; | ||
updatedAt: moment.Moment; | ||
} |
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 @@ | ||
export * from "./identity"; |
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,32 @@ | ||
import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; | ||
import { NoConnection } from "./noConnection"; | ||
|
||
type INodeStatus = cockroach.server.status.statuspb.INodeStatus; | ||
|
||
const LivenessStatus = | ||
cockroach.kv.kvserver.liveness.livenesspb.NodeLivenessStatus; | ||
|
||
function isNoConnection( | ||
node: INodeStatus | NoConnection, | ||
): node is NoConnection { | ||
return ( | ||
(node as NoConnection).to !== undefined && | ||
(node as NoConnection).from !== undefined | ||
); | ||
} | ||
|
||
export function getDisplayName( | ||
node: INodeStatus | NoConnection, | ||
livenessStatus = LivenessStatus.NODE_STATUS_LIVE, | ||
) { | ||
const decommissionedString = | ||
livenessStatus === LivenessStatus.NODE_STATUS_DECOMMISSIONED | ||
? "[decommissioned] " | ||
: ""; | ||
|
||
if (isNoConnection(node)) { | ||
return `${decommissionedString}(n${node.from.nodeID})`; | ||
} | ||
// as the only other type possible right now is INodeStatus we don't have a type guard for that | ||
return `${decommissionedString}(n${node.desc.node_id}) ${node.desc.address.address_field}`; | ||
} |
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,4 @@ | ||
export * from "./getDisplayName"; | ||
export * from "./noConnection"; | ||
export * from "./nodeCapacityStats"; | ||
export * from "./nodeSummaryStats"; |
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,6 @@ | ||
import { Identity } from "../network"; | ||
|
||
export interface NoConnection { | ||
from: Identity; | ||
to: Identity; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/admin-ui-components/src/nodes/nodeCapacityStats.ts
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,20 @@ | ||
import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; | ||
import { MetricConstants } from "../util/proto"; | ||
|
||
type INodeStatus = cockroach.server.status.statuspb.INodeStatus; | ||
|
||
export interface CapacityStats { | ||
used: number; | ||
usable: number; | ||
available: number; | ||
} | ||
|
||
export function nodeCapacityStats(n: INodeStatus): CapacityStats { | ||
const used = n.metrics[MetricConstants.usedCapacity]; | ||
const available = n.metrics[MetricConstants.availableCapacity]; | ||
return { | ||
used, | ||
available, | ||
usable: used + available, | ||
}; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/admin-ui-components/src/nodes/nodeSummaryStats.ts
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,19 @@ | ||
export type NodeSummaryStats = { | ||
nodeCounts: { | ||
total: number; | ||
healthy: number; | ||
suspect: number; | ||
dead: number; | ||
decommissioned: number; | ||
}; | ||
capacityUsed: number; | ||
capacityAvailable: number; | ||
capacityTotal: number; | ||
capacityUsable: number; | ||
usedBytes: number; | ||
usedMem: number; | ||
totalRanges: number; | ||
underReplicatedRanges: number; | ||
unavailableRanges: number; | ||
replicas: number; | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fixes React error about missing
key
attribute for array of elements.React.Children.toArray
accepts an array of react elements and allows to set automaticallykey
attribute if it's missed.