1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Linter fixes

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-01-18 15:05:26 +03:00
parent 739d8af85b
commit 0472371532
7 changed files with 338 additions and 311 deletions

View File

@ -37,7 +37,7 @@ export interface ContainerResourceMetricSource {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
type?: string; type?: string;
} };
} }
export interface ExternalMetricSource { export interface ExternalMetricSource {
@ -48,12 +48,12 @@ export interface ExternalMetricSource {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
}, };
target?: { target?: {
type: string; type: string;
value?: string; value?: string;
averageValue?: string; averageValue?: string;
} };
} }
export interface ObjectMetricSource { export interface ObjectMetricSource {
@ -63,13 +63,13 @@ export interface ObjectMetricSource {
targetValue?: string; targetValue?: string;
metric?: { metric?: {
name?: string; name?: string;
}, };
target?: { target?: {
type?: string; type?: string;
value?: string; value?: string;
averageValue?: string; averageValue?: string;
}; };
describedObject?: CrossVersionObjectReference describedObject?: CrossVersionObjectReference;
} }
export interface PodsMetricSource { export interface PodsMetricSource {
@ -78,11 +78,11 @@ export interface PodsMetricSource {
targetAverageValue?: string; targetAverageValue?: string;
metric?: { metric?: {
name?: string; name?: string;
} };
target?: { target?: {
averageValue?: string; averageValue?: string;
type?: string; type?: string;
} };
} }
export interface ResourceMetricSource { export interface ResourceMetricSource {
@ -93,7 +93,7 @@ export interface ResourceMetricSource {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
type?: string; type?: string;
} };
} }
export interface BaseHorizontalPodAutoscalerMetricSpec { export interface BaseHorizontalPodAutoscalerMetricSpec {
@ -140,7 +140,7 @@ export interface ContainerResourceMetricStatus {
current?: { current?: {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
} };
} }
export interface ExternalMetricStatus { export interface ExternalMetricStatus {
@ -151,11 +151,11 @@ export interface ExternalMetricStatus {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
}, };
current?: { current?: {
averageValue?: string; averageValue?: string;
value?: string; value?: string;
} };
} }
export interface ObjectMetricStatus { export interface ObjectMetricStatus {
@ -166,7 +166,7 @@ export interface ObjectMetricStatus {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
}, };
current?: { current?: {
type?: string; type?: string;
value?: string; value?: string;
@ -181,10 +181,10 @@ export interface PodsMetricStatus {
selector?: LabelSelector; selector?: LabelSelector;
metric?: { metric?: {
name?: string; name?: string;
} };
current?: { current?: {
averageValue?: string; averageValue?: string;
} };
} }
export interface ResourceMetricStatus { export interface ResourceMetricStatus {
@ -194,7 +194,7 @@ export interface ResourceMetricStatus {
current?: { current?: {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
} };
} }
export interface BaseHorizontalPodAutoscalerMetricStatus { export interface BaseHorizontalPodAutoscalerMetricStatus {

View File

@ -1,5 +1,10 @@
/**
* 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 { getInjectable } from "@ogre-tools/injectable";
import { HorizontalPodAutoscaler, HorizontalPodAutoscalerMetricSpec, HorizontalPodAutoscalerMetricStatus, HpaMetricType } from "../../../common/k8s-api/endpoints"; import type { HorizontalPodAutoscaler, HorizontalPodAutoscalerMetricSpec, HorizontalPodAutoscalerMetricStatus } from "../../../common/k8s-api/endpoints";
import { HpaMetricType } from "../../../common/k8s-api/endpoints";
import horizonalPodAutoscalerV1MetricParser from "./hpa-v1-metric-parser.injectable"; import horizonalPodAutoscalerV1MetricParser from "./hpa-v1-metric-parser.injectable";
import type { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser"; import type { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser";
import horizonalPodAutoscalerV2MetricParser from "./hpa-v2-metric-parser.injectable"; import horizonalPodAutoscalerV2MetricParser from "./hpa-v2-metric-parser.injectable";
@ -16,13 +21,14 @@ const getHorizontalPodAutoscalerMetrics = getInjectable({
if (cpuUtilization) { if (cpuUtilization) {
const utilizationCurrent = hpa.status?.currentCPUUtilizationPercentage ? `${hpa.status.currentCPUUtilizationPercentage}%` : "unknown"; const utilizationCurrent = hpa.status?.currentCPUUtilizationPercentage ? `${hpa.status.currentCPUUtilizationPercentage}%` : "unknown";
const utilizationTarget = cpuUtilization ? `${cpuUtilization}%` : "unknown"; const utilizationTarget = cpuUtilization ? `${cpuUtilization}%` : "unknown";
return [`${utilizationCurrent} / ${utilizationTarget}`]; return [`${utilizationCurrent} / ${utilizationTarget}`];
} }
return metrics.map((metric) => { return metrics.map((metric) => {
const currentMetric = currentMetrics.find(current => const currentMetric = currentMetrics.find(current =>
current.type === metric.type current.type === metric.type
&& getMetricName(current) === getMetricName(metric) && getMetricName(current) === getMetricName(metric),
); );
const h2Values = getMetricValues(hpaV2Parser, currentMetric, metric); const h2Values = getMetricValues(hpaV2Parser, currentMetric, metric);
@ -36,12 +42,12 @@ const getHorizontalPodAutoscalerMetrics = getInjectable({
return `${values.current ?? "unknown"} / ${values.target ?? "unknown"}`; return `${values.current ?? "unknown"} / ${values.target ?? "unknown"}`;
}); });
}, },
}) });
function getMetricValues(parser: HorizontalPodAutoscalerV2MetricParser, current: HorizontalPodAutoscalerMetricStatus | undefined, target: HorizontalPodAutoscalerMetricSpec) { function getMetricValues(parser: HorizontalPodAutoscalerV2MetricParser, current: HorizontalPodAutoscalerMetricStatus | undefined, target: HorizontalPodAutoscalerMetricSpec) {
switch (target.type) { switch (target.type) {
case HpaMetricType.Resource: case HpaMetricType.Resource:
return parser.getResource({ current: current?.resource, target: target.resource}); return parser.getResource({ current: current?.resource, target: target.resource });
case HpaMetricType.Pods: case HpaMetricType.Pods:
return parser.getPods({ current: current?.pods, target: target.pods }); return parser.getPods({ current: current?.pods, target: target.pods });
case HpaMetricType.Object: case HpaMetricType.Object:
@ -72,4 +78,4 @@ function getMetricName(metric: HorizontalPodAutoscalerMetricSpec | HorizontalPod
} }
} }
export default getHorizontalPodAutoscalerMetrics; export default getHorizontalPodAutoscalerMetrics;

View File

@ -1,3 +1,7 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import getHorizontalPodAutoscalerMetrics from "./get-hpa-metrics.injectable"; import getHorizontalPodAutoscalerMetrics from "./get-hpa-metrics.injectable";
import { getDiForUnitTesting } from "../../getDiForUnitTesting"; import { getDiForUnitTesting } from "../../getDiForUnitTesting";
@ -19,9 +23,9 @@ const hpaV2 = {
kind: "Deployment", kind: "Deployment",
name: "hpav2deployment", name: "hpav2deployment",
apiVersion: "apps/v1", apiVersion: "apps/v1",
} },
} },
} };
const hpaV2Beta1 = { const hpaV2Beta1 = {
apiVersion: "autoscaling/v2beta1", apiVersion: "autoscaling/v2beta1",
@ -41,7 +45,7 @@ const hpaV2Beta1 = {
apiVersion: "apps/v1", apiVersion: "apps/v1",
}, },
}, },
} };
// const hpaV2Beta2 = { // const hpaV2Beta2 = {
// ...hpaV2Beta1, // ...hpaV2Beta1,
@ -77,12 +81,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "cpu", name: "cpu",
target: { target: {
type: "Utilization", type: "Utilization",
averageUtilization: 50 averageUtilization: 50,
} },
} },
} },
] ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
@ -100,11 +104,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "cpu", name: "cpu",
target: { target: {
type: "Utilization", type: "Utilization",
averageUtilization: 50 averageUtilization: 50,
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -116,12 +120,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "cpu", name: "cpu",
current: { current: {
averageValue: "100m", averageValue: "100m",
averageUtilization: 10 averageUtilization: 10,
} },
} },
} },
], ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("10% / 50%"); expect(getMetrics(hpa)[0]).toEqual("10% / 50%");
@ -139,11 +143,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "cpu", name: "cpu",
target: { target: {
type: "Value", type: "Value",
averageValue: "100m" averageValue: "100m",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -155,11 +159,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "cpu", name: "cpu",
current: { current: {
averageValue: "500m", averageValue: "500m",
} },
} },
} },
], ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("500m / 100m"); expect(getMetrics(hpa)[0]).toEqual("500m / 100m");
@ -180,12 +184,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
target: { target: {
type: "Utilization", type: "Utilization",
averageUtilization: 60, averageUtilization: 60,
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 60%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 60%");
@ -205,11 +209,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
container: "nginx", container: "nginx",
target: { target: {
type: "Utilization", type: "Utilization",
averageUtilization: 60 averageUtilization: 60,
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -220,13 +224,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
containerResource: { containerResource: {
name: "cpu", name: "cpu",
current: { current: {
averageUtilization: 10 averageUtilization: 10,
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10% / 60%"); expect(getMetrics(hpa)[0]).toEqual("10% / 60%");
@ -243,17 +247,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Pods, type: HpaMetricType.Pods,
pods: { pods: {
metric: { metric: {
name: "packets-per-second" name: "packets-per-second",
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "1k" averageValue: "1k",
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 1k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 1k");
@ -270,15 +274,15 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Pods, type: HpaMetricType.Pods,
pods: { pods: {
metric: { metric: {
name: "packets-per-second" name: "packets-per-second",
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "1k" averageValue: "1k",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -291,13 +295,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "packets-per-second", name: "packets-per-second",
}, },
current: { current: {
averageValue: "10" averageValue: "10",
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 / 1k"); expect(getMetrics(hpa)[0]).toEqual("10 / 1k");
@ -314,17 +318,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metric: { metric: {
name: "requests-per-second" name: "requests-per-second",
}, },
target: { target: {
type: "Value", type: "Value",
value: "10k" value: "10k",
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 10k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 10k");
@ -341,17 +345,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metric: { metric: {
name: "requests-per-second" name: "requests-per-second",
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "5k" averageValue: "5k",
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 5k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 5k");
@ -368,15 +372,15 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metric: { metric: {
name: "requests-per-second" name: "requests-per-second",
}, },
target: { target: {
type: "Value", type: "Value",
value: "5k" value: "5k",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -389,13 +393,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "requests-per-second", name: "requests-per-second",
}, },
current: { current: {
value: "10k" value: "10k",
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10k / 5k"); expect(getMetrics(hpa)[0]).toEqual("10k / 5k");
@ -414,18 +418,18 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
metric: { metric: {
name: "queue_messages_ready", name: "queue_messages_ready",
selector: { selector: {
matchLabels: {queue: 'worker_tasks'} matchLabels: { queue: "worker_tasks" },
} },
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "30" averageValue: "30",
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)"); expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)");
@ -444,18 +448,18 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
metric: { metric: {
name: "queue_messages_ready", name: "queue_messages_ready",
selector: { selector: {
matchLabels: {queue: 'worker_tasks'} matchLabels: { queue: "worker_tasks" },
} },
}, },
target: { target: {
type: "Value", type: "Value",
value: "30" value: "30",
} },
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); expect(getMetrics(hpa)[0]).toEqual("unknown / 30");
@ -474,16 +478,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
metric: { metric: {
name: "queue_messages_ready", name: "queue_messages_ready",
selector: { selector: {
matchLabels: {queue: 'worker_tasks'} matchLabels: { queue: "worker_tasks" },
} },
}, },
target: { target: {
type: "Value", type: "Value",
value: "30" value: "30",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -496,13 +500,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "queue_messages_ready", name: "queue_messages_ready",
}, },
current: { current: {
value: "10" value: "10",
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 / 30"); expect(getMetrics(hpa)[0]).toEqual("10 / 30");
@ -521,16 +525,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
metric: { metric: {
name: "queue_messages_ready", name: "queue_messages_ready",
selector: { selector: {
matchLabels: {queue: 'worker_tasks'} matchLabels: { queue: "worker_tasks" },
} },
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "30" averageValue: "30",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -543,13 +547,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "queue_messages_ready", name: "queue_messages_ready",
}, },
current: { current: {
averageValue: "10" averageValue: "10",
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 (avg) / 30 (avg)"); expect(getMetrics(hpa)[0]).toEqual("10 (avg) / 30 (avg)");
@ -568,16 +572,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
metric: { metric: {
name: "queue_messages_ready", name: "queue_messages_ready",
selector: { selector: {
matchLabels: {queue: 'worker_tasks'} matchLabels: { queue: "worker_tasks" },
} },
}, },
target: { target: {
type: "AverageValue", type: "AverageValue",
averageValue: "30" averageValue: "30",
} },
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -590,13 +594,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "queue_messages_NOT_ready", name: "queue_messages_NOT_ready",
}, },
current: { current: {
averageValue: "10" averageValue: "10",
} },
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)"); expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)");
@ -620,11 +624,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
targetAverageUtilization: 50 targetAverageUtilization: 50,
} },
} },
] ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
@ -640,10 +644,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
targetAverageUtilization: 50 targetAverageUtilization: 50,
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -653,11 +657,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
currentAverageUtilization: 10 currentAverageUtilization: 10,
} },
} },
], ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("10% / 50%"); expect(getMetrics(hpa)[0]).toEqual("10% / 50%");
@ -673,10 +677,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
targetAverageValue: "100m" targetAverageValue: "100m",
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -686,11 +690,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
currentAverageValue: "500m" currentAverageValue: "500m",
} },
} },
], ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("500m / 100m"); expect(getMetrics(hpa)[0]).toEqual("500m / 100m");
@ -708,12 +712,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
containerResource: { containerResource: {
name: "cpu", name: "cpu",
container: "nginx", container: "nginx",
targetAverageUtilization: 60 targetAverageUtilization: 60,
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 60%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 60%");
@ -731,10 +735,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
containerResource: { containerResource: {
name: "cpu", name: "cpu",
container: "nginx", container: "nginx",
targetAverageUtilization: 60 targetAverageUtilization: 60,
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -744,12 +748,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.ContainerResource, type: HpaMetricType.ContainerResource,
containerResource: { containerResource: {
name: "cpu", name: "cpu",
currentAverageUtilization: 10 currentAverageUtilization: 10,
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10% / 60%"); expect(getMetrics(hpa)[0]).toEqual("10% / 60%");
@ -766,12 +770,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Pods, type: HpaMetricType.Pods,
pods: { pods: {
metricName: "packets-per-second", metricName: "packets-per-second",
targetAverageValue: "1k" targetAverageValue: "1k",
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 1k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 1k");
@ -789,10 +793,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
pods: { pods: {
metricName: "packets-per-second", metricName: "packets-per-second",
targetAverageValue: "1k" targetAverageValue: "1k",
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -802,12 +806,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Pods, type: HpaMetricType.Pods,
pods: { pods: {
metricName: "packets-per-second", metricName: "packets-per-second",
currentAverageValue: "10" currentAverageValue: "10",
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 / 1k"); expect(getMetrics(hpa)[0]).toEqual("10 / 1k");
@ -824,12 +828,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metricName: "packets-per-second", metricName: "packets-per-second",
targetValue: "10k" targetValue: "10k",
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 10k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 10k");
@ -846,12 +850,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metricName: "packets-per-second", metricName: "packets-per-second",
averageValue: "5k" averageValue: "5k",
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 5k"); expect(getMetrics(hpa)[0]).toEqual("unknown / 5k");
@ -868,10 +872,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metricName: "packets-per-second", metricName: "packets-per-second",
targetValue: "5k" targetValue: "5k",
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -881,12 +885,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Object, type: HpaMetricType.Object,
object: { object: {
metricName: "packets-per-second", metricName: "packets-per-second",
currentValue: "10k" currentValue: "10k",
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10k / 5k"); expect(getMetrics(hpa)[0]).toEqual("10k / 5k");
@ -903,13 +907,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
metricSelector: { matchLabels: {queue: 'worker_tasks'} }, metricSelector: { matchLabels: { queue: "worker_tasks" }},
targetAverageValue: "30" targetAverageValue: "30",
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); expect(getMetrics(hpa)[0]).toEqual("unknown / 30");
@ -926,13 +930,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
metricSelector: { matchLabels: {queue: 'worker_tasks'} }, metricSelector: { matchLabels: { queue: "worker_tasks" }},
targetValue: "30" targetValue: "30",
} },
} },
] ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); expect(getMetrics(hpa)[0]).toEqual("unknown / 30");
@ -949,11 +953,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
metricSelector: { matchLabels: {queue: 'worker_tasks'} }, metricSelector: { matchLabels: { queue: "worker_tasks" }},
targetValue: "30" targetValue: "30",
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -963,12 +967,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
currentValue: "10" currentValue: "10",
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 / 30"); expect(getMetrics(hpa)[0]).toEqual("10 / 30");
@ -985,11 +989,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
metricSelector: { matchLabels: {queue: 'worker_tasks'} }, metricSelector: { matchLabels: { queue: "worker_tasks" }},
targetAverageValue: "30" targetAverageValue: "30",
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -999,12 +1003,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.External, type: HpaMetricType.External,
external: { external: {
metricName: "queue_messages_ready", metricName: "queue_messages_ready",
currentAverageValue: "10" currentAverageValue: "10",
} },
} },
], ],
} },
} },
); );
expect(getMetrics(hpa)[0]).toEqual("10 / 30"); expect(getMetrics(hpa)[0]).toEqual("10 / 30");
@ -1020,10 +1024,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "cpu", name: "cpu",
targetAverageUtilization: 50 targetAverageUtilization: 50,
} },
} },
] ],
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
@ -1033,11 +1037,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
type: HpaMetricType.Resource, type: HpaMetricType.Resource,
resource: { resource: {
name: "memory", name: "memory",
currentAverageUtilization: 10 currentAverageUtilization: 10,
} },
} },
], ],
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%");
@ -1063,8 +1067,8 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "hpav1deployment", name: "hpav1deployment",
apiVersion: "apps/v1", apiVersion: "apps/v1",
}, },
targetCPUUtilizationPercentage: 80 targetCPUUtilizationPercentage: 80,
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("unknown / 80%"); expect(getMetrics(hpa)[0]).toEqual("unknown / 80%");
@ -1088,16 +1092,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => {
name: "hpav1deployment", name: "hpav1deployment",
apiVersion: "apps/v1", apiVersion: "apps/v1",
}, },
targetCPUUtilizationPercentage: 80 targetCPUUtilizationPercentage: 80,
}, },
status: { status: {
currentReplicas: 1, currentReplicas: 1,
desiredReplicas: 10, desiredReplicas: 10,
currentCPUUtilizationPercentage: 10 currentCPUUtilizationPercentage: 10,
} },
}); });
expect(getMetrics(hpa)[0]).toEqual("10% / 80%"); expect(getMetrics(hpa)[0]).toEqual("10% / 80%");
}); });
}); });
}); });

View File

@ -1,3 +1,7 @@
/**
* 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 { getInjectable } from "@ogre-tools/injectable";
import { HorizontalPodAutoscalerV1MetricParser } from "./hpa-v1-metric-parser"; import { HorizontalPodAutoscalerV1MetricParser } from "./hpa-v1-metric-parser";
@ -6,6 +10,6 @@ const horizonalPodAutoscalerV1MetricParser = getInjectable({
instantiate: () => { instantiate: () => {
return new HorizontalPodAutoscalerV1MetricParser(); return new HorizontalPodAutoscalerV1MetricParser();
}, },
}) });
export default horizonalPodAutoscalerV1MetricParser; export default horizonalPodAutoscalerV1MetricParser;

View File

@ -1,7 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints"; import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints";
export class HorizontalPodAutoscalerV1MetricParser { export class HorizontalPodAutoscalerV1MetricParser {
public getResource({ current, target }: { current: ResourceMetricStatus | undefined, target: ResourceMetricSource }): MetricCurrentTarget { public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.currentAverageUtilization === "number" typeof current?.currentAverageUtilization === "number"
@ -16,14 +20,14 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getPods({ current, target }: { current: PodsMetricStatus | undefined, target: PodsMetricSource }): MetricCurrentTarget { public getPods({ current, target }: { current: PodsMetricStatus | undefined; target: PodsMetricSource }): MetricCurrentTarget {
return { return {
current: current?.currentAverageValue, current: current?.currentAverageValue,
target: target?.targetAverageValue, target: target?.targetAverageValue,
}; };
} }
public getObject({ current, target }: { current: ObjectMetricStatus | undefined, target: ObjectMetricSource }): MetricCurrentTarget { public getObject({ current, target }: { current: ObjectMetricStatus | undefined; target: ObjectMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.currentValue current?.currentValue
@ -36,7 +40,7 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getExternal({ current, target }: { current: ExternalMetricStatus | undefined, target: ExternalMetricSource }): MetricCurrentTarget { public getExternal({ current, target }: { current: ExternalMetricStatus | undefined; target: ExternalMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.currentValue current?.currentValue
@ -49,7 +53,7 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined, target: ContainerResourceMetricSource }): MetricCurrentTarget { public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined; target: ContainerResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.currentAverageUtilization === "number" typeof current?.currentAverageUtilization === "number"
@ -63,4 +67,4 @@ export class HorizontalPodAutoscalerV1MetricParser {
), ),
}; };
} }
} }

View File

@ -1,3 +1,7 @@
/**
* 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 { getInjectable } from "@ogre-tools/injectable";
import { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser"; import { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser";
@ -6,6 +10,6 @@ const horizonalPodAutoscalerV2MetricParser = getInjectable({
instantiate: () => { instantiate: () => {
return new HorizontalPodAutoscalerV2MetricParser(); return new HorizontalPodAutoscalerV2MetricParser();
}, },
}) });
export default horizonalPodAutoscalerV2MetricParser; export default horizonalPodAutoscalerV2MetricParser;

View File

@ -1,7 +1,11 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints"; import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints";
export class HorizontalPodAutoscalerV2MetricParser { export class HorizontalPodAutoscalerV2MetricParser {
public getResource({ current, target }: { current: ResourceMetricStatus | undefined, target: ResourceMetricSource }): MetricCurrentTarget { public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.current?.averageUtilization === "number" typeof current?.current?.averageUtilization === "number"
@ -9,19 +13,19 @@ export class HorizontalPodAutoscalerV2MetricParser {
: current?.current?.averageValue : current?.current?.averageValue
), ),
target: typeof target?.target?.averageUtilization === "number" target: typeof target?.target?.averageUtilization === "number"
? `${target.target.averageUtilization}%` ? `${target.target.averageUtilization}%`
: target?.target?.averageValue : target?.target?.averageValue,
}; };
} }
public getPods({ current, target }: { current: PodsMetricStatus | undefined, target: PodsMetricSource }): MetricCurrentTarget { public getPods({ current, target }: { current: PodsMetricStatus | undefined; target: PodsMetricSource }): MetricCurrentTarget {
return { return {
current: current?.current?.averageValue, current: current?.current?.averageValue,
target: target?.target?.averageValue, target: target?.target?.averageValue,
} };
} }
public getObject({ current, target }: { current: ObjectMetricStatus | undefined, target: ObjectMetricSource }): MetricCurrentTarget { public getObject({ current, target }: { current: ObjectMetricStatus | undefined; target: ObjectMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.current?.value current?.current?.value
@ -30,13 +34,14 @@ export class HorizontalPodAutoscalerV2MetricParser {
target: ( target: (
target?.target?.value target?.target?.value
?? target?.target?.averageValue ?? target?.target?.averageValue
) ),
}; };
} }
public getExternal({ current, target }: { current: ExternalMetricStatus | undefined, target: ExternalMetricSource }): MetricCurrentTarget { public getExternal({ current, target }: { current: ExternalMetricStatus | undefined; target: ExternalMetricSource }): MetricCurrentTarget {
const currentAverage = current?.current?.averageValue ? `${current?.current?.averageValue} (avg)` : undefined; const currentAverage = current?.current?.averageValue ? `${current?.current?.averageValue} (avg)` : undefined;
const targetAverage = target?.target?.averageValue ? `${target?.target?.averageValue} (avg)` : undefined; const targetAverage = target?.target?.averageValue ? `${target?.target?.averageValue} (avg)` : undefined;
return { return {
current: ( current: (
current?.current?.value current?.current?.value
@ -49,7 +54,7 @@ export class HorizontalPodAutoscalerV2MetricParser {
}; };
} }
public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined, target: ContainerResourceMetricSource }): MetricCurrentTarget { public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined; target: ContainerResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.current?.averageValue current?.current?.averageValue
@ -61,4 +66,4 @@ export class HorizontalPodAutoscalerV2MetricParser {
), ),
}; };
} }
} }