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

Add ReadyReplicas metric to deployment metric family #1534

Merged
merged 4 commits into from
Aug 3, 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
1 change: 1 addition & 0 deletions docs/deployment-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| Metric name| Metric type | Labels/tags | Status |
| ---------- | ----------- | ----------- | ----------- |
| kube_deployment_status_replicas | Gauge | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_ready | Gauge | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | EXPERIMENTAL |
| kube_deployment_status_replicas_available | Gauge | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_unavailable | Gauge | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
| kube_deployment_status_replicas_updated | Gauge | `deployment`=&lt;deployment-name&gt; <br> `namespace`=&lt;deployment-namespace&gt; | STABLE |
Expand Down
15 changes: 15 additions & 0 deletions internal/store/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ func deploymentMetricFamilies(allowLabelsList []string) []generator.FamilyGenera
}
}),
),
*generator.NewFamilyGenerator(
"kube_deployment_status_replicas_ready",
"The number of ready replicas per deployment.",
metric.Gauge,
"",
wrapDeploymentFunc(func(d *v1.Deployment) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(d.Status.ReadyReplicas),
},
},
}
}),
),
*generator.NewFamilyGenerator(
"kube_deployment_status_replicas_available",
"The number of available replicas per deployment.",
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 @@ -53,6 +53,8 @@ func TestDeploymentStore(t *testing.T) {
# TYPE kube_deployment_spec_replicas gauge
# HELP kube_deployment_status_replicas The number of replicas per deployment.
# TYPE kube_deployment_status_replicas gauge
# HELP kube_deployment_status_replicas_ready The number of ready replicas per deployment.
# TYPE kube_deployment_status_replicas_ready gauge
# HELP kube_deployment_status_replicas_available The number of available replicas per deployment.
# TYPE kube_deployment_status_replicas_available gauge
# HELP kube_deployment_status_replicas_unavailable The number of unavailable replicas per deployment.
Expand Down Expand Up @@ -84,6 +86,7 @@ func TestDeploymentStore(t *testing.T) {
},
Status: v1.DeploymentStatus{
Replicas: 15,
ReadyReplicas: 10,
AvailableReplicas: 10,
UnavailableReplicas: 5,
UpdatedReplicas: 2,
Expand Down Expand Up @@ -116,6 +119,7 @@ func TestDeploymentStore(t *testing.T) {
kube_deployment_status_replicas_unavailable{deployment="depl1",namespace="ns1"} 5
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_condition{deployment="depl1",namespace="ns1",condition="Available",status="true"} 1
kube_deployment_status_condition{deployment="depl1",namespace="ns1",condition="Progressing",status="true"} 1
kube_deployment_status_condition{deployment="depl1",namespace="ns1",condition="Available",status="false"} 0
Expand All @@ -136,6 +140,7 @@ func TestDeploymentStore(t *testing.T) {
},
Status: v1.DeploymentStatus{
Replicas: 10,
ReadyReplicas: 5,
AvailableReplicas: 5,
UnavailableReplicas: 0,
UpdatedReplicas: 1,
Expand Down Expand Up @@ -169,6 +174,7 @@ func TestDeploymentStore(t *testing.T) {
kube_deployment_status_replicas_unavailable{deployment="depl2",namespace="ns2"} 0
kube_deployment_status_replicas_updated{deployment="depl2",namespace="ns2"} 1
kube_deployment_status_replicas{deployment="depl2",namespace="ns2"} 10
kube_deployment_status_replicas_ready{deployment="depl2",namespace="ns2"} 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ready always the same as kube_deployment_status_replicas_available? Judging by these tests at least? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lilic
Available and Ready replicas count will not necessarily be same
Available replicas are more like a subset of ready replicas (Replicas which are ready for a certain amount of time configurable based on spec.minReadySeconds)

kube_deployment_status_condition{deployment="depl2",namespace="ns2",condition="Available",status="true"} 0
kube_deployment_status_condition{deployment="depl2",namespace="ns2",condition="Progressing",status="true"} 0
kube_deployment_status_condition{deployment="depl2",namespace="ns2",condition="ReplicaFailure",status="true"} 1
Expand Down