mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Using metrics parser in hpa list and details
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
7f70c49a5c
commit
cb807d843e
@ -17,6 +17,11 @@ export enum HpaMetricType {
|
||||
ContainerResource = "ContainerResource",
|
||||
}
|
||||
|
||||
export interface MetricCurrentTarget {
|
||||
current?: string;
|
||||
target?: string;
|
||||
}
|
||||
|
||||
export interface HorizontalPodAutoscalerMetricTarget {
|
||||
kind: string;
|
||||
name: string;
|
||||
|
||||
@ -22,6 +22,7 @@ import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable";
|
||||
import getDetailsUrlInjectable from "../kube-detail-params/get-details-url.injectable";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import getHorizontalPodAutoscalerMetrics from "./get-hpa-metrics.injectable";
|
||||
|
||||
export interface HpaDetailsProps extends KubeObjectDetailsProps<HorizontalPodAutoscaler> {
|
||||
}
|
||||
@ -30,6 +31,7 @@ interface Dependencies {
|
||||
apiManager: ApiManager;
|
||||
logger: Logger;
|
||||
getDetailsUrl: GetDetailsUrl;
|
||||
getMetrics: (hpa: HorizontalPodAutoscaler) => string[];
|
||||
}
|
||||
|
||||
@observer
|
||||
@ -70,19 +72,19 @@ class NonInjectedHpaDetails extends React.Component<HpaDetailsProps & Dependenci
|
||||
return `Resource ${metricSpec.name} on Pods${addition}`;
|
||||
}
|
||||
case HpaMetricType.Pods:
|
||||
return `${metric.pods.metricName} on Pods`;
|
||||
return `${metric.pods.metricName ?? metric.pods.metric?.name} on Pods`;
|
||||
|
||||
case HpaMetricType.Object: {
|
||||
return (
|
||||
<>
|
||||
{metric.object.metricName}
|
||||
{metric.object.metricName || metric.object.metric?.name}
|
||||
{" "}
|
||||
{this.renderTargetLink(metric.object.target)}
|
||||
{this.renderTargetLink(metric.object.describedObject)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
case HpaMetricType.External:
|
||||
return `${metric.external.metricName} on ${JSON.stringify(metric.external.metricSelector)}`;
|
||||
return `${metric.external.metricName ?? metric.external.metric?.name} on ${JSON.stringify(metric.external.metricSelector ?? metric.external.metric?.selector)}`;
|
||||
}
|
||||
};
|
||||
|
||||
@ -93,11 +95,11 @@ class NonInjectedHpaDetails extends React.Component<HpaDetailsProps & Dependenci
|
||||
<TableCell className="metrics">Current / Target</TableCell>
|
||||
</TableHead>
|
||||
{
|
||||
hpa.getMetrics()
|
||||
.map((metric, index) => (
|
||||
this.props.getMetrics(hpa)
|
||||
.map((metrics, index) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell className="name">{renderName(metric)}</TableCell>
|
||||
<TableCell className="metrics">{hpa.getMetricValues(metric)}</TableCell>
|
||||
<TableCell className="name">{renderName(hpa.getMetrics()[index])}</TableCell>
|
||||
<TableCell className="metrics">{metrics}</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
}
|
||||
@ -175,5 +177,6 @@ export const HpaDetails = withInjectables<Dependencies, HpaDetailsProps>(NonInje
|
||||
apiManager: di.inject(apiManagerInjectable),
|
||||
getDetailsUrl: di.inject(getDetailsUrlInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
getMetrics: di.inject(getHorizontalPodAutoscalerMetrics),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -19,6 +19,7 @@ import type { FilterByNamespace } from "../+namespaces/namespace-select-filter-m
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import filterByNamespaceInjectable from "../+namespaces/namespace-select-filter-model/filter-by-namespace.injectable";
|
||||
import horizontalPodAutoscalerStoreInjectable from "./store.injectable";
|
||||
import getHorizontalPodAutoscalerMetrics from "./get-hpa-metrics.injectable";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
@ -34,6 +35,7 @@ enum columnId {
|
||||
interface Dependencies {
|
||||
horizontalPodAutoscalerStore: HorizontalPodAutoscalerStore;
|
||||
filterByNamespace: FilterByNamespace;
|
||||
getMetrics: (hpa: HorizontalPodAutoscaler) => string[];
|
||||
}
|
||||
|
||||
@observer
|
||||
@ -49,7 +51,7 @@ class NonInjectedHorizontalPodAutoscalers extends React.Component<Dependencies>
|
||||
|
||||
return (
|
||||
<p>
|
||||
{hpa.getMetricValues(metrics[0])}
|
||||
{this.props.getMetrics(hpa)[0]}
|
||||
{" "}
|
||||
{metricsRemain}
|
||||
</p>
|
||||
@ -126,5 +128,6 @@ export const HorizontalPodAutoscalers = withInjectables<Dependencies>(NonInjecte
|
||||
...props,
|
||||
filterByNamespace: di.inject(filterByNamespaceInjectable),
|
||||
horizontalPodAutoscalerStore: di.inject(horizontalPodAutoscalerStoreInjectable),
|
||||
getMetrics: di.inject(getHorizontalPodAutoscalerMetrics),
|
||||
}),
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user