priyeshkaratha commented on code in PR #9584: URL: https://github.com/apache/ozone/pull/9584#discussion_r2670901177
########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/pages/capacity/capacity.tsx: ########## @@ -0,0 +1,342 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Popover, Tag, Tooltip, Typography } from 'antd'; +import React from 'react'; +import AutoReloadPanel from '@/components/autoReloadPanel/autoReloadPanel'; + +import './capacity.less'; +import { showDataFetchError } from '@/utils/common' +import moment from 'moment'; +import CapacityBreakdown from '@/v2/pages/capacity/components/CapacityBreakdown'; +import CapacityDetail from '@/v2/pages/capacity/components/CapacityDetail'; +import { + datanodesPendingDeletionDesc, + otherUsedSpaceDesc, + ozoneUsedSpaceDesc, + totalCapacityDesc +} from '@/v2/pages/capacity/constants/descriptions.constants'; +import WrappedInfoIcon from '@/v2/pages/capacity/components/WrappedInfoIcon'; +import filesize from 'filesize'; +import { InfoCircleOutlined, WarningFilled, CheckCircleFilled } from '@ant-design/icons'; +import { useApiData } from '@/v2/hooks/useAPIData.hook'; +import * as CONSTANTS from '@/v2/constants/capacity.constants'; +import { UtilizationResponse, SCMPendingDeletion, OMPendingDeletion, DNPendingDeletion, DataNodeUsage } from '@/v2/types/capacity.types'; +import { useAutoReload } from '@/v2/hooks/useAutoReload.hook'; + +type CapacityState = { + isDNPending: boolean; + lastUpdated: number; +}; + +const Capacity: React.FC<object> = () => { + + const [state, setState] = React.useState<CapacityState>({ + isDNPending: true, + lastUpdated: 0 + }); + + const storageDistribution = useApiData<UtilizationResponse>( + '/api/v1/storageDistribution', + CONSTANTS.DEFAULT_CAPACITY_UTILIZATION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const scmPendingDeletes = useApiData<SCMPendingDeletion>( + '/api/v1/pendingDeletion?component=scm', + CONSTANTS.DEFAULT_SCM_PENDING_DELETION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const omPendingDeletes = useApiData<OMPendingDeletion>( + '/api/v1/pendingDeletion?component=om', + CONSTANTS.DEFAULT_OM_PENDING_DELETION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const dnPendingDeletes = useApiData<DNPendingDeletion>( + '/api/v1/pendingDeletion?component=dn', + CONSTANTS.DEFAULT_DN_PENDING_DELETION, + { + retryAttempts: 2, + initialFetch: false, + onError: (error) => showDataFetchError(error) + } + ); + + const [selectedDatanode, setSelectedDatanode] = React.useState<string>(storageDistribution.data.dataNodeUsage[0]?.hostName ?? ""); + + // Seed selected datanode once data loads so dependent calculations work + React.useEffect(() => { + const firstHost = storageDistribution.data.dataNodeUsage[0]?.hostName; + if (!selectedDatanode && firstHost) { + setSelectedDatanode(firstHost); + } + }, [selectedDatanode, storageDistribution.data.dataNodeUsage]); + + const loadDNData = () => { + dnPendingDeletes.refetch(); + setState({ + isDNPending: dnPendingDeletes.data.status === "FINISHED", + lastUpdated: Number(moment()) + }) + } + + const autoReload = useAutoReload(loadDNData); + + const selectedDNDetails: DataNodeUsage & { pendingBlockSize: number } = React.useMemo(() => { + const selected = storageDistribution.data.dataNodeUsage.find(datanode => datanode.hostName === selectedDatanode) + ?? storageDistribution.data.dataNodeUsage[0]; + return { + ...(selected ?? { + datanodeUuid: "unknown-uuid", + hostName: "unknown-host", + capacity: 0, + used: 0, + remaining: 0, + committed: 0, + minimumFreeSpace: 0, + reserved: 0 + }), + ...dnPendingDeletes.data.pendingDeletionPerDataNode?.find(dn => dn.hostName === (selected?.hostName ?? selectedDatanode)) ?? { + hostName: "unknown-host", + datanodeUuid: "unknown-uuid", + pendingBlockSize: 0 + } + } + }, [selectedDatanode, storageDistribution.data.dataNodeUsage, dnPendingDeletes.data.pendingDeletionPerDataNode]); + + const dnReportStatus = ( + (dnPendingDeletes.data.totalNodeQueriesFailed ?? 0) > 0 + ? <Tooltip title={<> + { (dnPendingDeletes.data.totalNodesQueried ?? 0) + - (dnPendingDeletes.data.totalNodeQueriesFailed ?? 0) + } / { (dnPendingDeletes.data.totalNodesQueried ?? 0) } DNs + </> + }> + <WarningFilled style={{ color: '#f6a62eff', marginRight: 8, fontSize: 14 }} /> + Datanodes + </Tooltip> + : <Tooltip title={ + <> + {dnPendingDeletes.data.totalNodesQueried ?? 0} / {dnPendingDeletes.data.totalNodesQueried ?? 0} DNs + </> + }> + <CheckCircleFilled style={{ color: '#1ea57a', marginRight: 8, fontSize: 14 }} /> + Datanodes + </Tooltip> + ) + + const unusedSpaceBreakdown = ( + <span> + UNUSED + <Popover + title="Unused Space Breakdown" + placement='topLeft' + content={ + <div className='unused-space-breakdown'> + Minimum Free Space + <Tag color='red'>{filesize(selectedDNDetails.minimumFreeSpace, {round: 1})}</Tag> + Remaining + <Tag color='green'>{filesize(selectedDNDetails.remaining, { round: 1})}</Tag> + </div> + } + > + <InfoCircleOutlined style={{ color: '#2f84d8', fontSize: 12, marginLeft: 4 }} /> + </Popover> + </span> + ) + + return ( + <> + <div className='page-header-v2'> + Cluster Capacity + <AutoReloadPanel + isLoading={state.isDNPending} + lastRefreshed={state.lastUpdated} + togglePolling={autoReload.handleAutoReloadToggle} + onReload={loadDNData} /> + </div> + <div className='data-container'> + <Typography.Title level={4} className='section-title'>Cluster</Typography.Title> + <CapacityBreakdown + title='Ozone Capacity' + loading={storageDistribution.loading} + items={[{ + title: ( + <span> + TOTAL + <WrappedInfoIcon title={totalCapacityDesc} /> + </span> + ), + value: storageDistribution.data.globalStorage.totalCapacity, + }, { + title: 'OZONE USED SPACE', + value: storageDistribution.data.globalStorage.totalUsedSpace, + color: '#f4a233' + }, { + title: ( + <span> + OTHER USED SPACE + <WrappedInfoIcon title={otherUsedSpaceDesc} /> + </span> + ), + value: ( + storageDistribution.data.globalStorage.totalCapacity + - storageDistribution.data.globalStorage.totalFreeSpace + - storageDistribution.data.globalStorage.totalUsedSpace + ), + color: '#11073a' + }, { + title: 'CONTAINER PRE-ALLOCATED', + value: storageDistribution.data.usedSpaceBreakdown.preAllocatedContainerBytes, + color: '#f47b2d' + }, { + title: 'REMAINING SPACE', + value: storageDistribution.data.globalStorage.totalFreeSpace, + color: '#4553ee' + }]} + /> + <Typography.Title level={4} className='section-title'>Service</Typography.Title> + <CapacityBreakdown + title={( + <span> + Ozone Used Space + <WrappedInfoIcon title={ozoneUsedSpaceDesc} /> + </span> + )} + loading={storageDistribution.loading} + items={[{ + title: 'TOTAL', + value: storageDistribution.data.globalStorage.totalUsedSpace + }, { + title: 'OPEN KEYS', + value: storageDistribution.data.usedSpaceBreakdown.openKeyBytes, + color: '#f47c2d' + }, { + title: 'COMMITTED KEYS', + value: storageDistribution.data.usedSpaceBreakdown.committedKeyBytes, + color: '#f4a233' + }, { + title: ( + dnPendingDeletes.data.status === "FINISHED" + ? 'PENDING DELETION' + : ( + <span> + PENDING DELETION + <WrappedInfoIcon title="DN pending deletion data is not yet available. It will be fetched once the pending deletion scan is finished on all datanodes." /> Review Comment: This can be shown only once during initial calculations. Once data is available you can cache it and after that you can show different info. ########## hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/pages/capacity/capacity.tsx: ########## @@ -0,0 +1,342 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Popover, Tag, Tooltip, Typography } from 'antd'; +import React from 'react'; +import AutoReloadPanel from '@/components/autoReloadPanel/autoReloadPanel'; + +import './capacity.less'; +import { showDataFetchError } from '@/utils/common' +import moment from 'moment'; +import CapacityBreakdown from '@/v2/pages/capacity/components/CapacityBreakdown'; +import CapacityDetail from '@/v2/pages/capacity/components/CapacityDetail'; +import { + datanodesPendingDeletionDesc, + otherUsedSpaceDesc, + ozoneUsedSpaceDesc, + totalCapacityDesc +} from '@/v2/pages/capacity/constants/descriptions.constants'; +import WrappedInfoIcon from '@/v2/pages/capacity/components/WrappedInfoIcon'; +import filesize from 'filesize'; +import { InfoCircleOutlined, WarningFilled, CheckCircleFilled } from '@ant-design/icons'; +import { useApiData } from '@/v2/hooks/useAPIData.hook'; +import * as CONSTANTS from '@/v2/constants/capacity.constants'; +import { UtilizationResponse, SCMPendingDeletion, OMPendingDeletion, DNPendingDeletion, DataNodeUsage } from '@/v2/types/capacity.types'; +import { useAutoReload } from '@/v2/hooks/useAutoReload.hook'; + +type CapacityState = { + isDNPending: boolean; + lastUpdated: number; +}; + +const Capacity: React.FC<object> = () => { + + const [state, setState] = React.useState<CapacityState>({ + isDNPending: true, + lastUpdated: 0 + }); + + const storageDistribution = useApiData<UtilizationResponse>( + '/api/v1/storageDistribution', + CONSTANTS.DEFAULT_CAPACITY_UTILIZATION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const scmPendingDeletes = useApiData<SCMPendingDeletion>( + '/api/v1/pendingDeletion?component=scm', + CONSTANTS.DEFAULT_SCM_PENDING_DELETION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const omPendingDeletes = useApiData<OMPendingDeletion>( + '/api/v1/pendingDeletion?component=om', + CONSTANTS.DEFAULT_OM_PENDING_DELETION, + { + retryAttempts: 2, + onError: (error) => showDataFetchError(error) + } + ); + + const dnPendingDeletes = useApiData<DNPendingDeletion>( + '/api/v1/pendingDeletion?component=dn', + CONSTANTS.DEFAULT_DN_PENDING_DELETION, + { + retryAttempts: 2, + initialFetch: false, + onError: (error) => showDataFetchError(error) + } + ); + + const [selectedDatanode, setSelectedDatanode] = React.useState<string>(storageDistribution.data.dataNodeUsage[0]?.hostName ?? ""); + + // Seed selected datanode once data loads so dependent calculations work + React.useEffect(() => { + const firstHost = storageDistribution.data.dataNodeUsage[0]?.hostName; + if (!selectedDatanode && firstHost) { + setSelectedDatanode(firstHost); + } + }, [selectedDatanode, storageDistribution.data.dataNodeUsage]); + + const loadDNData = () => { Review Comment: Currently, the UI shows loading because data is cleared during the 30-second refresh interval. To fix this, we should persist the existing data in the UI while the background update is in progress, only replacing it once the new value is available. Additionally, for the initial load, we should poll at a faster 2-second interval until the first value is retrieved to avoid a long initial loading state. Whenever use do refresh of the page call API which will give in progress state and that time also do a polling with some small interval. So that it can be more UI friendly. API results will be fast for even 100 node cluster so it usually takes less time for normal clusters. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
