Skip to content

Commit 23f9138

Browse files
Carlos MorenoCarlos Moreno
Carlos Moreno
authored and
Carlos Moreno
committed
fix: report correct values in kube_pod_status_reason metric
1 parent ffd8f41 commit 23f9138

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Diff for: internal/store/pod.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -1541,15 +1541,12 @@ func createPodStatusReasonFamilyGenerator() generator.FamilyGenerator {
15411541
ms := []*metric.Metric{}
15421542

15431543
for _, reason := range podStatusReasons {
1544-
metric := &metric.Metric{}
1545-
metric.LabelKeys = []string{"reason"}
1546-
metric.LabelValues = []string{reason}
1547-
if p.Status.Reason == reason {
1548-
metric.Value = boolFloat64(true)
1549-
} else {
1550-
metric.Value = boolFloat64(false)
1544+
m := &metric.Metric{
1545+
LabelKeys: []string{"reason"},
1546+
LabelValues: []string{reason},
1547+
Value: getPodStatusReasonValue(p, reason),
15511548
}
1552-
ms = append(ms, metric)
1549+
ms = append(ms, m)
15531550
}
15541551

15551552
return &metric.Family{
@@ -1559,6 +1556,23 @@ func createPodStatusReasonFamilyGenerator() generator.FamilyGenerator {
15591556
)
15601557
}
15611558

1559+
func getPodStatusReasonValue(p *v1.Pod, reason string) float64 {
1560+
if p.Status.Reason == reason {
1561+
return 1
1562+
}
1563+
for _, cond := range p.Status.Conditions {
1564+
if cond.Reason == reason {
1565+
return 1
1566+
}
1567+
}
1568+
for _, cs := range p.Status.ContainerStatuses {
1569+
if cs.State.Terminated != nil && cs.State.Terminated.Reason == reason {
1570+
return 1
1571+
}
1572+
}
1573+
return 0
1574+
}
1575+
15621576
func createPodStatusScheduledFamilyGenerator() generator.FamilyGenerator {
15631577
return *generator.NewFamilyGeneratorWithStability(
15641578
"kube_pod_status_scheduled",

0 commit comments

Comments
 (0)