-
Notifications
You must be signed in to change notification settings - Fork 4k
ui: encryption stats on stores report #26890
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
Merged
craig
merged 1 commit into
cockroachdb:master
from
mberhault:marc/file_stats_on_stores_report
Aug 9, 2018
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
102 changes: 95 additions & 7 deletions
102
pkg/ui/ccl/src/views/reports/containers/stores/encryption.tsx
This file contains hidden or 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,29 +1,117 @@ | ||
| import React from "react"; | ||
| import _ from "lodash"; | ||
| import Long from "long"; | ||
| import moment from "moment"; | ||
|
|
||
| import * as protos from "src/js/protos"; | ||
| import { EncryptionStatusProps } from "oss/src/views/reports/containers/stores/encryption"; | ||
| import { Bytes } from "src/util/format"; | ||
| import { FixLong } from "src/util/fixLong"; | ||
|
|
||
| export default class EncryptionStatus extends React.Component<EncryptionStatusProps, {}> { | ||
| const dateFormat = "Y-MM-DD HH:mm:ss"; | ||
|
|
||
| export default class EncryptionStatus { | ||
| props: EncryptionStatusProps; | ||
|
|
||
| constructor(props: EncryptionStatusProps) { | ||
| this.props = props; | ||
| } | ||
|
|
||
| renderHeaderRow(header: string) { | ||
| return ( | ||
| <tr className="stores-table__row"> | ||
| <td colSpan={2} className="stores-table__cell stores-table__cell--header--row">{header}</td> | ||
| </tr> | ||
| ); | ||
| } | ||
|
|
||
| renderSimpleRow(header: string, value: string) { | ||
| return ( | ||
| <tr className="stores-table__row"> | ||
| <th className="stores-table__cell stores-table__cell--header">{header}</th> | ||
| <td className="stores-table__cell" title={value}><pre>{value}</pre></td> | ||
| <td className="stores-table__cell" title={value}>{value}</td> | ||
| </tr> | ||
| ); | ||
| } | ||
|
|
||
| render(): React.ReactElement<any> { | ||
| renderStoreKey(key: protos.cockroach.ccl.storageccl.engineccl.enginepbccl.IKeyInfo) { | ||
| // Get the enum name from its value (eg: "AES128_CTR" for 1). | ||
| const encryptionType = protos.cockroach.ccl.storageccl.engineccl.enginepbccl.EncryptionType[key.encryption_type]; | ||
| const createdAt = moment.unix(FixLong(key.creation_time).toNumber()).utc().format(dateFormat); | ||
|
|
||
| return [ | ||
| this.renderHeaderRow("Active Store Key: user specified"), | ||
| this.renderSimpleRow("Algorithm", encryptionType), | ||
| this.renderSimpleRow("Key ID", key.key_id), | ||
| this.renderSimpleRow("Created", createdAt), | ||
| this.renderSimpleRow("Source", key.source), | ||
| ]; | ||
| } | ||
|
|
||
| renderDataKey(key: protos.cockroach.ccl.storageccl.engineccl.enginepbccl.IKeyInfo) { | ||
| // Get the enum name from its value (eg: "AES128_CTR" for 1). | ||
| const encryptionType = protos.cockroach.ccl.storageccl.engineccl.enginepbccl.EncryptionType[key.encryption_type]; | ||
| const createdAt = moment.unix(key.creation_time.toNumber()).utc().format(dateFormat); | ||
|
|
||
| return [ | ||
| this.renderHeaderRow("Active Data Key: automatically generated"), | ||
| this.renderSimpleRow("Algorithm", encryptionType), | ||
| this.renderSimpleRow("Key ID", key.key_id), | ||
| this.renderSimpleRow("Created", createdAt), | ||
| this.renderSimpleRow("Parent Key ID", key.parent_key_id), | ||
| ]; | ||
| } | ||
|
|
||
| calculatePercentage(active: Long, total: Long): number { | ||
| if (active.eq(total)) { | ||
| return 100; | ||
| } | ||
| return Long.fromInt(100).mul(active).toNumber() / total.toNumber(); | ||
| } | ||
|
|
||
| renderFileStats(stats: protos.cockroach.server.serverpb.IStoreDetails) { | ||
| const totalFiles = FixLong(stats.total_files); | ||
| const totalBytes = FixLong(stats.total_bytes); | ||
| if (totalFiles.eq(0) && totalBytes.eq(0)) { | ||
| return null; | ||
| } | ||
|
|
||
| const activeFiles = FixLong(stats.active_key_files); | ||
| const activeBytes = FixLong(stats.active_key_bytes); | ||
|
|
||
| let fileDetails = this.calculatePercentage(activeFiles, totalFiles).toFixed(2) + "%"; | ||
| fileDetails += " (" + activeFiles + "/" + totalFiles + ")"; | ||
|
|
||
| let byteDetails = this.calculatePercentage(activeBytes, totalBytes).toFixed(2) + "%"; | ||
| byteDetails += " (" + Bytes(activeBytes.toNumber()) + "/" + Bytes(totalBytes.toNumber()) + ")"; | ||
|
|
||
| return [ | ||
| this.renderHeaderRow("Encryption Progress: fraction encrypted using the active data key"), | ||
| this.renderSimpleRow("Files", fileDetails), | ||
| this.renderSimpleRow("Bytes", byteDetails), | ||
| ]; | ||
| } | ||
|
|
||
| getEncryptionRows() { | ||
| const { store } = this.props; | ||
| const rawStatus = store.encryption_status; | ||
| if (_.isEmpty(rawStatus)) { | ||
| return [ this.renderSimpleRow("Encryption status", "Not encrypted") ]; | ||
| } | ||
|
|
||
| let decodedStatus; | ||
|
|
||
| // Attempt to decode protobuf. | ||
| try { | ||
| const decodedStatus = protos.cockroach.ccl.storageccl.engineccl.enginepbccl.EncryptionStatus.decode(rawStatus); | ||
| return this.renderSimpleRow("Encryption Status", JSON.stringify(decodedStatus.toJSON(), null, 2)); | ||
| decodedStatus = protos.cockroach.ccl.storageccl.engineccl.enginepbccl.EncryptionStatus.decode(rawStatus); | ||
| } catch (e) { | ||
| console.log("Error decoding protobuf: ", e); | ||
| return null; | ||
| return [ this.renderSimpleRow("Encryption status", "Error decoding protobuf: " + e.toString()) ]; | ||
| } | ||
|
|
||
| return [ | ||
| this.renderStoreKey(decodedStatus.active_store_key), | ||
| this.renderDataKey(decodedStatus.active_data_key), | ||
| this.renderFileStats(store), | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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
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.
@BramGruneir is there a reason that all the debug reports have their styles in here, whereas top-level pages have their own style files?