Skip to content

Commit 559bb28

Browse files
authored
Merge pull request #1932 from frezes/feat/addPodStatusQosClass
Add kube_pod_status_qos_class gauge to pod metrics
2 parents ef627d6 + c3004c6 commit 559bb28

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

docs/pod-metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| kube_pod_labels | Gauge | Kubernetes labels converted to Prometheus labels | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `label_POD_LABEL`=&lt;POD_LABEL&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
1212
| kube_pod_nodeselectors| Gauge | Describes the Pod nodeSelectors | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `nodeselector_NODE_SELECTOR`=&lt;NODE_SELECTOR&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | Opt-in |
1313
| kube_pod_status_phase | Gauge | The pods current phase | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `phase`=&lt;Pending\|Running\|Succeeded\|Failed\|Unknown&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
14+
| kube_pod_status_qos_class | Gauge | The pods current qosClass | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `qos_class`=&lt;BestEffort\|Burstable\|Guaranteed&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
1415
| kube_pod_status_ready | Gauge | Describes whether the pod is ready to serve requests | | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `condition`=&lt;true\|false\|unknown&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
1516
| kube_pod_status_scheduled | Gauge | Describes the status of the scheduling process for the pod | |`pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `condition`=&lt;true\|false\|unknown&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
1617
| kube_pod_container_info | Gauge | Information about a container in a pod | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `image`=&lt;image-name&gt; <br> `image_id`=&lt;image-id&gt; <br> `image_spec`=&lt;image-spec&gt; <br> `container_id`=&lt;containerid&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |

internal/store/pod.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func podMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
8282
createPodSpecVolumesPersistentVolumeClaimsReadonlyFamilyGenerator(),
8383
createPodStartTimeFamilyGenerator(),
8484
createPodStatusPhaseFamilyGenerator(),
85+
createPodStatusQosClassFamilyGenerator(),
8586
createPodStatusReadyFamilyGenerator(),
8687
createPodStatusReasonFamilyGenerator(),
8788
createPodStatusScheduledFamilyGenerator(),
@@ -1317,6 +1318,48 @@ func createPodStatusPhaseFamilyGenerator() generator.FamilyGenerator {
13171318
)
13181319
}
13191320

1321+
func createPodStatusQosClassFamilyGenerator() generator.FamilyGenerator {
1322+
return *generator.NewFamilyGeneratorWithStability(
1323+
"kube_pod_status_qos_class",
1324+
"The pods current qosClass.",
1325+
metric.Gauge,
1326+
basemetrics.ALPHA,
1327+
"",
1328+
wrapPodFunc(func(p *v1.Pod) *metric.Family {
1329+
class := p.Status.QOSClass
1330+
if class == "" {
1331+
return &metric.Family{
1332+
Metrics: []*metric.Metric{},
1333+
}
1334+
}
1335+
1336+
qosClasses := []struct {
1337+
v bool
1338+
n string
1339+
}{
1340+
{class == v1.PodQOSBestEffort, string(v1.PodQOSBestEffort)},
1341+
{class == v1.PodQOSBurstable, string(v1.PodQOSBurstable)},
1342+
{class == v1.PodQOSGuaranteed, string(v1.PodQOSGuaranteed)},
1343+
}
1344+
1345+
ms := make([]*metric.Metric, len(qosClasses))
1346+
1347+
for i, p := range qosClasses {
1348+
ms[i] = &metric.Metric{
1349+
1350+
LabelKeys: []string{"qos_class"},
1351+
LabelValues: []string{p.n},
1352+
Value: boolFloat64(p.v),
1353+
}
1354+
}
1355+
1356+
return &metric.Family{
1357+
Metrics: ms,
1358+
}
1359+
}),
1360+
)
1361+
}
1362+
13201363
func createPodStatusReadyFamilyGenerator() generator.FamilyGenerator {
13211364
return *generator.NewFamilyGeneratorWithStability(
13221365
"kube_pod_status_ready",

internal/store/pod_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,26 @@ func TestPodStore(t *testing.T) {
12941294
`,
12951295
MetricNames: []string{"kube_pod_status_phase", "kube_pod_status_reason"},
12961296
},
1297+
{
1298+
Obj: &v1.Pod{
1299+
ObjectMeta: metav1.ObjectMeta{
1300+
Name: "pod1",
1301+
Namespace: "ns1",
1302+
UID: "uid1",
1303+
},
1304+
Status: v1.PodStatus{
1305+
QOSClass: v1.PodQOSBestEffort,
1306+
},
1307+
},
1308+
Want: `
1309+
# HELP kube_pod_status_qos_class The pods current qosClass.
1310+
# TYPE kube_pod_status_qos_class gauge
1311+
kube_pod_status_qos_class{namespace="ns1",qos_class="BestEffort",pod="pod1",uid="uid1"} 1
1312+
kube_pod_status_qos_class{namespace="ns1",qos_class="Burstable",pod="pod1",uid="uid1"} 0
1313+
kube_pod_status_qos_class{namespace="ns1",qos_class="Guaranteed",pod="pod1",uid="uid1"} 0
1314+
`,
1315+
MetricNames: []string{"kube_pod_status_qos_class"},
1316+
},
12971317
{
12981318
Obj: &v1.Pod{
12991319
ObjectMeta: metav1.ObjectMeta{
@@ -2079,7 +2099,7 @@ func BenchmarkPodStore(b *testing.B) {
20792099
},
20802100
}
20812101

2082-
expectedFamilies := 47
2102+
expectedFamilies := 48
20832103
for n := 0; n < b.N; n++ {
20842104
families := f(pod)
20852105
if len(families) != expectedFamilies {

pkg/app/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ 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_qos_class The pods current qosClass.
241242
# HELP kube_pod_status_phase [STABLE] The pods current phase.
242243
# HELP kube_pod_status_ready [STABLE] Describes whether the pod is ready to serve requests.
243244
# HELP kube_pod_status_reason The pod status reasons
@@ -285,6 +286,7 @@ func TestFullScrapeCycle(t *testing.T) {
285286
# TYPE kube_pod_spec_volumes_persistentvolumeclaims_readonly gauge
286287
# TYPE kube_pod_start_time gauge
287288
# TYPE kube_pod_status_phase gauge
289+
# TYPE kube_pod_status_qos_class gauge
288290
# TYPE kube_pod_status_ready gauge
289291
# TYPE kube_pod_status_reason gauge
290292
# TYPE kube_pod_status_scheduled gauge

0 commit comments

Comments
 (0)