From 93d2db6e9221b77b093d09a2be0c278b8b83c9d6 Mon Sep 17 00:00:00 2001 From: j4ckstraw Date: Tue, 30 Jan 2024 09:27:53 +0800 Subject: [PATCH] add test for koordlet metric Signed-off-by: j4ckstraw --- pkg/koordlet/metrics/metrics_test.go | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/koordlet/metrics/metrics_test.go b/pkg/koordlet/metrics/metrics_test.go index 20d887c4c..2f6b619da 100644 --- a/pkg/koordlet/metrics/metrics_test.go +++ b/pkg/koordlet/metrics/metrics_test.go @@ -163,12 +163,16 @@ func TestResourceSummaryCollectors(t *testing.T) { corev1.ResourceMemory: resource.MustParse("200Gi"), apiext.BatchCPU: resource.MustParse("50000"), apiext.BatchMemory: resource.MustParse("80Gi"), + apiext.MidCPU: resource.MustParse("50000"), + apiext.MidMemory: resource.MustParse("80Gi"), }, Capacity: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("100"), corev1.ResourceMemory: resource.MustParse("200Gi"), apiext.BatchCPU: resource.MustParse("50000"), apiext.BatchMemory: resource.MustParse("80Gi"), + apiext.MidCPU: resource.MustParse("50000"), + apiext.MidMemory: resource.MustParse("80Gi"), }, }, } @@ -236,6 +240,38 @@ func TestResourceSummaryCollectors(t *testing.T) { }, }, } + testingMidPod := &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test_mid_pod", + Namespace: "test_mid_pod_namespace", + UID: "mid01", + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "test_mid_container", + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + apiext.MidCPU: resource.MustParse("1000"), + apiext.MidMemory: resource.MustParse("2Gi"), + }, + Limits: corev1.ResourceList{ + apiext.MidCPU: resource.MustParse("1000"), + apiext.MidMemory: resource.MustParse("2Gi"), + }, + }, + }, + }, + }, + Status: corev1.PodStatus{ + ContainerStatuses: []corev1.ContainerStatus{ + { + Name: "test_mid_container", + ContainerID: "containerd://midxxx", + }, + }, + }, + } t.Run("test not panic", func(t *testing.T) { Register(testingNode) @@ -247,8 +283,12 @@ func TestResourceSummaryCollectors(t *testing.T) { RecordContainerResourceRequests(string(corev1.ResourceMemory), UnitByte, &testingPod.Status.ContainerStatuses[0], testingPod, float64(testingPod.Spec.Containers[0].Resources.Requests.Memory().Value())) RecordContainerResourceRequests(string(apiext.BatchCPU), UnitInteger, &testingBatchPod.Status.ContainerStatuses[0], testingBatchPod, float64(util.QuantityPtr(testingBatchPod.Spec.Containers[0].Resources.Requests[apiext.BatchCPU]).Value())) RecordContainerResourceRequests(string(apiext.BatchMemory), UnitByte, &testingBatchPod.Status.ContainerStatuses[0], testingBatchPod, float64(util.QuantityPtr(testingBatchPod.Spec.Containers[0].Resources.Requests[apiext.BatchMemory]).Value())) + RecordContainerResourceRequests(string(apiext.MidCPU), UnitInteger, &testingMidPod.Status.ContainerStatuses[0], testingMidPod, float64(util.QuantityPtr(testingMidPod.Spec.Containers[0].Resources.Requests[apiext.MidCPU]).Value())) + RecordContainerResourceRequests(string(apiext.MidMemory), UnitByte, &testingMidPod.Status.ContainerStatuses[0], testingMidPod, float64(util.QuantityPtr(testingMidPod.Spec.Containers[0].Resources.Requests[apiext.MidMemory]).Value())) RecordContainerResourceLimits(string(apiext.BatchCPU), UnitInteger, &testingBatchPod.Status.ContainerStatuses[0], testingBatchPod, float64(util.QuantityPtr(testingBatchPod.Spec.Containers[0].Resources.Limits[apiext.BatchCPU]).Value())) RecordContainerResourceLimits(string(apiext.BatchMemory), UnitByte, &testingBatchPod.Status.ContainerStatuses[0], testingBatchPod, float64(util.QuantityPtr(testingBatchPod.Spec.Containers[0].Resources.Limits[apiext.BatchMemory]).Value())) + RecordContainerResourceLimits(string(apiext.MidCPU), UnitInteger, &testingMidPod.Status.ContainerStatuses[0], testingMidPod, float64(util.QuantityPtr(testingMidPod.Spec.Containers[0].Resources.Limits[apiext.MidCPU]).Value())) + RecordContainerResourceLimits(string(apiext.MidMemory), UnitByte, &testingMidPod.Status.ContainerStatuses[0], testingMidPod, float64(util.QuantityPtr(testingMidPod.Spec.Containers[0].Resources.Limits[apiext.MidMemory]).Value())) ResetContainerResourceRequests() ResetContainerResourceLimits()