Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Jan 20, 2020
1 parent b7922c6 commit fd38b74
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 116 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/ceph-storage-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const plugin: Plugin<ConsumedExtensions> = [
id: 'persistent-storage',
title: 'OCS PV',
required: CEPH_FLAG,
blocker: INDEPENDENT_FLAG,
disallowed: INDEPENDENT_FLAG,
},
},
{
Expand Down
7 changes: 4 additions & 3 deletions frontend/packages/console-plugin-sdk/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ export class ExtensionRegistry {
);
}

public getBlockerFlags(typeGuards: ExtensionTypeGuard<ExtensionWithFlags>[]) {
public getDisallowedFlags(typeGuards: ExtensionTypeGuard<ExtensionWithFlags>[]) {
return _.flatMap(typeGuards.map((tg) => this.extensions.filter(tg)))
.filter((e) => e.properties.blocker)
.filter((e) => e.properties.disallowed)
.reduce(
(blockerFlags, e) => _.uniq([...blockerFlags, ..._.castArray(e.properties.blocker)]),
(disallowedFlags, e) =>
_.uniq([...disallowedFlags, ..._.castArray(e.properties.disallowed)]),
[] as string[],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ export const HOST_HARDWARE_ERROR_STATES = [HOST_STATUS_POWER_MANAGEMENT_ERROR];
export const HOST_HEALTH_OK = 'Host is healthy';
export const HOST_HEALTH_ERROR = 'Host is in an error state';
export const HOST_HEALTH_LOADING = 'Loading host health data';
export const BAREMETAL = 'BAREMETAL';
2 changes: 2 additions & 0 deletions frontend/packages/metal3-plugin/src/constants/index.ts
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';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as _ from 'lodash';
import { k8sGet, K8sResourceKind } from '@console/internal/module/k8s';
import { InfrastructureModel } from '@console/internal/models';
import { getInfrastructurePlatform } from '@console/shared/src/selectors/infrastructure';
import * as _ from 'lodash';
import { BAREMETAL } from './constants';
import { BAREMETAL_FLAG } from './constants';

const retryFlagDetection = (dispatch, cb) => {
setTimeout(() => cb(dispatch), 15000);
Expand All @@ -19,13 +19,13 @@ const handleError = (res, flag, dispatch, cb) => {
};

export const detectBaremetalPlatform = (dispatch) => {
dispatch({ type: 'addFlag', payload: { flag: BAREMETAL } });
dispatch({ type: 'addFlag', payload: { flag: BAREMETAL_FLAG } });
return k8sGet(InfrastructureModel, 'cluster')
.then((infra: K8sResourceKind) => {
dispatch({
type: 'setFlag',
payload: {
flag: BAREMETAL,
flag: BAREMETAL_FLAG,
value: getInfrastructurePlatform(infra) === 'Baremetal',
},
});
Expand All @@ -35,10 +35,10 @@ export const detectBaremetalPlatform = (dispatch) => {
? dispatch({
type: 'setFlag',
payload: {
flag: BAREMETAL,
flag: BAREMETAL_FLAG,
value: false,
},
})
: handleError(err, BAREMETAL, dispatch, detectBaremetalPlatform);
: handleError(err, BAREMETAL_FLAG, dispatch, detectBaremetalPlatform);
});
};
21 changes: 11 additions & 10 deletions frontend/packages/metal3-plugin/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { getHostPowerStatus } from './selectors';
import {
HOST_POWER_STATUS_POWERING_OFF,
HOST_POWER_STATUS_POWERING_ON,
BAREMETAL,
BAREMETAL_FLAG,
} from './constants';
import { BareMetalHostKind } from './types';
import { detectBaremetalPlatform } from './feature';
import { detectBaremetalPlatform } from './features';

type ConsumedExtensions =
| DashboardsOverviewInventoryItem
Expand Down Expand Up @@ -61,6 +61,7 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'FeatureFlag/Action',
properties: {
flag: BAREMETAL_FLAG,
detect: detectBaremetalPlatform,
},
},
Expand All @@ -71,7 +72,7 @@ const plugin: Plugin<ConsumedExtensions> = [
componentProps: {
name: 'Bare Metal Hosts',
resource: referenceForModel(BareMetalHostModel),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
mergeBefore: 'ComputeSeparator',
},
Expand Down Expand Up @@ -105,7 +106,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-hosts/add-baremetal-host/AddBareMetalHostPage' /* webpackChunkName: "metal3-baremetalhost" */
).then((m) => m.default),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -121,7 +122,7 @@ const plugin: Plugin<ConsumedExtensions> = [
},
],
mapper: getBMNStatusGroups,
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -147,7 +148,7 @@ const plugin: Plugin<ConsumedExtensions> = [
],
model: BareMetalHostModel,
mapper: getBMHStatusGroups,
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -159,7 +160,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-nodes/BareMetalNodesPage' /* webpackChunkName: "node" */
).then((m) => m.default),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -171,7 +172,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-nodes/BareMetalNodeDetailsPage' /* webpackChunkName: "node" */
).then((m) => m.default),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -188,7 +189,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/maintenance/MaintenanceDashboardActivity' /* webpackChunkName: "node-maintenance" */
).then((m) => m.default),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
{
Expand All @@ -214,7 +215,7 @@ const plugin: Plugin<ConsumedExtensions> = [
import(
'./components/baremetal-hosts/dashboard/BareMetalStatusActivity' /* webpackChunkName: "metal3-powering" */
).then((m) => m.default),
required: [BAREMETAL, METAL3_FLAG],
required: [BAREMETAL_FLAG, METAL3_FLAG],
},
},
];
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/ocs-independent-plugin/OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ reviewers:
- bipuladh
- cloudbehl
- gnehapk
- rawagner
approvers:
- a2batic
- afreen23
- bipuladh
- cloudbehl
- gnehapk
- rawagner
labels:
- component/ceph-independent
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
} from '@console/ceph-storage-plugin/src/constants/queries';
import { getResiliencyProgress } from '@console/ceph-storage-plugin/src/utils';
import { PrometheusResponse } from '@console/internal/components/graphs';

const OCS_NS = 'openshift-storage';
import { OCS_NS } from '../../../consts';

const eventsResource: FirehoseResource = {
isList: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { ALERTS_KEY } from '@console/internal/actions/dashboards';
import { withDashboardResources } from '@console/internal/components/dashboard/with-dashboard-resources';
import { PrometheusRulesResponse, alertURL } from '@console/internal/components/monitoring';
import { getAlerts } from '@console/shared/src/components/dashboard/status-card/utils';
import { getAlerts } from '@console/shared/src/components/dashboard/status-card/alert-utils';
import { filterCephAlerts } from '@console/ceph-storage-plugin/src/selectors';
import AlertItem from '@console/shared/src/components/dashboard/status-card/AlertItem';
import AlertsBody from '@console/shared/src/components/dashboard/status-card/AlertsBody';
Expand Down
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;
1 change: 1 addition & 0 deletions frontend/packages/ocs-independent-plugin/src/consts.ts
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';
14 changes: 0 additions & 14 deletions frontend/packages/ocs-independent-plugin/src/feature.ts

This file was deleted.

24 changes: 24 additions & 0 deletions frontend/packages/ocs-independent-plugin/src/features.ts
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);
});
};
3 changes: 2 additions & 1 deletion frontend/packages/ocs-independent-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@console/plugin-sdk';
import { GridPosition } from '@console/shared/src/components/dashboard/DashboardGrid';
import { OCSServiceModel } from '@console/ceph-storage-plugin/src/models';
import { detectIndependentMode } from './feature';
import { detectIndependentMode } from './features';
import { INDEPENDENT_FLAG } from './consts';

type ConsumedExtensions =
Expand All @@ -29,6 +29,7 @@ const plugin: Plugin<ConsumedExtensions> = [
{
type: 'FeatureFlag/Action',
properties: {
flag: INDEPENDENT_FLAG,
detect: detectIndependentMode,
},
},
Expand Down

0 comments on commit fd38b74

Please sign in to comment.