-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
83 additions
and
116 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './node-maintenance'; | ||
export * from './bare-metal-host'; | ||
|
||
export const BAREMETAL_FLAG = 'BAREMETAL_FLAG'; |
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
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
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
85 changes: 20 additions & 65 deletions
85
...d/packages/ocs-independent-plugin/src/components/dashboard-page/utilization-card/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 |
---|---|---|
@@ -1,95 +1,50 @@ | ||
import * as React from 'react'; | ||
import { withDashboardResources } from '@console/internal/components/dashboard/with-dashboard-resources'; | ||
import { | ||
ONE_HR, | ||
SIX_HR, | ||
TWENTY_FOUR_HR, | ||
UTILIZATION_QUERY_HOUR_MAP, | ||
} from '@console/shared/src/components/dashboard/utilization-card/dropdown-value'; | ||
import * as _ from 'lodash'; | ||
import { getPrometheusQueryResponse } from '@console/internal/actions/dashboards'; | ||
import { getRangeVectorStats } from '@console/internal/components/graphs/utils'; | ||
import { getLatestValue } from '@console/ceph-storage-plugin/src/components/dashboard-page/storage-dashboard/utilization-card/utils'; | ||
import DashboardCardTitle from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardTitle'; | ||
import DashboardCardHeader from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardHeader'; | ||
import DashboardCard from '@console/shared/src/components/dashboard/dashboard-card/DashboardCard'; | ||
import { Dropdown, humanizeBinaryBytes } from '@console/internal/components/utils'; | ||
import UtilizationBody from '@console/shared/src/components/dashboard/utilization-card/UtilizationBody'; | ||
import UtilizationItem from '@console/shared/src/components/dashboard/utilization-card/UtilizationItem'; | ||
import { ByteDataTypes } from '@console/shared/src/graph-helper/data-utils'; | ||
import DashboardCardBody from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardBody'; | ||
import { UTILIZATION_QUERY, IndependentDashboardQuery } from '../../../queries'; | ||
import { | ||
useMetricDuration, | ||
Duration, | ||
} from '@console/shared/src/components/dashboard/duration-hook'; | ||
import { PrometheusUtilizationItem } from '@console/internal/components/dashboard/dashboards-page/overview-dashboard/utilization-card'; | ||
|
||
const metricDurations = [ONE_HR, SIX_HR, TWENTY_FOUR_HR]; | ||
const metricDurationsOptions = _.zipObject(metricDurations, metricDurations); | ||
|
||
const UtilizationCard = withDashboardResources((props) => { | ||
const { watchPrometheus, stopWatchPrometheusQuery, prometheusResults } = props; | ||
const [duration, setDuration] = React.useState(metricDurations[0]); | ||
|
||
React.useEffect(() => { | ||
Object.keys(UTILIZATION_QUERY).forEach((q) => | ||
watchPrometheus(UTILIZATION_QUERY[q], null, UTILIZATION_QUERY_HOUR_MAP[duration]), | ||
); | ||
return () => { | ||
Object.keys(UTILIZATION_QUERY).forEach((q) => | ||
stopWatchPrometheusQuery(UTILIZATION_QUERY[q], UTILIZATION_QUERY_HOUR_MAP[duration]), | ||
); | ||
}; | ||
}, [duration, stopWatchPrometheusQuery, watchPrometheus]); | ||
|
||
const [capacityUtilization, capacityUtilizationError] = getPrometheusQueryResponse( | ||
prometheusResults, | ||
UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_USED], | ||
); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [totalCapacity, totalCapacityError] = getPrometheusQueryResponse( | ||
prometheusResults, | ||
UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_TOTAL], | ||
UTILIZATION_QUERY_HOUR_MAP[duration], | ||
); | ||
|
||
const capacityStats = getRangeVectorStats(capacityUtilization); | ||
const maxCapacityStats = getLatestValue(getRangeVectorStats(totalCapacity)); | ||
const UtilizationCard: React.FC = () => { | ||
const [duration, setDuration] = useMetricDuration(); | ||
const [timestamps, setTimestamps] = React.useState<Date[]>(); | ||
|
||
return ( | ||
<DashboardCard> | ||
<DashboardCardHeader> | ||
<DashboardCardTitle>Utilization</DashboardCardTitle> | ||
<Dropdown | ||
items={metricDurationsOptions} | ||
onChange={setDuration} | ||
selectedKey={duration} | ||
title={duration} | ||
/> | ||
<Dropdown items={Duration} onChange={setDuration} selectedKey={duration} title={duration} /> | ||
</DashboardCardHeader> | ||
<DashboardCardBody> | ||
<UtilizationBody timestamps={capacityStats.map((stat) => stat.x as Date)}> | ||
<UtilizationItem | ||
title="Used capacity" | ||
query={UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_USED]} | ||
data={capacityStats} | ||
error={capacityUtilizationError} | ||
isLoading={!capacityUtilization} | ||
<UtilizationBody timestamps={timestamps}> | ||
<PrometheusUtilizationItem | ||
title="Used Capacity" | ||
utilizationQuery={UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_USED]} | ||
duration={duration} | ||
humanizeValue={humanizeBinaryBytes} | ||
byteDataType={ByteDataTypes.BinaryBytes} | ||
max={maxCapacityStats} | ||
setTimestamps={setTimestamps} | ||
/> | ||
<UtilizationItem | ||
<PrometheusUtilizationItem | ||
title="Requested capacity" | ||
query={UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_TOTAL]} | ||
data={capacityStats} | ||
error={capacityUtilizationError} | ||
isLoading={!capacityUtilization} | ||
utilizationQuery={UTILIZATION_QUERY[IndependentDashboardQuery.CEPH_CAPACITY_TOTAL]} | ||
duration={duration} | ||
humanizeValue={humanizeBinaryBytes} | ||
byteDataType={ByteDataTypes.BinaryBytes} | ||
max={maxCapacityStats} | ||
setTimestamps={setTimestamps} | ||
/> | ||
</UtilizationBody> | ||
</DashboardCardBody> | ||
</DashboardCard> | ||
); | ||
}); | ||
}; | ||
|
||
export default UtilizationCard; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export const INDEPENDENT_FLAG = 'INDEPENDENT_FLAG'; | ||
export const OCS_NS = 'openshift-storage'; |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
import { k8sGet, K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { OCSServiceModel } from './models'; | ||
import { INDEPENDENT_FLAG } from './consts'; | ||
|
||
const isIndependent = (data: K8sResourceKind): boolean => { | ||
const isExt = data.spec.isExternal; | ||
return !!isExt; | ||
}; | ||
|
||
export const detectIndependentMode = (dispatch) => { | ||
dispatch({ type: 'addFlag', payload: { flag: INDEPENDENT_FLAG } }); | ||
return k8sGet(OCSServiceModel, { ns: 'openshift-storage', name: 'ocs-storagecluster' }) | ||
.then((data) => { | ||
if (isIndependent(data)) { | ||
dispatch({ type: 'setFlag', payload: { flag: INDEPENDENT_FLAG, value: true } }); | ||
} else { | ||
dispatch({ type: 'setFlag', payload: { flag: INDEPENDENT_FLAG, value: true } }); | ||
} | ||
}) | ||
.catch((err) => { | ||
// Todo(bipuladh): Add handle error once error is fixed! | ||
console.error(err); | ||
}); | ||
}; |
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
Oops, something went wrong.