Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture start time for containers in terminated state #1519

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/store/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ func createPodContainerStateStartedFamilyGenerator() generator.FamilyGenerator {
LabelValues: []string{cs.Name},
Value: float64((cs.State.Running.StartedAt).Unix()),
})
} else if cs.State.Terminated != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"container"},
LabelValues: []string{cs.Name},
Value: float64((cs.State.Terminated.StartedAt).Unix()),
})
}
}

Expand Down
57 changes: 57 additions & 0 deletions internal/store/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,56 @@ func TestPodStore(t *testing.T) {
"kube_pod_init_container_status_terminated_reason",
},
},
{
Obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod1",
Namespace: "ns1",
UID: "uid1",
},
Status: v1.PodStatus{
ContainerStatuses: []v1.ContainerStatus{
{
Name: "container1",
State: v1.ContainerState{
Terminated: &v1.ContainerStateTerminated{
StartedAt: metav1.Time{
Time: time.Unix(1501777018, 0),
},
Reason: "Completed",
},
},
},
},
},
},
Want: `
# 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.
# 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_running gauge
# TYPE kube_pod_container_state_started gauge
# TYPE kube_pod_container_status_terminated gauge
# TYPE kube_pod_container_status_terminated_reason gauge
# TYPE kube_pod_container_status_waiting gauge
# TYPE kube_pod_container_status_waiting_reason gauge
kube_pod_container_state_started{container="container1",namespace="ns1",pod="pod1",uid="uid1"} 1.501777018e+09
kube_pod_container_status_running{container="container1",namespace="ns1",pod="pod1",uid="uid1"} 0
kube_pod_container_status_terminated_reason{container="container1",namespace="ns1",pod="pod1",reason="Completed",uid="uid1"} 1
kube_pod_container_status_terminated{container="container1",namespace="ns1",pod="pod1",uid="uid1"} 1
kube_pod_container_status_waiting{container="container1",namespace="ns1",pod="pod1",uid="uid1"} 0
`,
MetricNames: []string{
"kube_pod_container_status_running",
"kube_pod_container_state_started",
"kube_pod_container_status_waiting",
"kube_pod_container_status_terminated",
"kube_pod_container_status_terminated_reason",
},
},
{
Obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -378,6 +428,9 @@ func TestPodStore(t *testing.T) {
Name: "container2",
State: v1.ContainerState{
Terminated: &v1.ContainerStateTerminated{
StartedAt: metav1.Time{
Time: time.Unix(1501777018, 0),
},
Reason: "OOMKilled",
},
},
Expand All @@ -395,17 +448,20 @@ func TestPodStore(t *testing.T) {
},
Want: `
# 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.
# 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_running gauge
# TYPE kube_pod_container_state_started gauge
# TYPE kube_pod_container_status_terminated gauge
# TYPE kube_pod_container_status_terminated_reason gauge
# TYPE kube_pod_container_status_waiting gauge
# TYPE kube_pod_container_status_waiting_reason gauge
kube_pod_container_status_running{container="container2",namespace="ns2",pod="pod2",uid="uid2"} 0
kube_pod_container_status_running{container="container3",namespace="ns2",pod="pod2",uid="uid2"} 0
kube_pod_container_state_started{container="container2",namespace="ns2",pod="pod2",uid="uid2"} 1.501777018e+09
kube_pod_container_status_terminated_reason{container="container2",namespace="ns2",pod="pod2",reason="OOMKilled",uid="uid2"} 1
kube_pod_container_status_terminated{container="container2",namespace="ns2",pod="pod2",uid="uid2"} 1
kube_pod_container_status_terminated{container="container3",namespace="ns2",pod="pod2",uid="uid2"} 0
Expand All @@ -415,6 +471,7 @@ func TestPodStore(t *testing.T) {
`,
MetricNames: []string{
"kube_pod_container_status_running",
"kube_pod_container_state_started",
"kube_pod_container_status_waiting",
"kube_pod_container_status_terminated",
"kube_pod_container_status_terminated_reason",
Expand Down