Skip to content

Commit

Permalink
Add metrics Feature (#7507)
Browse files Browse the repository at this point in the history
Signed-off-by: Juho Heikka <[email protected]>
  • Loading branch information
jweak authored Apr 12, 2023
1 parent 01cc018 commit 53cb3a5
Show file tree
Hide file tree
Showing 40 changed files with 780 additions and 223 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"@astronautlabs/jsonpath": "^1.1.0",
"@hapi/call": "^9.0.1",
"@hapi/subtext": "^7.1.0",
"@k8slens/metrics": "^6.5.0-alpha.1",
"@k8slens/node-fetch": "^6.5.0-alpha.1",
"@k8slens/react-application": "^1.0.0-alpha.0",
"@kubernetes/client-node": "^0.18.1",
Expand Down
164 changes: 164 additions & 0 deletions packages/core/src/features/metrics/metrics-feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getFeature } from "@k8slens/feature-core";
import { clusterOverviewUIBlockInjectionToken, daemonSetDetailsMetricsInjectionToken, deploymentDetailsMetricsInjectionToken, jobDetailsMetricsInjectionToken, namespaceDetailsMetricsInjectionToken, ingressDetailsMetricsInjectionToken, nodeDetailsMetricsInjectionToken, persistentVolumeClaimDetailsMetricsInjectionToken, podDetailsContainerMetricsInjectionToken, podDetailsMetricsInjectionToken, replicaSetDetailsMetricsInjectionToken, statefulSetDetailsMetricsInjectionToken } from "@k8slens/metrics";
import { getInjectable } from "@ogre-tools/injectable";
import { ClusterMetrics } from "../../renderer/components/+cluster/cluster-metrics";
import { ClusterPieCharts } from "../../renderer/components/+cluster/cluster-pie-charts";
import { NamespaceMetricsDetailsComponent } from "../../renderer/components/+namespaces/metrics-details-component";
import { NodeMetricsDetailsComponent } from "../../renderer/components/+nodes/metrics-details-component";
import { PersistentVolumeClaimMetricsDetailsComponent } from "../../renderer/components/+storage-volume-claims/metrics-details-component";
import { DaemonSetMetricsDetailsComponent } from "../../renderer/components/+workloads-daemonsets/metrics-details-component";
import { DeploymentMetricsDetailsComponent } from "../../renderer/components/+workloads-deployments/metrics-details-component";
import { JobMetricsDetailsComponent } from "../../renderer/components/+workloads-jobs/metrics-details-component";
import { PodDetailsContainerMetrics } from "../../renderer/components/+workloads-pods/pod-details-container-metrics";
import PodMetricsDetailsComponent from "../../renderer/components/+workloads-pods/pod-metrics-details-component";
import { ReplicaSetMetricsDetailsComponent } from "../../renderer/components/+workloads-replicasets/metrics-details-component";
import { StatefulSetMetricsDetailsComponent } from "../../renderer/components/+workloads-statefulsets/metrics-details-component";
import { IngressMetricsDetailsComponent } from "../../renderer/components/+network-ingresses/metrics-details-component";

const clusterPieChartsClusterOverviewInjectable = getInjectable({
id: "cluster-pie-charts-cluster-overview",

instantiate: () => ({
id: "cluster-pie-charts-cluster-overview",
Component: ClusterPieCharts,
orderNumber: 2,
}),

injectionToken: clusterOverviewUIBlockInjectionToken,
});

const clusterMetricsOverviewBlockInjectable = getInjectable({
id: "cluster-metrics-overview-block",

instantiate: () => ({
id: "cluster-metrics-overview-block",
Component: ClusterMetrics,
orderNumber: 1,
}),

injectionToken: clusterOverviewUIBlockInjectionToken,
});

const podDetailsMetricsInjectable = getInjectable({
id: "pod-details-metrics-injectable",
instantiate: () => ({
id: "pod-details-metrics",
Component: PodMetricsDetailsComponent,
}),
injectionToken: podDetailsMetricsInjectionToken,
});

const deploymentDetailsMetricsInjectable = getInjectable({
id: "deployment-details-metrics-injectable",
instantiate: () => ({
id: "deployment-details-metrics",
Component: DeploymentMetricsDetailsComponent,
}),
injectionToken: deploymentDetailsMetricsInjectionToken,
});

const podDetailsContainerMetricsInjectable = getInjectable({
id: "pod-details-container-metrics-injectable",
instantiate: () => ({
id: "pod-details-container-metrics",
Component: PodDetailsContainerMetrics,
}),
injectionToken: podDetailsContainerMetricsInjectionToken,
});

const nodeDetailsMetricsInjectable = getInjectable({
id: "node-details-metrics-injectable",
instantiate: () => ({
id: "node-details-metrics",
Component: NodeMetricsDetailsComponent,
}),
injectionToken: nodeDetailsMetricsInjectionToken,
});

const replicaSetDetailsMetricsInjectable = getInjectable({
id: "replica-set-details-metrics-injectable",
instantiate: () => ({
id: "replica-set-details-metrics",
Component: ReplicaSetMetricsDetailsComponent,
}),
injectionToken: replicaSetDetailsMetricsInjectionToken,
});

const persistentVolumeClaimDetailsMetricsInjectable = getInjectable({
id: "persistent-volume-claim-details-metrics-injectable",
instantiate: () => ({
id: "persistent-volume-claim-details-metrics",
Component: PersistentVolumeClaimMetricsDetailsComponent,
}),
injectionToken: persistentVolumeClaimDetailsMetricsInjectionToken,
});

const statefulSetDetailsMetricsInjectable = getInjectable({
id: "stateful-set-details-metrics-injectable",
instantiate: () => ({
id: "stateful-set-details-metrics",
Component: StatefulSetMetricsDetailsComponent,
}),
injectionToken: statefulSetDetailsMetricsInjectionToken,
});

const namespaceDetailsMetricsInjectable = getInjectable({
id: "namespace-details-metrics-injectable",
instantiate: () => ({
id: "namespace-details-metrics",
Component: NamespaceMetricsDetailsComponent,
}),
injectionToken: namespaceDetailsMetricsInjectionToken,
});

const jobDetailsMetricsInjectable = getInjectable({
id: "job-details-metrics-injectable",
instantiate: () => ({
id: "job-details-metrics",
Component: JobMetricsDetailsComponent,
}),
injectionToken: jobDetailsMetricsInjectionToken,
});

const daemonSetDetailsMetricsInjectable = getInjectable({
id: "daemon-set-details-metrics-injectable",
instantiate: () => ({
id: "daemon-set-details-metrics",
Component: DaemonSetMetricsDetailsComponent,
}),
injectionToken: daemonSetDetailsMetricsInjectionToken,
});

const ingressDetailsMetricsInjectable = getInjectable({
id: "network-ingress-details-metrics-injectable",
instantiate: () => ({
id: "network-ingress-details-metrics",
Component: IngressMetricsDetailsComponent,
}),
injectionToken: ingressDetailsMetricsInjectionToken,
});

export const metricsFeature = getFeature({
id: "core-metrics-feature",

register: (di) => {
di.register(clusterPieChartsClusterOverviewInjectable);
di.register(clusterMetricsOverviewBlockInjectable);

di.register(podDetailsMetricsInjectable);
di.register(podDetailsContainerMetricsInjectable);
di.register(deploymentDetailsMetricsInjectable);
di.register(nodeDetailsMetricsInjectable);
di.register(replicaSetDetailsMetricsInjectable);
di.register(persistentVolumeClaimDetailsMetricsInjectable);
di.register(statefulSetDetailsMetricsInjectable);
di.register(namespaceDetailsMetricsInjectable);
di.register(jobDetailsMetricsInjectable);
di.register(daemonSetDetailsMetricsInjectable);
di.register(ingressDetailsMetricsInjectable);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import { interval } from "@k8slens/utilities";
import { TabLayout } from "../layout/tab-layout";
import { Spinner } from "../spinner";
import { ClusterIssues } from "./cluster-issues";
import { ClusterMetrics } from "./cluster-metrics";
import type { ClusterOverviewStore } from "./cluster-overview-store/cluster-overview-store";
import { ClusterPieCharts } from "./cluster-pie-charts";
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { EventStore } from "../+events/store";
import { withInjectables } from "@ogre-tools/injectable-react";
Expand All @@ -28,6 +26,10 @@ import podStoreInjectable from "../+workloads-pods/store.injectable";
import eventStoreInjectable from "../+events/store.injectable";
import nodeStoreInjectable from "../+nodes/store.injectable";
import enabledMetricsInjectable from "../../api/catalog/entity/metrics-enabled.injectable";
import type { ClusterOverviewUIBlock } from "@k8slens/metrics";
import { clusterOverviewUIBlockInjectionToken } from "@k8slens/metrics";
import { orderByOrderNumber } from "../../../common/utils/composable-responsibilities/orderable/orderable";
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";

interface Dependencies {
subscribeStores: SubscribeStores;
Expand All @@ -36,6 +38,7 @@ interface Dependencies {
eventStore: EventStore;
nodeStore: NodeStore;
clusterMetricsAreVisible: IComputedValue<boolean>;
uiBlocks: IComputedValue<ClusterOverviewUIBlock[]>;
}

@observer
Expand Down Expand Up @@ -76,8 +79,9 @@ class NonInjectedClusterOverview extends React.Component<Dependencies> {

return (
<>
<ClusterMetrics/>
<ClusterPieCharts/>
{orderByOrderNumber(this.props.uiBlocks.get()).map((block) => (
<block.Component key={block.id} />
))}
</>
);
}
Expand Down Expand Up @@ -118,5 +122,6 @@ export const ClusterOverview = withInjectables<Dependencies>(NonInjectedClusterO
podStore: di.inject(podStoreInjectable),
eventStore: di.inject(eventStoreInjectable),
nodeStore: di.inject(nodeStoreInjectable),
uiBlocks: di.inject(computedInjectManyInjectable)(clusterOverviewUIBlockInjectionToken),
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
* 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 type { IAsyncComputed } from "@ogre-tools/injectable-react";
import { withInjectables } from "@ogre-tools/injectable-react";
import React from "react";
import { PodCharts, podMetricTabs } from "../+workloads-pods/pod-charts";
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Namespace } from "../../../common/k8s-api/endpoints";
import type { PodMetricInNamespaceData } from "../../../common/k8s-api/endpoints/metrics.api/request-pod-metrics-in-namespace.injectable";
import metricsDetailsComponentEnabledInjectable from "../../api/catalog/entity/metrics-details-component-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 namespaceMetricsInjectable from "./metrics.injectable";

Expand All @@ -33,21 +29,9 @@ const NonInjectedNamespaceMetricsDetailsComponent = ({
</ResourceMetrics>
);

const NamespaceMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Namespace>>(NonInjectedNamespaceMetricsDetailsComponent, {
export const NamespaceMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Namespace>>(NonInjectedNamespaceMetricsDetailsComponent, {
getProps: (di, props) => ({
metrics: di.inject(namespaceMetricsInjectable, props.object),
...props,
}),
});

const namespaceMetricsDetailsComponentInjectable = getInjectable({
id: "namespace-metrics-details-component",
instantiate: (di) => ({
Component: NamespaceMetricsDetailsComponent,
enabled: di.inject(metricsDetailsComponentEnabledInjectable, ClusterMetricsResourceType.Namespace),
orderNumber: -1,
}),
injectionToken: kubeObjectDetailItemInjectionToken,
});

export default namespaceMetricsDetailsComponentInjectable;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
* 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 type { IAsyncComputed } from "@ogre-tools/injectable-react";
import { withInjectables } from "@ogre-tools/injectable-react";
import React from "react";
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Ingress } from "../../../common/k8s-api/endpoints";
import type { IngressMetricData } from "../../../common/k8s-api/endpoints/metrics.api/request-ingress-metrics.injectable";
import metricsDetailsComponentEnabledInjectable from "../../api/catalog/entity/metrics-details-component-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 { IngressCharts } from "./ingress-charts";
import ingressMetricsInjectable from "./metrics.injectable";
Expand All @@ -36,21 +32,9 @@ const NonInjectedIngressMetricsDetailsComponent = ({
</ResourceMetrics>
);

const IngressMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Ingress>>(NonInjectedIngressMetricsDetailsComponent, {
export const IngressMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Ingress>>(NonInjectedIngressMetricsDetailsComponent, {
getProps: (di, props) => ({
metrics: di.inject(ingressMetricsInjectable, props.object),
...props,
}),
});

const ingressMetricsDetailsComponentInjectable = getInjectable({
id: "ingress-metrics-details-component",
instantiate: (di) => ({
Component: IngressMetricsDetailsComponent,
enabled: di.inject(metricsDetailsComponentEnabledInjectable, ClusterMetricsResourceType.Ingress),
orderNumber: -1,
}),
injectionToken: kubeObjectDetailItemInjectionToken,
});

export default ingressMetricsDetailsComponentInjectable;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
* 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 type { IAsyncComputed } from "@ogre-tools/injectable-react";
import { withInjectables } from "@ogre-tools/injectable-react";
import React from "react";
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Node } from "../../../common/k8s-api/endpoints";
import type { ClusterMetricData } from "../../../common/k8s-api/endpoints/metrics.api/request-cluster-metrics-by-node-names.injectable";
import metricsDetailsComponentEnabledInjectable from "../../api/catalog/entity/metrics-details-component-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 nodeMetricsInjectable from "./metrics.injectable";
import { NodeCharts } from "./node-charts";
Expand All @@ -38,21 +34,9 @@ const NonInjectedNodeMetricsDetailsComponent = ({
</ResourceMetrics>
);

const NodeMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Node>>(NonInjectedNodeMetricsDetailsComponent, {
export const NodeMetricsDetailsComponent = withInjectables<Dependencies, KubeObjectDetailsProps<Node>>(NonInjectedNodeMetricsDetailsComponent, {
getProps: (di, props) => ({
metrics: di.inject(nodeMetricsInjectable, props.object),
...props,
}),
});

const nodeMetricsDetailsComponentInjectable = getInjectable({
id: "node-metrics-details-component",
instantiate: (di) => ({
Component: NodeMetricsDetailsComponent,
enabled: di.inject(metricsDetailsComponentEnabledInjectable, ClusterMetricsResourceType.Node),
orderNumber: -1,
}),
injectionToken: kubeObjectDetailItemInjectionToken,
});

export default nodeMetricsDetailsComponentInjectable;
Loading

0 comments on commit 53cb3a5

Please sign in to comment.