mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add more types for ObjectMetricStatus
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
ecdf6667cf
commit
25b594de7e
@ -51,6 +51,45 @@ describe("HorizontalPodAutoscalerApi", () => {
|
|||||||
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 50%");
|
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 50%");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return correct resource metrics with current metrics", () => {
|
||||||
|
const hpa = new HorizontalPodAutoscaler({
|
||||||
|
...hpaV2,
|
||||||
|
spec: {
|
||||||
|
...hpaV2.spec,
|
||||||
|
metrics: [
|
||||||
|
{
|
||||||
|
type: HpaMetricType.Resource,
|
||||||
|
resource: {
|
||||||
|
name: "cpu",
|
||||||
|
target: {
|
||||||
|
type: "Utilization",
|
||||||
|
averageUtilization: 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
currentReplicas: 1,
|
||||||
|
desiredReplicas: 10,
|
||||||
|
currentMetrics: [
|
||||||
|
{
|
||||||
|
type: HpaMetricType.Resource,
|
||||||
|
resource: {
|
||||||
|
name: "cpu",
|
||||||
|
current: {
|
||||||
|
averageValue: "100m",
|
||||||
|
averageUtilization: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("10% / 50%");
|
||||||
|
});
|
||||||
|
|
||||||
it("should return correct container resource metrics", () => {
|
it("should return correct container resource metrics", () => {
|
||||||
const hpa = new HorizontalPodAutoscaler(
|
const hpa = new HorizontalPodAutoscaler(
|
||||||
{
|
{
|
||||||
|
|||||||
@ -94,6 +94,7 @@ export interface ResourceMetricSource {
|
|||||||
// autoscaling/v2
|
// autoscaling/v2
|
||||||
target?: {
|
target?: {
|
||||||
averageUtilization?: number;
|
averageUtilization?: number;
|
||||||
|
averageValue?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,9 +152,18 @@ export interface ExternalMetricStatus {
|
|||||||
export interface ObjectMetricStatus {
|
export interface ObjectMetricStatus {
|
||||||
averageValue?: string;
|
averageValue?: string;
|
||||||
currentValue?: string;
|
currentValue?: string;
|
||||||
metricName: string;
|
metricName?: string;
|
||||||
selector?: LabelSelector;
|
selector?: LabelSelector;
|
||||||
target: CrossVersionObjectReference;
|
|
||||||
|
// autoscaling/v2
|
||||||
|
metric?: {
|
||||||
|
name?: string;
|
||||||
|
},
|
||||||
|
current: {
|
||||||
|
type?: string;
|
||||||
|
value?: string;
|
||||||
|
};
|
||||||
|
describedObject?: CrossVersionObjectReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PodsMetricStatus {
|
export interface PodsMetricStatus {
|
||||||
@ -164,8 +174,14 @@ export interface PodsMetricStatus {
|
|||||||
|
|
||||||
export interface ResourceMetricStatus {
|
export interface ResourceMetricStatus {
|
||||||
currentAverageUtilization?: number;
|
currentAverageUtilization?: number;
|
||||||
currentAverageValue: string;
|
currentAverageValue?: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
// autoscaling/v2
|
||||||
|
current?: {
|
||||||
|
averageUtilization?: number;
|
||||||
|
averageValue?: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseHorizontalPodAutoscalerMetricStatus {
|
export interface BaseHorizontalPodAutoscalerMetricStatus {
|
||||||
@ -325,23 +341,15 @@ function getMetricName(metric: HorizontalPodAutoscalerMetricSpec | HorizontalPod
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getResourceMetricValue(currentMetric: ResourceMetricStatus | undefined, targetMetric: ResourceMetricSource): MetricCurrentTarget {
|
function getResourceMetricValue(currentMetric: ResourceMetricStatus | undefined, targetMetric: ResourceMetricSource): MetricCurrentTarget {
|
||||||
let target = "unknown";
|
|
||||||
|
|
||||||
if (targetMetric.target) {
|
|
||||||
target = targetMetric.target.averageUtilization ? `${targetMetric.target.averageUtilization}%` : "unknown";
|
|
||||||
} else {
|
|
||||||
target = typeof targetMetric?.targetAverageUtilization === "number"
|
|
||||||
? `${targetMetric.targetAverageUtilization}%`
|
|
||||||
: targetMetric?.targetAverageValue ?? "unknown";
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
current: (
|
current: (
|
||||||
typeof currentMetric?.currentAverageUtilization === "number"
|
typeof currentMetric?.current?.averageUtilization === "number"
|
||||||
? `${currentMetric.currentAverageUtilization}%`
|
? `${currentMetric.current?.averageUtilization}%`
|
||||||
: currentMetric?.currentAverageValue
|
: currentMetric?.current?.averageValue
|
||||||
),
|
),
|
||||||
target,
|
target: typeof targetMetric?.target?.averageUtilization === "number"
|
||||||
|
? `${targetMetric.target.averageUtilization}%`
|
||||||
|
: targetMetric?.target?.averageValue ?? "unknown"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user