Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arun Kumar Mohan <amohan@redhat.com>
- Loading branch information
Showing
4 changed files
with
131 additions
and
4 deletions.
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
112 changes: 112 additions & 0 deletions
112
...ges/ceph-storage-plugin/src/components/dashboards/block-pool/compression-details-card.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,112 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { compose } from 'redux'; | ||
|
||
import { getInstantVectorStats } from '@console/internal/components/graphs/utils'; | ||
|
||
import DashboardCard from '@console/shared/src/components/dashboard/dashboard-card/DashboardCard'; | ||
import DashboardCardBody from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardBody'; | ||
import DashboardCardHeader from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardHeader'; | ||
import DashboardCardTitle from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardTitle'; | ||
import DetailItem from '@console/shared/src/components/dashboard/details-card/DetailItem'; | ||
import DetailsBody from '@console/shared/src/components/dashboard/details-card/DetailsBody'; | ||
import { usePrometheusQueries } from '@console/shared/src/components/dashboard/utilization-card/prometheus-hook'; | ||
import { | ||
humanizePercentage, | ||
humanizeBinaryBytes, | ||
humanizeNumber, | ||
} from '@console/internal/components/utils'; | ||
|
||
import { BlockPoolDashboardContext } from './block-pool-dashboard-context'; | ||
import { EfficiencyItemBody } from '../common/storage-efficiency/storage-efficiency-card-item'; | ||
|
||
import { getPoolQuery, StorageDashboardQuery } from '../../../queries/ceph-queries'; | ||
|
||
const parser = compose((val) => val?.[0]?.y, getInstantVectorStats); | ||
|
||
export const CompressionDetailsCard: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const { obj } = React.useContext(BlockPoolDashboardContext); | ||
|
||
const compressionMode = obj.spec?.compressionMode; | ||
const compressionEnabled = compressionMode !== 'none'; | ||
const { name } = obj.metadata; | ||
|
||
// Compression Metrics | ||
const queries = React.useMemo( | ||
() => [ | ||
getPoolQuery([name], StorageDashboardQuery.POOL_COMPRESSION_SAVINGS), | ||
getPoolQuery([name], StorageDashboardQuery.POOL_COMPRESSION_ELIGIBILITY), | ||
getPoolQuery([name], StorageDashboardQuery.POOL_COMPRESSION_RATIO), | ||
], | ||
[name], | ||
); | ||
|
||
const [values, loading, loadError] = usePrometheusQueries(queries, parser as any); | ||
const poolCompressionSavings = values?.[0]; | ||
const poolCompressionEligibility = values?.[1]; | ||
const poolCompressionRatio = values?.[2]; | ||
|
||
const compressionEligibilityProps = { | ||
stats: Number(poolCompressionEligibility), | ||
isLoading: loading, | ||
error: loadError || !poolCompressionEligibility, | ||
title: t('ceph-storage-plugin~Compression eligibility'), | ||
getStats: () => humanizePercentage(poolCompressionEligibility).string, | ||
infoText: t( | ||
'ceph-storage-plugin~Compression eligibility indicates the percentage of incoming data that is compressible', | ||
), | ||
}; | ||
|
||
const compressionSavingsProps = { | ||
stats: Number(poolCompressionSavings), | ||
isLoading: loading, | ||
error: loadError || !poolCompressionSavings, | ||
title: t('ceph-storage-plugin~Compression savings'), | ||
getStats: () => humanizeBinaryBytes(poolCompressionSavings).string, | ||
infoText: t( | ||
'ceph-storage-plugin~Compression savings indicates the total savings gained from compression for this pool, including replicas', | ||
), | ||
}; | ||
|
||
const compressionRatioProps = { | ||
stats: Number(poolCompressionRatio), | ||
isLoading: loading, | ||
error: loadError || !poolCompressionRatio, | ||
title: t('ceph-storage-plugin~Compression ratio'), | ||
getStats: () => `${humanizeNumber(poolCompressionRatio).string}:1`, | ||
infoText: t( | ||
'ceph-storage-plugin~Compression ratio indicates the achieved compression on eligible data for this pool', | ||
), | ||
}; | ||
|
||
return ( | ||
<DashboardCard data-test-id="compression-details-card"> | ||
<DashboardCardHeader> | ||
<DashboardCardTitle>{t('ceph-storage-plugin~Compression')}</DashboardCardTitle> | ||
</DashboardCardHeader> | ||
<DashboardCardBody> | ||
<DetailsBody> | ||
<DetailItem isLoading={!obj} title={t('ceph-storage-plugin~Compression status')}> | ||
{!compressionEnabled | ||
? t('ceph-storage-plugin~Disabled') | ||
: t('ceph-storage-plugin~Enabled')} | ||
</DetailItem> | ||
</DetailsBody> | ||
{compressionEnabled && ( | ||
<DetailsBody> | ||
<div> | ||
<DetailsBody> | ||
<DetailItem isLoading={loading} title={t('ceph-storage-plugin~Storage efficiency')}> | ||
<EfficiencyItemBody {...compressionEligibilityProps} /> | ||
<EfficiencyItemBody {...compressionRatioProps} /> | ||
<EfficiencyItemBody {...compressionSavingsProps} /> | ||
</DetailItem> | ||
</DetailsBody> | ||
</div> | ||
</DetailsBody> | ||
)} | ||
</DashboardCardBody> | ||
</DashboardCard> | ||
); | ||
}; |
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