diff --git a/pinot-controller/src/main/resources/app/pages/TenantDetails.tsx b/pinot-controller/src/main/resources/app/pages/TenantDetails.tsx index 8b8ed7f76e8f..f4b80a3e0bea 100644 --- a/pinot-controller/src/main/resources/app/pages/TenantDetails.tsx +++ b/pinot-controller/src/main/resources/app/pages/TenantDetails.tsx @@ -468,14 +468,14 @@ const TenantPageDetails = ({ match }: RouteComponentProps) => { - Reported Size: {tableSummary.reportedSize} + Reported Size: {Utils.formatBytes(tableSummary.reportedSize)} Estimated Size: - {tableSummary.estimatedSize} + {Utils.formatBytes(tableSummary.estimatedSize)} diff --git a/pinot-controller/src/main/resources/app/utils/PinotMethodUtils.ts b/pinot-controller/src/main/resources/app/utils/PinotMethodUtils.ts index cdcad16dc1e6..211a9b1d502f 100644 --- a/pinot-controller/src/main/resources/app/utils/PinotMethodUtils.ts +++ b/pinot-controller/src/main/resources/app/utils/PinotMethodUtils.ts @@ -422,8 +422,8 @@ const getAllTableDetails = (tablesList) => { } = result.data; singleTableData.push( tableName, - reportedSizeInBytes, - estimatedSizeInBytes + Utils.formatBytes(reportedSizeInBytes), + Utils.formatBytes(estimatedSizeInBytes) ); } else if (index % 3 === 1) { // response of getIdealState API diff --git a/pinot-controller/src/main/resources/app/utils/Utils.tsx b/pinot-controller/src/main/resources/app/utils/Utils.tsx index d6e22accb85d..f279e59d6e70 100644 --- a/pinot-controller/src/main/resources/app/utils/Utils.tsx +++ b/pinot-controller/src/main/resources/app/utils/Utils.tsx @@ -324,6 +324,18 @@ const encodeString = (str: string) => { return str; } +const formatBytes = (bytes, decimals = 2) => { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + export default { sortArray, tableFormat, @@ -333,5 +345,6 @@ export default { serialize, navigateToPreviousPage, syncTableSchemaData, - encodeString + encodeString, + formatBytes };