diff --git a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts index c335a68ce6..36e54786da 100644 --- a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts +++ b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts @@ -37,7 +37,7 @@ export interface ContainerResourceMetricSource { averageUtilization?: number; averageValue?: string; type?: string; - } + }; } export interface ExternalMetricSource { @@ -48,12 +48,12 @@ export interface ExternalMetricSource { metric?: { name?: string; selector?: LabelSelector; - }, + }; target?: { type: string; value?: string; averageValue?: string; - } + }; } export interface ObjectMetricSource { @@ -63,13 +63,13 @@ export interface ObjectMetricSource { targetValue?: string; metric?: { name?: string; - }, + }; target?: { type?: string; value?: string; averageValue?: string; }; - describedObject?: CrossVersionObjectReference + describedObject?: CrossVersionObjectReference; } export interface PodsMetricSource { @@ -78,11 +78,11 @@ export interface PodsMetricSource { targetAverageValue?: string; metric?: { name?: string; - } + }; target?: { averageValue?: string; type?: string; - } + }; } export interface ResourceMetricSource { @@ -93,7 +93,7 @@ export interface ResourceMetricSource { averageUtilization?: number; averageValue?: string; type?: string; - } + }; } export interface BaseHorizontalPodAutoscalerMetricSpec { @@ -140,7 +140,7 @@ export interface ContainerResourceMetricStatus { current?: { averageUtilization?: number; averageValue?: string; - } + }; } export interface ExternalMetricStatus { @@ -151,11 +151,11 @@ export interface ExternalMetricStatus { metric?: { name?: string; selector?: LabelSelector; - }, + }; current?: { averageValue?: string; value?: string; - } + }; } export interface ObjectMetricStatus { @@ -166,7 +166,7 @@ export interface ObjectMetricStatus { metric?: { name?: string; selector?: LabelSelector; - }, + }; current?: { type?: string; value?: string; @@ -181,10 +181,10 @@ export interface PodsMetricStatus { selector?: LabelSelector; metric?: { name?: string; - } + }; current?: { averageValue?: string; - } + }; } export interface ResourceMetricStatus { @@ -194,7 +194,7 @@ export interface ResourceMetricStatus { current?: { averageUtilization?: number; averageValue?: string; - } + }; } export interface BaseHorizontalPodAutoscalerMetricStatus { diff --git a/src/renderer/components/+config-autoscalers/get-hpa-metrics.injectable.ts b/src/renderer/components/+config-autoscalers/get-hpa-metrics.injectable.ts index 6e80c6ec01..d343c43241 100644 --- a/src/renderer/components/+config-autoscalers/get-hpa-metrics.injectable.ts +++ b/src/renderer/components/+config-autoscalers/get-hpa-metrics.injectable.ts @@ -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 { 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 type { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser"; import horizonalPodAutoscalerV2MetricParser from "./hpa-v2-metric-parser.injectable"; @@ -16,13 +21,14 @@ const getHorizontalPodAutoscalerMetrics = getInjectable({ if (cpuUtilization) { const utilizationCurrent = hpa.status?.currentCPUUtilizationPercentage ? `${hpa.status.currentCPUUtilizationPercentage}%` : "unknown"; const utilizationTarget = cpuUtilization ? `${cpuUtilization}%` : "unknown"; + return [`${utilizationCurrent} / ${utilizationTarget}`]; } return metrics.map((metric) => { const currentMetric = currentMetrics.find(current => current.type === metric.type - && getMetricName(current) === getMetricName(metric) + && getMetricName(current) === getMetricName(metric), ); const h2Values = getMetricValues(hpaV2Parser, currentMetric, metric); @@ -36,12 +42,12 @@ const getHorizontalPodAutoscalerMetrics = getInjectable({ return `${values.current ?? "unknown"} / ${values.target ?? "unknown"}`; }); }, -}) +}); function getMetricValues(parser: HorizontalPodAutoscalerV2MetricParser, current: HorizontalPodAutoscalerMetricStatus | undefined, target: HorizontalPodAutoscalerMetricSpec) { switch (target.type) { case HpaMetricType.Resource: - return parser.getResource({ current: current?.resource, target: target.resource}); + return parser.getResource({ current: current?.resource, target: target.resource }); case HpaMetricType.Pods: return parser.getPods({ current: current?.pods, target: target.pods }); case HpaMetricType.Object: @@ -72,4 +78,4 @@ function getMetricName(metric: HorizontalPodAutoscalerMetricSpec | HorizontalPod } } -export default getHorizontalPodAutoscalerMetrics; \ No newline at end of file +export default getHorizontalPodAutoscalerMetrics; diff --git a/src/renderer/components/+config-autoscalers/horizontal-pod-autoscaler-metrics.test.ts b/src/renderer/components/+config-autoscalers/horizontal-pod-autoscaler-metrics.test.ts index 6ba168b8a7..026e2eff2f 100644 --- a/src/renderer/components/+config-autoscalers/horizontal-pod-autoscaler-metrics.test.ts +++ b/src/renderer/components/+config-autoscalers/horizontal-pod-autoscaler-metrics.test.ts @@ -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 getHorizontalPodAutoscalerMetrics from "./get-hpa-metrics.injectable"; import { getDiForUnitTesting } from "../../getDiForUnitTesting"; @@ -19,9 +23,9 @@ const hpaV2 = { kind: "Deployment", name: "hpav2deployment", apiVersion: "apps/v1", - } - } -} + }, + }, +}; const hpaV2Beta1 = { apiVersion: "autoscaling/v2beta1", @@ -41,7 +45,7 @@ const hpaV2Beta1 = { apiVersion: "apps/v1", }, }, -} +}; // const hpaV2Beta2 = { // ...hpaV2Beta1, @@ -77,12 +81,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "cpu", target: { type: "Utilization", - averageUtilization: 50 - } - } - } - ] - } + averageUtilization: 50, + }, + }, + }, + ], + }, }); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); @@ -100,11 +104,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "cpu", target: { type: "Utilization", - averageUtilization: 50 - } - } - } - ] + averageUtilization: 50, + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -116,12 +120,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "cpu", current: { averageValue: "100m", - averageUtilization: 10 - } - } - } + averageUtilization: 10, + }, + }, + }, ], - } + }, }); expect(getMetrics(hpa)[0]).toEqual("10% / 50%"); @@ -139,11 +143,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "cpu", target: { type: "Value", - averageValue: "100m" - } - } - } - ] + averageValue: "100m", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -155,11 +159,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "cpu", current: { averageValue: "500m", - } - } - } + }, + }, + }, ], - } + }, }); expect(getMetrics(hpa)[0]).toEqual("500m / 100m"); @@ -180,12 +184,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { target: { type: "Utilization", averageUtilization: 60, - } - } - } - ] - } - } + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 60%"); @@ -205,11 +209,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { container: "nginx", target: { type: "Utilization", - averageUtilization: 60 - } - } - } - ] + averageUtilization: 60, + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -220,13 +224,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { containerResource: { name: "cpu", current: { - averageUtilization: 10 - } - } - } + averageUtilization: 10, + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10% / 60%"); @@ -243,17 +247,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Pods, pods: { metric: { - name: "packets-per-second" + name: "packets-per-second", }, target: { type: "AverageValue", - averageValue: "1k" - } - } - } - ] - } - } + averageValue: "1k", + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 1k"); @@ -270,15 +274,15 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Pods, pods: { metric: { - name: "packets-per-second" + name: "packets-per-second", }, target: { type: "AverageValue", - averageValue: "1k" - } - } - } - ] + averageValue: "1k", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -291,13 +295,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "packets-per-second", }, current: { - averageValue: "10" - } - } - } + averageValue: "10", + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 / 1k"); @@ -314,17 +318,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metric: { - name: "requests-per-second" + name: "requests-per-second", }, target: { type: "Value", - value: "10k" - } - } - } - ] - } - } + value: "10k", + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 10k"); @@ -341,17 +345,17 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metric: { - name: "requests-per-second" + name: "requests-per-second", }, target: { type: "AverageValue", - averageValue: "5k" - } - } - } - ] - } - } + averageValue: "5k", + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 5k"); @@ -368,15 +372,15 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metric: { - name: "requests-per-second" + name: "requests-per-second", }, target: { type: "Value", - value: "5k" - } - } - } - ] + value: "5k", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -389,13 +393,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "requests-per-second", }, current: { - value: "10k" - } - } - } + value: "10k", + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10k / 5k"); @@ -414,18 +418,18 @@ describe("getHorizontalPodAutoscalerMetrics", () => { metric: { name: "queue_messages_ready", selector: { - matchLabels: {queue: 'worker_tasks'} - } + matchLabels: { queue: "worker_tasks" }, + }, }, target: { type: "AverageValue", - averageValue: "30" - } - } - } - ] - } - } + averageValue: "30", + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)"); @@ -444,18 +448,18 @@ describe("getHorizontalPodAutoscalerMetrics", () => { metric: { name: "queue_messages_ready", selector: { - matchLabels: {queue: 'worker_tasks'} - } + matchLabels: { queue: "worker_tasks" }, + }, }, target: { type: "Value", - value: "30" - } - } - } - ] - } - } + value: "30", + }, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); @@ -474,16 +478,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => { metric: { name: "queue_messages_ready", selector: { - matchLabels: {queue: 'worker_tasks'} - } + matchLabels: { queue: "worker_tasks" }, + }, }, target: { type: "Value", - value: "30" - } - } - } - ] + value: "30", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -496,13 +500,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "queue_messages_ready", }, current: { - value: "10" - } - } - } + value: "10", + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 / 30"); @@ -521,16 +525,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => { metric: { name: "queue_messages_ready", selector: { - matchLabels: {queue: 'worker_tasks'} - } + matchLabels: { queue: "worker_tasks" }, + }, }, target: { type: "AverageValue", - averageValue: "30" - } - } - } - ] + averageValue: "30", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -543,13 +547,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "queue_messages_ready", }, current: { - averageValue: "10" - } - } - } + averageValue: "10", + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 (avg) / 30 (avg)"); @@ -568,16 +572,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => { metric: { name: "queue_messages_ready", selector: { - matchLabels: {queue: 'worker_tasks'} - } + matchLabels: { queue: "worker_tasks" }, + }, }, target: { type: "AverageValue", - averageValue: "30" - } - } - } - ] + averageValue: "30", + }, + }, + }, + ], }, status: { currentReplicas: 1, @@ -590,13 +594,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "queue_messages_NOT_ready", }, current: { - averageValue: "10" - } - } - } + averageValue: "10", + }, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 30 (avg)"); @@ -620,11 +624,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - targetAverageUtilization: 50 - } - } - ] - } + targetAverageUtilization: 50, + }, + }, + ], + }, }); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); @@ -640,10 +644,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - targetAverageUtilization: 50 - } - } - ] + targetAverageUtilization: 50, + }, + }, + ], }, status: { currentReplicas: 1, @@ -653,11 +657,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - currentAverageUtilization: 10 - } - } + currentAverageUtilization: 10, + }, + }, ], - } + }, }); expect(getMetrics(hpa)[0]).toEqual("10% / 50%"); @@ -673,10 +677,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - targetAverageValue: "100m" - } - } - ] + targetAverageValue: "100m", + }, + }, + ], }, status: { currentReplicas: 1, @@ -686,11 +690,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - currentAverageValue: "500m" - } - } + currentAverageValue: "500m", + }, + }, ], - } + }, }); expect(getMetrics(hpa)[0]).toEqual("500m / 100m"); @@ -708,12 +712,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { containerResource: { name: "cpu", container: "nginx", - targetAverageUtilization: 60 - } - } - ] - } - } + targetAverageUtilization: 60, + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 60%"); @@ -731,10 +735,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { containerResource: { name: "cpu", container: "nginx", - targetAverageUtilization: 60 - } - } - ] + targetAverageUtilization: 60, + }, + }, + ], }, status: { currentReplicas: 1, @@ -744,12 +748,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.ContainerResource, containerResource: { name: "cpu", - currentAverageUtilization: 10 - } - } + currentAverageUtilization: 10, + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10% / 60%"); @@ -766,12 +770,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Pods, pods: { metricName: "packets-per-second", - targetAverageValue: "1k" - } - } - ] - } - } + targetAverageValue: "1k", + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 1k"); @@ -789,10 +793,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { pods: { metricName: "packets-per-second", - targetAverageValue: "1k" - } - } - ] + targetAverageValue: "1k", + }, + }, + ], }, status: { currentReplicas: 1, @@ -802,12 +806,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Pods, pods: { metricName: "packets-per-second", - currentAverageValue: "10" - } - } + currentAverageValue: "10", + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 / 1k"); @@ -824,12 +828,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metricName: "packets-per-second", - targetValue: "10k" - } - } - ] - } - } + targetValue: "10k", + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 10k"); @@ -846,12 +850,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metricName: "packets-per-second", - averageValue: "5k" - } - } - ] - } - } + averageValue: "5k", + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 5k"); @@ -868,10 +872,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metricName: "packets-per-second", - targetValue: "5k" - } - } - ] + targetValue: "5k", + }, + }, + ], }, status: { currentReplicas: 1, @@ -881,12 +885,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Object, object: { metricName: "packets-per-second", - currentValue: "10k" - } - } + currentValue: "10k", + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10k / 5k"); @@ -903,13 +907,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - metricSelector: { matchLabels: {queue: 'worker_tasks'} }, - targetAverageValue: "30" - } - } - ] - } - } + metricSelector: { matchLabels: { queue: "worker_tasks" }}, + targetAverageValue: "30", + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); @@ -926,13 +930,13 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - metricSelector: { matchLabels: {queue: 'worker_tasks'} }, - targetValue: "30" - } - } - ] - } - } + metricSelector: { matchLabels: { queue: "worker_tasks" }}, + targetValue: "30", + }, + }, + ], + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("unknown / 30"); @@ -949,11 +953,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - metricSelector: { matchLabels: {queue: 'worker_tasks'} }, - targetValue: "30" - } - } - ] + metricSelector: { matchLabels: { queue: "worker_tasks" }}, + targetValue: "30", + }, + }, + ], }, status: { currentReplicas: 1, @@ -963,12 +967,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - currentValue: "10" - } - } + currentValue: "10", + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 / 30"); @@ -985,11 +989,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - metricSelector: { matchLabels: {queue: 'worker_tasks'} }, - targetAverageValue: "30" - } - } - ] + metricSelector: { matchLabels: { queue: "worker_tasks" }}, + targetAverageValue: "30", + }, + }, + ], }, status: { currentReplicas: 1, @@ -999,12 +1003,12 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.External, external: { metricName: "queue_messages_ready", - currentAverageValue: "10" - } - } + currentAverageValue: "10", + }, + }, ], - } - } + }, + }, ); expect(getMetrics(hpa)[0]).toEqual("10 / 30"); @@ -1020,10 +1024,10 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "cpu", - targetAverageUtilization: 50 - } - } - ] + targetAverageUtilization: 50, + }, + }, + ], }, status: { currentReplicas: 1, @@ -1033,11 +1037,11 @@ describe("getHorizontalPodAutoscalerMetrics", () => { type: HpaMetricType.Resource, resource: { name: "memory", - currentAverageUtilization: 10 - } - } + currentAverageUtilization: 10, + }, + }, ], - } + }, }); expect(getMetrics(hpa)[0]).toEqual("unknown / 50%"); @@ -1063,8 +1067,8 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "hpav1deployment", apiVersion: "apps/v1", }, - targetCPUUtilizationPercentage: 80 - } + targetCPUUtilizationPercentage: 80, + }, }); expect(getMetrics(hpa)[0]).toEqual("unknown / 80%"); @@ -1088,16 +1092,16 @@ describe("getHorizontalPodAutoscalerMetrics", () => { name: "hpav1deployment", apiVersion: "apps/v1", }, - targetCPUUtilizationPercentage: 80 + targetCPUUtilizationPercentage: 80, }, status: { currentReplicas: 1, desiredReplicas: 10, - currentCPUUtilizationPercentage: 10 - } + currentCPUUtilizationPercentage: 10, + }, }); expect(getMetrics(hpa)[0]).toEqual("10% / 80%"); }); }); -}); \ No newline at end of file +}); diff --git a/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.injectable.ts b/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.injectable.ts index 346c6baade..69b305d6c1 100644 --- a/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.injectable.ts +++ b/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.injectable.ts @@ -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 { HorizontalPodAutoscalerV1MetricParser } from "./hpa-v1-metric-parser"; @@ -6,6 +10,6 @@ const horizonalPodAutoscalerV1MetricParser = getInjectable({ instantiate: () => { return new HorizontalPodAutoscalerV1MetricParser(); }, -}) +}); -export default horizonalPodAutoscalerV1MetricParser; \ No newline at end of file +export default horizonalPodAutoscalerV1MetricParser; diff --git a/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.ts b/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.ts index 4fa7554f47..68aa200144 100644 --- a/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.ts +++ b/src/renderer/components/+config-autoscalers/hpa-v1-metric-parser.ts @@ -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"; export class HorizontalPodAutoscalerV1MetricParser { - public getResource({ current, target }: { current: ResourceMetricStatus | undefined, target: ResourceMetricSource }): MetricCurrentTarget { + public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget { return { current: ( 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 { current: current?.currentAverageValue, target: target?.targetAverageValue, }; } - public getObject({ current, target }: { current: ObjectMetricStatus | undefined, target: ObjectMetricSource }): MetricCurrentTarget { + public getObject({ current, target }: { current: ObjectMetricStatus | undefined; target: ObjectMetricSource }): MetricCurrentTarget { return { current: ( 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 { current: ( 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 { current: ( typeof current?.currentAverageUtilization === "number" @@ -63,4 +67,4 @@ export class HorizontalPodAutoscalerV1MetricParser { ), }; } -} \ No newline at end of file +} diff --git a/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.injectable.ts b/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.injectable.ts index e34a3ebd2f..3b52ffeb60 100644 --- a/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.injectable.ts +++ b/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.injectable.ts @@ -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 { HorizontalPodAutoscalerV2MetricParser } from "./hpa-v2-metric-parser"; @@ -6,6 +10,6 @@ const horizonalPodAutoscalerV2MetricParser = getInjectable({ instantiate: () => { return new HorizontalPodAutoscalerV2MetricParser(); }, -}) +}); -export default horizonalPodAutoscalerV2MetricParser; \ No newline at end of file +export default horizonalPodAutoscalerV2MetricParser; diff --git a/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.ts b/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.ts index 643da8d326..4adb6085db 100644 --- a/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.ts +++ b/src/renderer/components/+config-autoscalers/hpa-v2-metric-parser.ts @@ -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"; export class HorizontalPodAutoscalerV2MetricParser { - public getResource({ current, target }: { current: ResourceMetricStatus | undefined, target: ResourceMetricSource }): MetricCurrentTarget { + public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget { return { current: ( typeof current?.current?.averageUtilization === "number" @@ -9,19 +13,19 @@ export class HorizontalPodAutoscalerV2MetricParser { : current?.current?.averageValue ), target: typeof target?.target?.averageUtilization === "number" - ? `${target.target.averageUtilization}%` - : target?.target?.averageValue + ? `${target.target.averageUtilization}%` + : target?.target?.averageValue, }; } - public getPods({ current, target }: { current: PodsMetricStatus | undefined, target: PodsMetricSource }): MetricCurrentTarget { + public getPods({ current, target }: { current: PodsMetricStatus | undefined; target: PodsMetricSource }): MetricCurrentTarget { return { current: current?.current?.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 { current: ( current?.current?.value @@ -30,13 +34,14 @@ export class HorizontalPodAutoscalerV2MetricParser { target: ( target?.target?.value ?? 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 targetAverage = target?.target?.averageValue ? `${target?.target?.averageValue} (avg)` : undefined; + return { current: ( 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 { current: ( current?.current?.averageValue @@ -61,4 +66,4 @@ export class HorizontalPodAutoscalerV2MetricParser { ), }; } -} \ No newline at end of file +}