Skip to content

Commit 1cda0bf

Browse files
authored
Merge pull request kubernetes#1938 from ryanrolds/rolds/pod_ready_time
Add metrics of kube_pod_status_ready_time and kube_pod_status_containers_ready_time redux
2 parents c752152 + ad5a7ac commit 1cda0bf

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

docs/pod-metrics.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
| kube_pod_container_status_last_terminated_reason | Gauge | Describes the last reason the container was in terminated state | |`container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `reason`=&lt;last-terminated-reason&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
2525
| kube_pod_container_status_last_terminated_exitcode | Gauge | Describes the exit code for the last container in terminated state. | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
2626
| kube_pod_container_status_ready | Gauge | Describes whether the containers readiness check succeeded | |`container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
27+
| kube_pod_status_ready_time | Gauge | Time when pod passed readiness probes. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
28+
| kube_pod_status_container_ready_time | Gauge | Time when the container of the pod entered Ready state. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
2729
| kube_pod_container_status_restarts_total | Counter | The number of container restarts per container | | `container`=&lt;container-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `pod`=&lt;pod-name&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
2830
| kube_pod_container_resource_requests | Gauge | The number of requested request resource by a container. It is recommended to use the `kube_pod_resource_requests` metric exposed by kube-scheduler instead, as it is more precise. | `cpu`=&lt;core&gt; <br> `memory`=&lt;bytes&gt; |`resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; <br> `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `node`=&lt; node-name&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
2931
| kube_pod_container_resource_limits | Gauge | The number of requested limit resource by a container. It is recommended to use the `kube_pod_resource_limits` metric exposed by kube-scheduler instead, as it is more precise. | `cpu`=&lt;core&gt; <br> `memory`=&lt;bytes&gt; |`resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; <br> `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `node`=&lt; node-name&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |

internal/store/pod.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
8484
createPodStatusPhaseFamilyGenerator(),
8585
createPodStatusQosClassFamilyGenerator(),
8686
createPodStatusReadyFamilyGenerator(),
87+
createPodStatusReadyTimeFamilyGenerator(),
88+
createPodStatusContainerReadyTimeFamilyGenerator(),
8789
createPodStatusReasonFamilyGenerator(),
8890
createPodStatusScheduledFamilyGenerator(),
8991
createPodStatusScheduledTimeFamilyGenerator(),
@@ -1318,6 +1320,60 @@ func createPodStatusPhaseFamilyGenerator() generator.FamilyGenerator {
13181320
)
13191321
}
13201322

1323+
func createPodStatusContainerReadyTimeFamilyGenerator() generator.FamilyGenerator {
1324+
return *generator.NewFamilyGeneratorWithStability(
1325+
"kube_pod_status_container_ready_time",
1326+
"Readiness achieved time in unix timestamp for a pod containers.",
1327+
metric.Gauge,
1328+
basemetrics.ALPHA,
1329+
"",
1330+
wrapPodFunc(func(p *v1.Pod) *metric.Family {
1331+
ms := []*metric.Metric{}
1332+
1333+
for _, c := range p.Status.Conditions {
1334+
if c.Type == v1.ContainersReady {
1335+
ms = append(ms, &metric.Metric{
1336+
LabelKeys: []string{},
1337+
LabelValues: []string{},
1338+
Value: float64((c.LastTransitionTime).Unix()),
1339+
})
1340+
}
1341+
}
1342+
1343+
return &metric.Family{
1344+
Metrics: ms,
1345+
}
1346+
}),
1347+
)
1348+
}
1349+
1350+
func createPodStatusReadyTimeFamilyGenerator() generator.FamilyGenerator {
1351+
return *generator.NewFamilyGeneratorWithStability(
1352+
"kube_pod_status_ready_time",
1353+
"Readiness achieved time in unix timestamp for a pod.",
1354+
metric.Gauge,
1355+
basemetrics.ALPHA,
1356+
"",
1357+
wrapPodFunc(func(p *v1.Pod) *metric.Family {
1358+
ms := []*metric.Metric{}
1359+
1360+
for _, c := range p.Status.Conditions {
1361+
if c.Type == v1.PodReady {
1362+
ms = append(ms, &metric.Metric{
1363+
LabelKeys: []string{},
1364+
LabelValues: []string{},
1365+
Value: float64((c.LastTransitionTime).Unix()),
1366+
})
1367+
}
1368+
}
1369+
1370+
return &metric.Family{
1371+
Metrics: ms,
1372+
}
1373+
}),
1374+
)
1375+
}
1376+
13211377
func createPodStatusQosClassFamilyGenerator() generator.FamilyGenerator {
13221378
return *generator.NewFamilyGeneratorWithStability(
13231379
"kube_pod_status_qos_class",

internal/store/pod_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,32 @@ func TestPodStore(t *testing.T) {
14341434
`,
14351435
MetricNames: []string{"kube_pod_status_reason"},
14361436
},
1437+
{
1438+
Obj: &v1.Pod{
1439+
ObjectMeta: metav1.ObjectMeta{
1440+
Name: "pod1",
1441+
Namespace: "ns1",
1442+
UID: "uid1",
1443+
},
1444+
Status: v1.PodStatus{
1445+
Conditions: []v1.PodCondition{
1446+
{
1447+
Type: v1.ContainersReady,
1448+
Status: v1.ConditionTrue,
1449+
LastTransitionTime: metav1.Time{
1450+
Time: time.Unix(1501666018, 0),
1451+
},
1452+
},
1453+
},
1454+
},
1455+
},
1456+
Want: `
1457+
# HELP kube_pod_status_container_ready_time Readiness achieved time in unix timestamp for a pod containers.
1458+
# TYPE kube_pod_status_container_ready_time gauge
1459+
kube_pod_status_container_ready_time{namespace="ns1",pod="pod1",uid="uid1"} 1.501666018e+09
1460+
`,
1461+
MetricNames: []string{"kube_pod_status_container_ready_time"},
1462+
},
14371463
{
14381464
Obj: &v1.Pod{
14391465
ObjectMeta: metav1.ObjectMeta{
@@ -1446,18 +1472,24 @@ func TestPodStore(t *testing.T) {
14461472
{
14471473
Type: v1.PodReady,
14481474
Status: v1.ConditionTrue,
1475+
LastTransitionTime: metav1.Time{
1476+
Time: time.Unix(1501666018, 0),
1477+
},
14491478
},
14501479
},
14511480
},
14521481
},
14531482
Want: `
14541483
# HELP kube_pod_status_ready [STABLE] Describes whether the pod is ready to serve requests.
1484+
# HELP kube_pod_status_ready_time Readiness achieved time in unix timestamp for a pod.
14551485
# TYPE kube_pod_status_ready gauge
1486+
# TYPE kube_pod_status_ready_time gauge
1487+
kube_pod_status_ready_time{namespace="ns1",pod="pod1",uid="uid1"} 1.501666018e+09
14561488
kube_pod_status_ready{condition="false",namespace="ns1",pod="pod1",uid="uid1"} 0
14571489
kube_pod_status_ready{condition="true",namespace="ns1",pod="pod1",uid="uid1"} 1
14581490
kube_pod_status_ready{condition="unknown",namespace="ns1",pod="pod1",uid="uid1"} 0
14591491
`,
1460-
MetricNames: []string{"kube_pod_status_ready"},
1492+
MetricNames: []string{"kube_pod_status_ready_time", "kube_pod_status_ready"},
14611493
},
14621494
{
14631495
Obj: &v1.Pod{
@@ -1471,18 +1503,24 @@ func TestPodStore(t *testing.T) {
14711503
{
14721504
Type: v1.PodReady,
14731505
Status: v1.ConditionFalse,
1506+
LastTransitionTime: metav1.Time{
1507+
Time: time.Unix(1501666018, 0),
1508+
},
14741509
},
14751510
},
14761511
},
14771512
},
14781513
Want: `
14791514
# HELP kube_pod_status_ready [STABLE] Describes whether the pod is ready to serve requests.
1515+
# HELP kube_pod_status_ready_time Readiness achieved time in unix timestamp for a pod.
14801516
# TYPE kube_pod_status_ready gauge
1517+
# TYPE kube_pod_status_ready_time gauge
1518+
kube_pod_status_ready_time{namespace="ns2",pod="pod2",uid="uid2"} 1.501666018e+09
14811519
kube_pod_status_ready{condition="false",namespace="ns2",pod="pod2",uid="uid2"} 1
14821520
kube_pod_status_ready{condition="true",namespace="ns2",pod="pod2",uid="uid2"} 0
14831521
kube_pod_status_ready{condition="unknown",namespace="ns2",pod="pod2",uid="uid2"} 0
14841522
`,
1485-
MetricNames: []string{"kube_pod_status_ready"},
1523+
MetricNames: []string{"kube_pod_status_ready_time", "kube_pod_status_ready"},
14861524
},
14871525
{
14881526
Obj: &v1.Pod{
@@ -2099,7 +2137,7 @@ func BenchmarkPodStore(b *testing.B) {
20992137
},
21002138
}
21012139

2102-
expectedFamilies := 48
2140+
expectedFamilies := 50
21032141
for n := 0; n < b.N; n++ {
21042142
families := f(pod)
21052143
if len(families) != expectedFamilies {

pkg/app/server_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ func TestFullScrapeCycle(t *testing.T) {
238238
# HELP kube_pod_spec_volumes_persistentvolumeclaims_info [STABLE] Information about persistentvolumeclaim volumes in a pod.
239239
# HELP kube_pod_spec_volumes_persistentvolumeclaims_readonly [STABLE] Describes whether a persistentvolumeclaim is mounted read only.
240240
# HELP kube_pod_start_time [STABLE] Start time in unix timestamp for a pod.
241+
# HELP kube_pod_status_container_ready_time Readiness achieved time in unix timestamp for a pod containers.
241242
# HELP kube_pod_status_qos_class The pods current qosClass.
242243
# HELP kube_pod_status_phase [STABLE] The pods current phase.
244+
# HELP kube_pod_status_ready_time Readiness achieved time in unix timestamp for a pod.
243245
# HELP kube_pod_status_ready [STABLE] Describes whether the pod is ready to serve requests.
244246
# HELP kube_pod_status_reason The pod status reasons
245247
# HELP kube_pod_status_scheduled [STABLE] Describes the status of the scheduling process for the pod.
@@ -285,9 +287,11 @@ func TestFullScrapeCycle(t *testing.T) {
285287
# TYPE kube_pod_spec_volumes_persistentvolumeclaims_info gauge
286288
# TYPE kube_pod_spec_volumes_persistentvolumeclaims_readonly gauge
287289
# TYPE kube_pod_start_time gauge
290+
# TYPE kube_pod_status_container_ready_time gauge
288291
# TYPE kube_pod_status_phase gauge
289292
# TYPE kube_pod_status_qos_class gauge
290293
# TYPE kube_pod_status_ready gauge
294+
# TYPE kube_pod_status_ready_time gauge
291295
# TYPE kube_pod_status_reason gauge
292296
# TYPE kube_pod_status_scheduled gauge
293297
# TYPE kube_pod_status_scheduled_time gauge

0 commit comments

Comments
 (0)