mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Change Deployment metrics to be injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
6f73c4dff2
commit
8c032ce704
@ -14,70 +14,40 @@ import { Deployment } from "../../../common/k8s-api/endpoints";
|
|||||||
import { PodDetailsTolerations } from "../+workloads-pods/pod-details-tolerations";
|
import { PodDetailsTolerations } from "../+workloads-pods/pod-details-tolerations";
|
||||||
import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities";
|
import { PodDetailsAffinities } from "../+workloads-pods/pod-details-affinities";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
import { ResourceMetrics, ResourceMetricsText } from "../resource-metrics";
|
|
||||||
import type { DeploymentStore } from "./store";
|
import type { DeploymentStore } from "./store";
|
||||||
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
|
||||||
import { makeObservable, observable, reaction } from "mobx";
|
|
||||||
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
import { PodDetailsList } from "../+workloads-pods/pod-details-list";
|
||||||
import { KubeObjectMeta } from "../kube-object-meta";
|
|
||||||
import type { ReplicaSetStore } from "../+workloads-replicasets/store";
|
import type { ReplicaSetStore } from "../+workloads-replicasets/store";
|
||||||
import { DeploymentReplicaSets } from "./deployment-replicasets";
|
import { DeploymentReplicaSets } from "./deployment-replicasets";
|
||||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
import type { Logger } from "../../../common/logger";
|
||||||
import logger from "../../../common/logger";
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api";
|
import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api";
|
||||||
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
||||||
import type { PodStore } from "../+workloads-pods/store";
|
|
||||||
import podStoreInjectable from "../+workloads-pods/store.injectable";
|
|
||||||
import replicaSetStoreInjectable from "../+workloads-replicasets/store.injectable";
|
import replicaSetStoreInjectable from "../+workloads-replicasets/store.injectable";
|
||||||
import deploymentStoreInjectable from "./store.injectable";
|
import deploymentStoreInjectable from "./store.injectable";
|
||||||
import type { GetActiveClusterEntity } from "../../api/catalog/entity/get-active-cluster-entity.injectable";
|
import loggerInjectable from "../../../common/logger.injectable";
|
||||||
import getActiveClusterEntityInjectable from "../../api/catalog/entity/get-active-cluster-entity.injectable";
|
|
||||||
import type { DeploymentPodMetricData, RequestPodMetricsForDeployments } from "../../../common/k8s-api/endpoints/metrics.api/request-pod-metrics-for-deployments.injectable";
|
|
||||||
import requestPodMetricsForDeploymentsInjectable from "../../../common/k8s-api/endpoints/metrics.api/request-pod-metrics-for-deployments.injectable";
|
|
||||||
|
|
||||||
export interface DeploymentDetailsProps extends KubeObjectDetailsProps<Deployment> {
|
export interface DeploymentDetailsProps extends KubeObjectDetailsProps<Deployment> {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
subscribeStores: SubscribeStores;
|
subscribeStores: SubscribeStores;
|
||||||
podStore: PodStore;
|
|
||||||
replicaSetStore: ReplicaSetStore;
|
replicaSetStore: ReplicaSetStore;
|
||||||
deploymentStore: DeploymentStore;
|
deploymentStore: DeploymentStore;
|
||||||
getActiveClusterEntity: GetActiveClusterEntity;
|
logger: Logger;
|
||||||
requestPodMetricsForDeployments: RequestPodMetricsForDeployments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProps & Dependencies> {
|
class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProps & Dependencies> {
|
||||||
@observable metrics: DeploymentPodMetricData | null = null;
|
|
||||||
|
|
||||||
constructor(props: DeploymentDetailsProps & Dependencies) {
|
|
||||||
super(props);
|
|
||||||
makeObservable(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.props.object, () => {
|
|
||||||
this.metrics = null;
|
|
||||||
}),
|
|
||||||
|
|
||||||
this.props.subscribeStores([
|
this.props.subscribeStores([
|
||||||
this.props.podStore,
|
|
||||||
this.props.replicaSetStore,
|
this.props.replicaSetStore,
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMetrics = async () => {
|
|
||||||
const { object: deployment, requestPodMetricsForDeployments } = this.props;
|
|
||||||
|
|
||||||
this.metrics = await requestPodMetricsForDeployments([deployment], deployment.getNs());
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { object: deployment, podStore, replicaSetStore, deploymentStore, getActiveClusterEntity } = this.props;
|
const { object: deployment, replicaSetStore, deploymentStore, logger } = this.props;
|
||||||
|
|
||||||
if (!deployment) {
|
if (!deployment) {
|
||||||
return null;
|
return null;
|
||||||
@ -94,21 +64,9 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
|||||||
const selectors = deployment.getSelectors();
|
const selectors = deployment.getSelectors();
|
||||||
const childPods = deploymentStore.getChildPods(deployment);
|
const childPods = deploymentStore.getChildPods(deployment);
|
||||||
const replicaSets = replicaSetStore.getReplicaSetsByOwner(deployment);
|
const replicaSets = replicaSetStore.getReplicaSetsByOwner(deployment);
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Deployment);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="DeploymentDetails">
|
<div className="DeploymentDetails">
|
||||||
{!isMetricHidden && podStore.isLoaded && (
|
|
||||||
<ResourceMetrics
|
|
||||||
loader={this.loadMetrics}
|
|
||||||
tabs={podMetricTabs}
|
|
||||||
object={deployment}
|
|
||||||
metrics={this.metrics}
|
|
||||||
>
|
|
||||||
<PodCharts/>
|
|
||||||
</ResourceMetrics>
|
|
||||||
)}
|
|
||||||
<KubeObjectMeta object={deployment}/>
|
|
||||||
<DrawerItem name="Replicas">
|
<DrawerItem name="Replicas">
|
||||||
{`${spec.replicas} desired, ${status?.updatedReplicas ?? 0} updated, `}
|
{`${spec.replicas} desired, ${status?.updatedReplicas ?? 0} updated, `}
|
||||||
{`${status?.replicas ?? 0} total, ${status?.availableReplicas ?? 0} available, `}
|
{`${status?.replicas ?? 0} total, ${status?.availableReplicas ?? 0} available, `}
|
||||||
@ -159,7 +117,6 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
|||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<PodDetailsTolerations workload={deployment}/>
|
<PodDetailsTolerations workload={deployment}/>
|
||||||
<PodDetailsAffinities workload={deployment}/>
|
<PodDetailsAffinities workload={deployment}/>
|
||||||
<ResourceMetricsText metrics={this.metrics}/>
|
|
||||||
<DeploymentReplicaSets replicaSets={replicaSets}/>
|
<DeploymentReplicaSets replicaSets={replicaSets}/>
|
||||||
<PodDetailsList pods={childPods} owner={deployment}/>
|
<PodDetailsList pods={childPods} owner={deployment}/>
|
||||||
</div>
|
</div>
|
||||||
@ -171,11 +128,9 @@ export const DeploymentDetails = withInjectables<Dependencies, DeploymentDetails
|
|||||||
getProps: (di, props) => ({
|
getProps: (di, props) => ({
|
||||||
...props,
|
...props,
|
||||||
subscribeStores: di.inject(subscribeStoresInjectable),
|
subscribeStores: di.inject(subscribeStoresInjectable),
|
||||||
podStore: di.inject(podStoreInjectable),
|
|
||||||
replicaSetStore: di.inject(replicaSetStoreInjectable),
|
replicaSetStore: di.inject(replicaSetStoreInjectable),
|
||||||
deploymentStore: di.inject(deploymentStoreInjectable),
|
deploymentStore: di.inject(deploymentStoreInjectable),
|
||||||
getActiveClusterEntity: di.inject(getActiveClusterEntityInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
requestPodMetricsForDeployments: di.inject(requestPodMetricsForDeploymentsInjectable),
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import React from "react";
|
||||||
|
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
|
||||||
|
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||||
|
import type { Deployment } from "../../../common/k8s-api/endpoints";
|
||||||
|
import enabledMetricsInjectable from "../../api/catalog/entity/metrics-enabled.injectable";
|
||||||
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
|
import { kubeObjectDetailItemInjectionToken } from "../kube-object-details/kube-object-detail-items/kube-object-detail-item-injection-token";
|
||||||
|
import { ResourceMetrics } from "../resource-metrics";
|
||||||
|
import deploymentMetricsInjectable from "./metrics.injectable";
|
||||||
|
|
||||||
|
const deploymentMetricsDetailsComponentInjectable = getInjectable({
|
||||||
|
id: "deployment-metrics-details-component",
|
||||||
|
instantiate: (di) => ({
|
||||||
|
Component: ({ object }: KubeObjectDetailsProps<Deployment>) => (
|
||||||
|
<ResourceMetrics
|
||||||
|
tabs={podMetricTabs}
|
||||||
|
object={object}
|
||||||
|
metrics={di.inject(deploymentMetricsInjectable, object)}
|
||||||
|
>
|
||||||
|
<PodCharts />
|
||||||
|
</ResourceMetrics>
|
||||||
|
),
|
||||||
|
enabled: di.inject(enabledMetricsInjectable, ClusterMetricsResourceType.Deployment),
|
||||||
|
orderNumber: -1,
|
||||||
|
}),
|
||||||
|
injectionToken: kubeObjectDetailItemInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default deploymentMetricsDetailsComponentInjectable;
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
|
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||||
|
import { now } from "mobx-utils";
|
||||||
|
import type { Deployment } from "../../../common/k8s-api/endpoints";
|
||||||
|
import requestPodMetricsForDeploymentsInjectable from "../../../common/k8s-api/endpoints/metrics.api/request-pod-metrics-for-deployments.injectable";
|
||||||
|
|
||||||
|
const deploymentMetricsInjectable = getInjectable({
|
||||||
|
id: "deployment-metrics",
|
||||||
|
instantiate: (di, deployment) => {
|
||||||
|
const requestPodMetricsForDeployments = di.inject(requestPodMetricsForDeploymentsInjectable);
|
||||||
|
|
||||||
|
return asyncComputed(() => {
|
||||||
|
now(60 * 1000);
|
||||||
|
|
||||||
|
return requestPodMetricsForDeployments([deployment], deployment.getNs());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
lifecycle: lifecycleEnum.keyedSingleton({
|
||||||
|
getInstanceKey: (di, deployment: Deployment) => deployment.getId(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default deploymentMetricsInjectable;
|
||||||
Loading…
Reference in New Issue
Block a user