From 085935314be9817e30a6d656752e88772324ae16 Mon Sep 17 00:00:00 2001 From: Shaun Sabo Date: Fri, 10 Jun 2022 10:40:35 -0700 Subject: [PATCH] unit tests --- internal/store/pod_test.go | 18 ++++++++++++++++-- pkg/app/server_test.go | 5 ++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/store/pod_test.go b/internal/store/pod_test.go index de3901d402..bf1f102ad5 100644 --- a/internal/store/pod_test.go +++ b/internal/store/pod_test.go @@ -649,12 +649,14 @@ func TestPodStore(t *testing.T) { }, }, Want: ` + # HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state. # HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state. # HELP kube_pod_container_status_running Describes whether the container is currently in running state. # HELP kube_pod_container_status_terminated Describes whether the container is currently in terminated state. # HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state. # HELP kube_pod_container_status_waiting Describes whether the container is currently in waiting state. # HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state. + # TYPE kube_pod_container_status_last_terminated_exitcode gauge # TYPE kube_pod_container_status_last_terminated_reason gauge # TYPE kube_pod_container_status_running gauge # TYPE kube_pod_container_status_terminated gauge @@ -679,6 +681,10 @@ func TestPodStore(t *testing.T) { "kube_pod_container_status_last_terminated_reason", "kube_pod_container_status_last_terminated_reason", "kube_pod_container_status_last_terminated_reason", + "kube_pod_container_status_last_terminated_exitcode", + "kube_pod_container_status_last_terminated_exitcode", + "kube_pod_container_status_last_terminated_exitcode", + "kube_pod_container_status_last_terminated_exitcode", }, }, { @@ -720,6 +726,7 @@ func TestPodStore(t *testing.T) { }, Want: ` # HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state. + # HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state. # HELP kube_pod_container_status_running Describes whether the container is currently in running state. # HELP kube_pod_container_status_terminated Describes whether the container is currently in terminated state. # HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state. @@ -727,6 +734,7 @@ func TestPodStore(t *testing.T) { # HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state. # HELP kube_pod_container_state_started Start time in unix timestamp for a pod container. # TYPE kube_pod_container_status_last_terminated_reason gauge + # TYPE kube_pod_container_status_last_terminated_exitcode gauge # TYPE kube_pod_container_status_running gauge # TYPE kube_pod_container_status_terminated gauge # TYPE kube_pod_container_status_terminated_reason gauge @@ -737,10 +745,12 @@ func TestPodStore(t *testing.T) { kube_pod_container_state_started{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 1.501777018e+09 kube_pod_container_status_terminated{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 0 kube_pod_container_status_waiting{container="container7",namespace="ns6",pod="pod6",uid="uid6"} 0 - kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6",exitcode="137"} 1 + kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6"} 1 + kube_pod_container_status_last_terminated_exitcode{container="container7",namespace="ns6",pod="pod6",reason="OOMKilled",uid="uid6"} 137 `, MetricNames: []string{ "kube_pod_container_status_last_terminated_reason", + "kube_pod_container_status_last_terminated_exitcode", "kube_pod_container_status_running", "kube_pod_container_state_started", "kube_pod_container_status_terminated", @@ -785,6 +795,7 @@ func TestPodStore(t *testing.T) { }, }, Want: ` + # HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state. # HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state. # HELP kube_pod_container_status_running Describes whether the container is currently in running state. # HELP kube_pod_container_state_started Start time in unix timestamp for a pod container. @@ -792,6 +803,7 @@ func TestPodStore(t *testing.T) { # HELP kube_pod_container_status_terminated_reason Describes the reason the container is currently in terminated state. # HELP kube_pod_container_status_waiting Describes whether the container is currently in waiting state. # HELP kube_pod_container_status_waiting_reason Describes the reason the container is currently in waiting state. + # TYPE kube_pod_container_status_last_terminated_exitcode gauge # TYPE kube_pod_container_status_last_terminated_reason gauge # TYPE kube_pod_container_status_running gauge # TYPE kube_pod_container_state_started gauge @@ -800,7 +812,8 @@ func TestPodStore(t *testing.T) { # TYPE kube_pod_container_status_waiting gauge # TYPE kube_pod_container_status_waiting_reason gauge kube_pod_container_state_started{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 1.501777018e+09 - kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7",exitcode="143"} 1 + kube_pod_container_status_last_terminated_exitcode{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7"} 143 + kube_pod_container_status_last_terminated_reason{container="container7",namespace="ns7",pod="pod7",reason="DeadlineExceeded",uid="uid7"} 1 kube_pod_container_status_running{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 1 kube_pod_container_status_terminated{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 0 kube_pod_container_status_waiting{container="container7",namespace="ns7",pod="pod7",uid="uid7"} 0 @@ -812,6 +825,7 @@ func TestPodStore(t *testing.T) { "kube_pod_container_status_terminated_reason", "kube_pod_container_status_waiting", "kube_pod_container_status_last_terminated_reason", + "kube_pod_container_status_last_terminated_exitcode", }, }, { diff --git a/pkg/app/server_test.go b/pkg/app/server_test.go index b9d73aef90..35843e080b 100644 --- a/pkg/app/server_test.go +++ b/pkg/app/server_test.go @@ -196,6 +196,7 @@ func TestFullScrapeCycle(t *testing.T) { # HELP kube_pod_container_resource_limits The number of requested limit resource by a container. # HELP kube_pod_container_resource_requests The number of requested request resource by a container. # HELP kube_pod_container_state_started Start time in unix timestamp for a pod container. +# HELP kube_pod_container_status_last_terminated_exitcode Describes the exit code for the last container in terminated state. # HELP kube_pod_container_status_last_terminated_reason Describes the last reason the container was in terminated state. # HELP kube_pod_container_status_ready Describes whether the containers readiness check succeeded. # HELP kube_pod_container_status_restarts_total The number of container restarts per container. @@ -241,6 +242,7 @@ func TestFullScrapeCycle(t *testing.T) { # TYPE kube_pod_container_resource_limits gauge # TYPE kube_pod_container_resource_requests gauge # TYPE kube_pod_container_state_started gauge +# TYPE kube_pod_container_status_last_terminated_exitcode gauge # TYPE kube_pod_container_status_last_terminated_reason gauge # TYPE kube_pod_container_status_ready gauge # TYPE kube_pod_container_status_restarts_total counter @@ -297,7 +299,8 @@ kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0", kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",node="node1",resource="storage",unit="byte"} 4e+08 kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2",node="node1",resource="cpu",unit="core"} 0.3 kube_pod_container_resource_requests{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2",node="node1",resource="memory",unit="byte"} 2e+08 -kube_pod_container_status_last_terminated_reason{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled",exitcode="137"} 1 +kube_pod_container_status_last_terminated_exitcode{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled"} 137 +kube_pod_container_status_last_terminated_reason{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1",reason="OOMKilled"} 1 kube_pod_container_status_ready{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1"} 0 kube_pod_container_status_ready{namespace="default",pod="pod0",uid="abc-0",container="pod1_con2"} 0 kube_pod_container_status_restarts_total{namespace="default",pod="pod0",uid="abc-0",container="pod1_con1"} 0