Skip to content

Commit

Permalink
add test for koordlet metric
Browse files Browse the repository at this point in the history
Signed-off-by: j4ckstraw <j4ckstraw@foxmail.com>
  • Loading branch information
j4ckstraw committed Jan 30, 2024
1 parent 623f38d commit 93d2db6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/koordlet/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit 93d2db6

Please sign in to comment.