Skip to content

Commit 85a3446

Browse files
authored
chore: add pod readiness dimension to pod state metrics (#2727)
1 parent 72387e3 commit 85a3446

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/controllers/metrics/pod/controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const (
5454
podHostInstanceType = "instance_type"
5555
podPhase = "phase"
5656
podScheduled = "scheduled"
57+
podReady = "ready"
5758
)
5859

5960
var (
@@ -63,7 +64,7 @@ var (
6364
Namespace: metrics.Namespace,
6465
Subsystem: metrics.PodSubsystem,
6566
Name: "state",
66-
Help: "Pod state is the current state of pods. This metric can be used several ways as it is labeled by the pod name, namespace, owner, node, nodepool name, zone, architecture, capacity type, instance type and pod phase.",
67+
Help: "Pod state is the current state of pods. This metric can be used several ways as it is labeled by the pod name, namespace, owner, node, nodepool name, zone, architecture, capacity type, instance type, pod phase, and pod readiness.",
6768
},
6869
labelNames(),
6970
)
@@ -191,6 +192,7 @@ func labelNames() []string {
191192
podHostCapacityType,
192193
podHostInstanceType,
193194
podPhase,
195+
podReady,
194196
}
195197
}
196198

@@ -426,6 +428,11 @@ func (c *Controller) makeLabels(ctx context.Context, pod *corev1.Pod) (prometheu
426428
metricLabels[podScheduled] = lo.Ternary(pod.Spec.NodeName != "", "true", "false")
427429
metricLabels[podPhase] = string(pod.Status.Phase)
428430

431+
_, ready := lo.Find(pod.Status.Conditions, func(c corev1.PodCondition) bool {
432+
return c.Type == corev1.PodReady && c.Status == corev1.ConditionTrue
433+
})
434+
metricLabels[podReady] = lo.Ternary(ready, "true", "false")
435+
429436
node := &corev1.Node{}
430437
if pod.Spec.NodeName != "" {
431438
if err := c.kubeClient.Get(ctx, types.NamespacedName{Name: pod.Spec.NodeName}, node); client.IgnoreNotFound(err) != nil {

0 commit comments

Comments
 (0)