Skip to content

Commit 0859353

Browse files
committed
unit tests
1 parent e31b035 commit 0859353

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

internal/store/pod_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,14 @@ func TestPodStore(t *testing.T) {
649649
},
650650
},
651651
Want: `
652+
# HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state.
652653
# HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state.
653654
# HELP kube_pod_container_status_running Describes whether the container is currently in running state.
654655
# HELP kube_pod_container_status_terminated Describes whether the container is currently in terminated state.
655656
# HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state.
656657
# HELP kube_pod_container_status_waiting Describes whether the container is currently in waiting state.
657658
# HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state.
659+
# TYPE kube_pod_container_status_last_terminated_exitcode gauge
658660
# TYPE kube_pod_container_status_last_terminated_reason gauge
659661
# TYPE kube_pod_container_status_running gauge
660662
# TYPE kube_pod_container_status_terminated gauge
@@ -679,6 +681,10 @@ func TestPodStore(t *testing.T) {
679681
"kube_pod_container_status_last_terminated_reason",
680682
"kube_pod_container_status_last_terminated_reason",
681683
"kube_pod_container_status_last_terminated_reason",
684+
"kube_pod_container_status_last_terminated_exitcode",
685+
"kube_pod_container_status_last_terminated_exitcode",
686+
"kube_pod_container_status_last_terminated_exitcode",
687+
"kube_pod_container_status_last_terminated_exitcode",
682688
},
683689
},
684690
{
@@ -720,13 +726,15 @@ func TestPodStore(t *testing.T) {
720726
},
721727
Want: `
722728
# HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state.
729+
# HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state.
723730
# HELP kube_pod_container_status_running Describes whether the container is currently in running state.
724731
# HELP kube_pod_container_status_terminated Describes whether the container is currently in terminated state.
725732
# HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state.
726733
# HELP kube_pod_container_status_waiting Describes whether the container is currently in waiting state.
727734
# HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state.
728735
# HELP kube_pod_container_state_started Start time in unix timestamp for a pod container.
729736
# TYPE kube_pod_container_status_last_terminated_reason gauge
737+
# TYPE kube_pod_container_status_last_terminated_exitcode gauge
730738
# TYPE kube_pod_container_status_running gauge
731739
# TYPE kube_pod_container_status_terminated gauge
732740
# TYPE kube_pod_container_status_terminated_reason gauge
@@ -737,10 +745,12 @@ func TestPodStore(t *testing.T) {
737745
kube_pod_container_state_started{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 1.501777018e+09
738746
kube_pod_container_status_terminated{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 0
739747
kube_pod_container_status_waiting{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 0
740-
kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6",exitcode="137"} 1
748+
kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6"} 1
749+
kube_pod_container_status_last_terminated_exitcode{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6"} 137
741750
`,
742751
MetricNames: []string{
743752
"kube_pod_container_status_last_terminated_reason",
753+
"kube_pod_container_status_last_terminated_exitcode",
744754
"kube_pod_container_status_running",
745755
"kube_pod_container_state_started",
746756
"kube_pod_container_status_terminated",
@@ -785,13 +795,15 @@ func TestPodStore(t *testing.T) {
785795
},
786796
},
787797
Want: `
798+
# HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state.
788799
# HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state.
789800
# HELP kube_pod_container_status_running Describes whether the container is currently in running state.
790801
# HELP kube_pod_container_state_started Start time in unix timestamp for a pod container.
791802
# HELP kube_pod_container_status_terminated Describes whether the container is currently in terminated state.
792803
# HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state.
793804
# HELP kube_pod_container_status_waiting Describes whether the container is currently in waiting state.
794805
# HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state.
806+
# TYPE kube_pod_container_status_last_terminated_exitcode gauge
795807
# TYPE kube_pod_container_status_last_terminated_reason gauge
796808
# TYPE kube_pod_container_status_running gauge
797809
# TYPE kube_pod_container_state_started gauge
@@ -800,7 +812,8 @@ func TestPodStore(t *testing.T) {
800812
# TYPE kube_pod_container_status_waiting gauge
801813
# TYPE kube_pod_container_status_waiting_reason gauge
802814
kube_pod_container_state_started{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 1.501777018e+09
803-
kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7",exitcode="143"} 1
815+
kube_pod_container_status_last_terminated_exitcode{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7"} 143
816+
kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7"} 1
804817
kube_pod_container_status_running{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 1
805818
kube_pod_container_status_terminated{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 0
806819
kube_pod_container_status_waiting{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 0
@@ -812,6 +825,7 @@ func TestPodStore(t *testing.T) {
812825
"kube_pod_container_status_terminated_reason",
813826
"kube_pod_container_status_waiting",
814827
"kube_pod_container_status_last_terminated_reason",
828+
"kube_pod_container_status_last_terminated_exitcode",
815829
},
816830
},
817831
{

pkg/app/server_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func TestFullScrapeCycle(t *testing.T) {
196196
# HELP kube_pod_container_resource_limits The number of requested limit resource by a container.
197197
# HELP kube_pod_container_resource_requests The number of requested request resource by a container.
198198
# HELP kube_pod_container_state_started Start time in unix timestamp for a pod container.
199+
# HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state.
199200
# HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state.
200201
# HELP kube_pod_container_status_ready Describes whether the containers readiness check succeeded.
201202
# HELP kube_pod_container_status_restarts_total The number of container restarts per container.
@@ -241,6 +242,7 @@ func TestFullScrapeCycle(t *testing.T) {
241242
# TYPE kube_pod_container_resource_limits gauge
242243
# TYPE kube_pod_container_resource_requests gauge
243244
# TYPE kube_pod_container_state_started gauge
245+
# TYPE kube_pod_container_status_last_terminated_exitcode gauge
244246
# TYPE kube_pod_container_status_last_terminated_reason gauge
245247
# TYPE kube_pod_container_status_ready gauge
246248
# TYPE kube_pod_container_status_restarts_total counter
@@ -297,7 +299,8 @@ kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",
297299
kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",node="node1",resource="storage",unit="byte"} 4e+08
298300
kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2",node="node1",resource="cpu",unit="core"} 0.3
299301
kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2",node="node1",resource="memory",unit="byte"} 2e+08
300-
kube_pod_container_status_last_terminated_reason{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled",exitcode="137"} 1
302+
kube_pod_container_status_last_terminated_exitcode{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled"} 137
303+
kube_pod_container_status_last_terminated_reason{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled"} 1
301304
kube_pod_container_status_ready{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1"} 0
302305
kube_pod_container_status_ready{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2"} 0
303306
kube_pod_container_status_restarts_total{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1"} 0

0 commit comments

Comments
 (0)