Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/metrics/workload/deployment-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| kube_deployment_status_replicas_available | Gauge | The number of available replicas per deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_unavailable | Gauge | The number of unavailable replicas per deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_updated | Gauge | The number of updated replicas per deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_terminating | Gauge | The number of terminating replicas per deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | ALPHA |
| kube_deployment_status_observed_generation | Gauge | The generation observed by the deployment controller. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_condition | Gauge | The current status conditions of a deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; <br> `reason`=&lt;deployment-transition-reason&gt; <br> `condition`=&lt;deployment-condition&gt; <br> `status`=&lt;true\|false\|unknown&gt; | STABLE |
| kube_deployment_spec_replicas | Gauge | Number of desired pods for a deployment. | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
Expand Down
1 change: 1 addition & 0 deletions docs/metrics/workload/replicaset-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
| kube_replicaset_status_replicas | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
| kube_replicaset_status_fully_labeled_replicas | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
| kube_replicaset_status_ready_replicas | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
| kube_replicaset_status_terminating_replicas | Gauge | The number of terminating replicas per ReplicaSet. | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | ALPHA |
| kube_replicaset_status_observed_generation | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
| kube_replicaset_spec_replicas | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
| kube_replicaset_metadata_generation | Gauge | | `replicaset`=&lt;replicaset-name&gt; <br> `namespace`=&lt;replicaset-namespace&gt; | STABLE |
Expand Down
20 changes: 20 additions & 0 deletions internal/store/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,26 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_deployment_status_replicas_terminating",
"The number of terminating replicas per deployment.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapDeploymentFunc(func(r *v1.Deployment) *metric.Family {
ms := []*metric.Metric{}

if r.Status.TerminatingReplicas != nil {
ms = append(ms, &metric.Metric{
Value: float64(*r.Status.TerminatingReplicas),
})
}

return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_deployment_status_observed_generation",
"The generation observed by the deployment controller.",
Expand Down
6 changes: 6 additions & 0 deletions internal/store/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"

generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
)
Expand Down Expand Up @@ -59,6 +60,8 @@ func TestDeploymentStore(t *testing.T) {
# TYPE kube_deployment_status_replicas gauge
# HELP kube_deployment_status_replicas_ready [STABLE] The number of ready replicas per deployment.
# TYPE kube_deployment_status_replicas_ready gauge
# HELP kube_deployment_status_replicas_terminating The number of terminating replicas per deployment.
# TYPE kube_deployment_status_replicas_terminating gauge
# HELP kube_deployment_status_replicas_available [STABLE] The number of available replicas per deployment.
# TYPE kube_deployment_status_replicas_available gauge
# HELP kube_deployment_status_replicas_unavailable [STABLE] The number of unavailable replicas per deployment.
Expand Down Expand Up @@ -100,6 +103,7 @@ func TestDeploymentStore(t *testing.T) {
AvailableReplicas: 10,
UnavailableReplicas: 5,
UpdatedReplicas: 2,
TerminatingReplicas: ptr.To[int32](3),
ObservedGeneration: 111,
Conditions: []v1.DeploymentCondition{
{Type: v1.DeploymentAvailable, Status: corev1.ConditionTrue, Reason: "MinimumReplicasAvailable"},
Expand Down Expand Up @@ -130,6 +134,7 @@ func TestDeploymentStore(t *testing.T) {
kube_deployment_status_replicas_updated{deployment="depl1",namespace="ns1"} 2
kube_deployment_status_replicas{deployment="depl1",namespace="ns1"} 15
kube_deployment_status_replicas_ready{deployment="depl1",namespace="ns1"} 10
kube_deployment_status_replicas_terminating{deployment="depl1",namespace="ns1"} 3
kube_deployment_status_condition{condition="Available",deployment="depl1",namespace="ns1",reason="MinimumReplicasAvailable",status="true"} 1
kube_deployment_status_condition{condition="Available",deployment="depl1",namespace="ns1",reason="MinimumReplicasAvailable",status="false"} 0
kube_deployment_status_condition{condition="Available",deployment="depl1",namespace="ns1",reason="MinimumReplicasAvailable",status="unknown"} 0
Expand All @@ -154,6 +159,7 @@ func TestDeploymentStore(t *testing.T) {
AvailableReplicas: 5,
UnavailableReplicas: 0,
UpdatedReplicas: 1,
TerminatingReplicas: nil,
ObservedGeneration: 1111,
Conditions: []v1.DeploymentCondition{
{Type: v1.DeploymentAvailable, Status: corev1.ConditionFalse, Reason: "MinimumReplicasUnavailable"},
Expand Down
20 changes: 20 additions & 0 deletions internal/store/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ func replicaSetMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_replicaset_status_terminating_replicas",
"The number of terminating replicas per ReplicaSet.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapReplicaSetFunc(func(r *v1.ReplicaSet) *metric.Family {
ms := []*metric.Metric{}

if r.Status.TerminatingReplicas != nil {
ms = append(ms, &metric.Metric{
Value: float64(*r.Status.TerminatingReplicas),
})
}

return &metric.Family{
Metrics: ms,
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_replicaset_status_observed_generation",
"The generation observed by the ReplicaSet controller.",
Expand Down
6 changes: 6 additions & 0 deletions internal/store/replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

v1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
)
Expand All @@ -43,11 +44,13 @@ func TestReplicaSetStore(t *testing.T) {
# HELP kube_replicaset_metadata_generation [STABLE] Sequence number representing a specific generation of the desired state.
# TYPE kube_replicaset_metadata_generation gauge
# HELP kube_replicaset_status_replicas [STABLE] The number of replicas per ReplicaSet.
# HELP kube_replicaset_status_terminating_replicas The number of terminating replicas per ReplicaSet.
# TYPE kube_replicaset_status_replicas gauge
# HELP kube_replicaset_status_fully_labeled_replicas [STABLE] The number of fully labeled replicas per ReplicaSet.
# TYPE kube_replicaset_status_fully_labeled_replicas gauge
# HELP kube_replicaset_status_ready_replicas [STABLE] The number of ready replicas per ReplicaSet.
# TYPE kube_replicaset_status_ready_replicas gauge
# TYPE kube_replicaset_status_terminating_replicas gauge
# HELP kube_replicaset_status_observed_generation [STABLE] The generation observed by the ReplicaSet controller.
# TYPE kube_replicaset_status_observed_generation gauge
# HELP kube_replicaset_spec_replicas [STABLE] Number of desired pods for a ReplicaSet.
Expand Down Expand Up @@ -80,6 +83,7 @@ func TestReplicaSetStore(t *testing.T) {
Replicas: 5,
FullyLabeledReplicas: 10,
ReadyReplicas: 5,
TerminatingReplicas: ptr.To[int32](3),
ObservedGeneration: 1,
},
Spec: v1.ReplicaSetSpec{
Expand All @@ -93,6 +97,7 @@ func TestReplicaSetStore(t *testing.T) {
kube_replicaset_status_observed_generation{namespace="ns1",replicaset="rs1"} 1
kube_replicaset_status_fully_labeled_replicas{namespace="ns1",replicaset="rs1"} 10
kube_replicaset_status_ready_replicas{namespace="ns1",replicaset="rs1"} 5
kube_replicaset_status_terminating_replicas{namespace="ns1",replicaset="rs1"} 3
kube_replicaset_spec_replicas{namespace="ns1",replicaset="rs1"} 5
kube_replicaset_owner{namespace="ns1",owner_is_controller="true",owner_kind="Deployment",owner_name="dp-name",replicaset="rs1"} 1
`,
Expand All @@ -112,6 +117,7 @@ func TestReplicaSetStore(t *testing.T) {
Replicas: 0,
FullyLabeledReplicas: 5,
ReadyReplicas: 0,
TerminatingReplicas: nil,
ObservedGeneration: 5,
},
Spec: v1.ReplicaSetSpec{
Expand Down