@@ -6,8 +6,9 @@ import Long from "long";
66import moment from "moment" ;
77import { EncryptionStatusProps } from "oss/src/views/reports/containers/stores/encryption" ;
88import { Bytes } from "src/util/format" ;
9+ import { FixLong } from "src/util/fixLong" ;
910
10- const dateFormat = "Y-MM-DD HH:mm:ss Z " ;
11+ const dateFormat = "Y-MM-DD HH:mm:ss" ;
1112
1213export default class EncryptionStatus extends React . Component < EncryptionStatusProps , { } > {
1314
@@ -23,53 +24,61 @@ export default class EncryptionStatus extends React.Component<EncryptionStatusPr
2324 return (
2425 < tr className = "stores-table__row" >
2526 < th className = "stores-table__cell stores-table__cell--header" > { header } </ th >
26- < td className = "stores-table__cell" title = { value } > < pre > { value } </ pre > </ td >
27+ < td className = "stores-table__cell" title = { value } > { value } </ td >
2728 </ tr >
2829 ) ;
2930 }
3031
31- renderKey ( isStoreKey : boolean , key : protos . cockroach . ccl . storageccl . engineccl . enginepbccl . KeyInfo$Properties ) {
32+ renderStoreKey ( key : protos . cockroach . ccl . storageccl . engineccl . enginepbccl . KeyInfo$Properties ) {
3233 // Get the enum name from its value (eg: "AES128_CTR" for 1).
3334 const encryptionType = protos . cockroach . ccl . storageccl . engineccl . enginepbccl . EncryptionType [ key . encryption_type ] ;
3435 const createdAt = moment . unix ( key . creation_time . toNumber ( ) ) . utc ( ) . format ( dateFormat ) ;
3536
36- if ( isStoreKey ) {
37- return [
38- this . renderHeaderRow ( "Active Store Key: user specified" ) ,
39- this . renderSimpleRow ( "Algorithm" , encryptionType ) ,
40- this . renderSimpleRow ( "Key ID" , key . key_id ) ,
41- this . renderSimpleRow ( "Created" , createdAt ) ,
42- this . renderSimpleRow ( "Source" , key . source ) ,
43- ] ;
44- } else {
45- return [
46- this . renderHeaderRow ( "Active Data Key: automatically generated" ) ,
47- this . renderSimpleRow ( "Algorithm" , encryptionType ) ,
48- this . renderSimpleRow ( "Key ID" , key . key_id ) ,
49- this . renderSimpleRow ( "Created" , createdAt ) ,
50- this . renderSimpleRow ( "Parent Key ID" , key . parent_key_id ) ,
51- ] ;
37+ return [
38+ this . renderHeaderRow ( "Active Store Key: user specified" ) ,
39+ this . renderSimpleRow ( "Algorithm" , encryptionType ) ,
40+ this . renderSimpleRow ( "Key ID" , key . key_id ) ,
41+ this . renderSimpleRow ( "Created" , createdAt ) ,
42+ this . renderSimpleRow ( "Source" , key . source ) ,
43+ ] ;
44+ }
45+
46+ renderDataKey ( key : protos . cockroach . ccl . storageccl . engineccl . enginepbccl . KeyInfo$Properties ) {
47+ // Get the enum name from its value (eg: "AES128_CTR" for 1).
48+ const encryptionType = protos . cockroach . ccl . storageccl . engineccl . enginepbccl . EncryptionType [ key . encryption_type ] ;
49+ const createdAt = moment . unix ( key . creation_time . toNumber ( ) ) . utc ( ) . format ( dateFormat ) ;
50+
51+ return [
52+ this . renderHeaderRow ( "Active Data Key: automatically generated" ) ,
53+ this . renderSimpleRow ( "Algorithm" , encryptionType ) ,
54+ this . renderSimpleRow ( "Key ID" , key . key_id ) ,
55+ this . renderSimpleRow ( "Created" , createdAt ) ,
56+ this . renderSimpleRow ( "Parent Key ID" , key . parent_key_id ) ,
57+ ] ;
58+ }
59+
60+ calculatePercentage ( active : Long , total : Long ) : number {
61+ if ( active === total ) {
62+ return 100 ;
5263 }
64+ return Long . fromInt ( 100 ) . mul ( active ) . toNumber ( ) / total . toNumber ( ) ;
5365 }
5466
5567 renderFileStats ( stats : protos . cockroach . server . serverpb . StoreDetails$Properties ) {
56- if ( stats . total_files . eq ( 0 ) && stats . total_bytes . eq ( 0 ) ) {
68+ let total_files = FixLong ( stats . total_files ) ;
69+ let total_bytes = FixLong ( stats . total_bytes ) ;
70+ if ( total_files . eq ( 0 ) && total_bytes . eq ( 0 ) ) {
5771 return null ;
5872 }
5973
60- let percentFiles = 100 ;
61- if ( stats . active_key_files !== stats . total_files ) {
62- percentFiles = Long . fromInt ( 100 ) . mul ( stats . active_key_files ) . toNumber ( ) / stats . total_files . toNumber ( ) ;
63- }
64- let fileDetails = percentFiles . toFixed ( 2 ) + "%" ;
65- fileDetails += " (" + stats . active_key_files + "/" + stats . total_files + ")" ;
74+ let active_files = FixLong ( stats . active_key_files ) ;
75+ let active_bytes = FixLong ( stats . active_key_bytes ) ;
6676
67- let percentBytes = 100 ;
68- if ( stats . active_key_bytes !== stats . total_bytes ) {
69- percentBytes = Long . fromInt ( 100 ) . mul ( stats . active_key_bytes ) . toNumber ( ) / stats . total_bytes . toNumber ( ) ;
70- }
71- let byteDetails = percentBytes . toFixed ( 2 ) + "%" ;
72- byteDetails += " (" + Bytes ( stats . active_key_bytes . toNumber ( ) ) + "/" + Bytes ( stats . total_bytes . toNumber ( ) ) + ")" ;
77+ let fileDetails = this . calculatePercentage ( active_files , total_files ) . toFixed ( 2 ) + "%" ;
78+ fileDetails += " (" + active_files + "/" + total_files + ")" ;
79+
80+ let byteDetails = this . calculatePercentage ( active_bytes , total_bytes ) . toFixed ( 2 ) + "%" ;
81+ byteDetails += " (" + Bytes ( active_bytes . toNumber ( ) ) + "/" + Bytes ( total_bytes . toNumber ( ) ) + ")" ;
7382
7483 return [
7584 this . renderHeaderRow ( "Encryption Progress: fraction encrypted using the active data key" ) ,
@@ -78,26 +87,34 @@ export default class EncryptionStatus extends React.Component<EncryptionStatusPr
7887 ] ;
7988 }
8089
90+ decodeEncryptionStatus ( data : Uint8Array ) : protos . cockroach . ccl . storageccl . engineccl . enginepbccl . EncryptionStatus {
91+ let decodedStatus ;
92+
93+ // Attempt to decode protobuf.
94+ try {
95+ decodedStatus = protos . cockroach . ccl . storageccl . engineccl . enginepbccl . EncryptionStatus . decode ( data ) ;
96+ } catch ( e ) {
97+ console . log ( "Error decoding protobuf: " , e ) ;
98+ return null ;
99+ }
100+ return decodedStatus ;
101+ }
102+
81103 render ( ) {
82104 const { store } = this . props ;
83105 const rawStatus = store . encryption_status ;
84106 if ( _ . isEmpty ( rawStatus ) ) {
85107 return null ;
86108 }
87109
88- let decodedStatus ;
89-
90- // Attempt to decode protobuf.
91- try {
92- decodedStatus = protos . cockroach . ccl . storageccl . engineccl . enginepbccl . EncryptionStatus . decode ( rawStatus ) ;
93- } catch ( e ) {
94- console . log ( "Error decoding protobuf: " , e ) ;
110+ let decodedStatus = this . decodeEncryptionStatus ( rawStatus ) ;
111+ if ( decodedStatus == null ) {
95112 return null ;
96113 }
97114
98115 return [
99- this . renderKey ( true , decodedStatus . active_store_key ) ,
100- this . renderKey ( false , decodedStatus . active_data_key ) ,
116+ this . renderStoreKey ( decodedStatus . active_store_key ) ,
117+ this . renderDataKey ( decodedStatus . active_data_key ) ,
101118 this . renderFileStats ( store ) ,
102119 ] ;
103120 }
0 commit comments