mirror of
https://github.com/lensapp/lens.git
synced 2024-09-11 09:25:26 +03:00
Updating PodDetailsContainerMetrics to support fetching metrics for Pods that have multiple containers
Signed-off-by: John Daly <john.daly2@gmail.com>
This commit is contained in:
parent
4ab97d2372
commit
6e8e58eaf9
@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { MetricData } from "../metrics.api";
|
||||
import type { Pod } from "@k8slens/kube-object";
|
||||
import type { Pod, Container } from "@k8slens/kube-object";
|
||||
import requestMetricsInjectable from "./request-metrics.injectable";
|
||||
|
||||
export interface PodMetricData {
|
||||
@ -21,16 +21,16 @@ export interface PodMetricData {
|
||||
memoryLimits: MetricData;
|
||||
}
|
||||
|
||||
export type RequestPodMetrics = (pods: Pod[], namespace: string, selector?: string) => Promise<PodMetricData>;
|
||||
export type RequestPodMetrics = (pods: Pod[], namespace: string, container?: Container, selector?: string) => Promise<PodMetricData>;
|
||||
|
||||
const requestPodMetricsInjectable = getInjectable({
|
||||
id: "request-pod-metrics",
|
||||
instantiate: (di): RequestPodMetrics => {
|
||||
const requestMetrics = di.inject(requestMetricsInjectable);
|
||||
|
||||
return (pods, namespace, selector = "pod, namespace") => {
|
||||
return (pods, namespace, container, selector = "pod, namespace") => {
|
||||
const podSelector = pods.map(pod => pod.getName()).join("|");
|
||||
const opts = { category: "pods", pods: podSelector, namespace, selector };
|
||||
const opts = { category: "pods", pods: podSelector, container: container?.name, namespace, selector };
|
||||
|
||||
return requestMetrics({
|
||||
cpuUsage: opts,
|
||||
|
@ -5,9 +5,14 @@
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
import { now } from "mobx-utils";
|
||||
import type { Pod } from "@k8slens/kube-object";
|
||||
import type { Pod, Container } from "@k8slens/kube-object";
|
||||
import requestPodMetricsInjectable from "../../../common/k8s-api/endpoints/metrics.api/request-pod-metrics.injectable";
|
||||
|
||||
interface PodContainerParams {
|
||||
pod: Pod;
|
||||
container: Container;
|
||||
}
|
||||
|
||||
const podContainerMetricsInjectable = getInjectable({
|
||||
id: "pod-container-metrics",
|
||||
instantiate: (di, pod) => {
|
||||
@ -17,12 +22,14 @@ const podContainerMetricsInjectable = getInjectable({
|
||||
getValueFromObservedPromise: () => {
|
||||
now(60 * 1000);
|
||||
|
||||
return requestPodMetrics([pod], pod.getNs(), "container, namespace");
|
||||
return requestPodMetrics([pod], pod.getNs(), container, "pod, container, namespace");
|
||||
},
|
||||
});
|
||||
},
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, pod: Pod) => pod.getId(),
|
||||
getInstanceKey: (di, { pod, container }: PodContainerParams) => {
|
||||
return `${pod.getId()}-${container.name}`;
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
|
@ -48,6 +48,6 @@ const NonInjectedPodDetailsContainerMetrics = observer(({ pod, container, podCon
|
||||
export const PodDetailsContainerMetrics = withInjectables<Dependencies, ContainerMetricsProps>(NonInjectedPodDetailsContainerMetrics, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
podContainerMetrics: di.inject(podContainerMetricsInjectable, props.pod),
|
||||
podContainerMetrics: di.inject(podContainerMetricsInjectable, { pod: props.pod, container: props.container }),
|
||||
}),
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user