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

External target metrics

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-01-16 12:11:05 +03:00
parent 525d439e7c
commit ecdf6667cf
2 changed files with 74 additions and 3 deletions

View File

@ -130,5 +130,65 @@ describe("HorizontalPodAutoscalerApi", () => {
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 10k");
});
it("should return correct external metrics with average value", () => {
const hpa = new HorizontalPodAutoscaler(
{
...hpaV2,
spec: {
...hpaV2.spec,
metrics: [
{
type: HpaMetricType.External,
external: {
metric: {
name: "queue_messages_ready",
selector: {
matchLabels: {queue: 'worker_tasks'}
}
},
target: {
type: "AverageValue",
averageValue: "30"
}
}
}
]
}
}
);
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 30 (avg)");
});
it("should return correct external metrics with value", () => {
const hpa = new HorizontalPodAutoscaler(
{
...hpaV2,
spec: {
...hpaV2.spec,
metrics: [
{
type: HpaMetricType.External,
external: {
metric: {
name: "queue_messages_ready",
selector: {
matchLabels: {queue: 'worker_tasks'}
}
},
target: {
type: "Value",
value: "30"
}
}
}
]
}
}
);
expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 30");
});
});
});

View File

@ -37,10 +37,21 @@ export interface ContainerResourceMetricSource {
}
export interface ExternalMetricSource {
metricName: string;
metricName?: string;
metricSelector?: LabelSelector;
targetAverageValue?: string;
targetValue?: string;
// autoscaling/v2
metric?: {
name?: string;
selector?: LabelSelector;
},
target?: {
type: string;
value?: string;
averageValue?: string;
}
}
export interface ObjectMetricSource {
@ -364,8 +375,8 @@ function getExternalMetricValue(currentMetric: ExternalMetricStatus | undefined,
?? currentMetric?.currentAverageValue
),
target: (
targetMetric?.targetValue
?? targetMetric?.targetAverageValue
targetMetric?.target?.value
?? `${targetMetric?.target?.averageValue} (avg)`
),
};
}