From 921f62f8f5ac224ea1fd93ceddc8a581df0a2770 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Wed, 25 Sep 2024 14:23:41 +0530 Subject: [PATCH] fixup! fixup! Prefer kube-scheduler's resource metrics to kube-state-metrics' reintroduce dropped rules --- rules/apps.libsonnet | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/rules/apps.libsonnet b/rules/apps.libsonnet index 82bf17463..2f073f9a0 100644 --- a/rules/apps.libsonnet +++ b/rules/apps.libsonnet @@ -83,6 +83,29 @@ { name: 'k8s.rules.container_memory_requests', rules: [ + { + record: 'cluster:namespace:pod_memory:active:kube_pod_container_resource_requests', + expr: ||| + kube_pod_container_resource_requests{resource="memory",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_memory:kube_pod_container_resource_requests:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_requests{resource="memory",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_memory:active:kube_pod_resource_request_or_kube_pod_container_resource_requests', expr: ||| @@ -106,6 +129,29 @@ { name: 'k8s.rules.container_cpu_requests', rules: [ + { + record: 'cluster:namespace:pod_cpu:active:kube_pod_container_resource_requests', + expr: ||| + kube_pod_container_resource_requests{resource="cpu",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_cpu:kube_pod_container_resource_requests:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_requests{resource="cpu",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_cpu:active:kube_pod_resource_request_or_kube_pod_container_resource_requests', expr: ||| @@ -129,6 +175,29 @@ { name: 'k8s.rules.container_memory_limits', rules: [ + { + record: 'cluster:namespace:pod_memory:active:kube_pod_container_resource_limits', + expr: ||| + kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_memory:kube_pod_container_resource_limits:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_memory:active:kube_pod_resource_limit_or_kube_pod_container_resource_limits', expr: ||| @@ -152,6 +221,29 @@ { name: 'k8s.rules.container_cpu_limits', rules: [ + { + record: 'cluster:namespace:pod_cpu:active:kube_pod_container_resource_limits', + expr: ||| + kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} * on (namespace, pod, %(clusterLabel)s) + group_left() max by (namespace, pod, %(clusterLabel)s) ( + (kube_pod_status_phase{phase=~"Pending|Running"} == 1) + ) + ||| % $._config, + }, + { + record: 'namespace_cpu:kube_pod_container_resource_limits:sum', + expr: ||| + sum by (namespace, %(clusterLabel)s) ( + sum by (namespace, pod, %(clusterLabel)s) ( + max by (namespace, pod, container, %(clusterLabel)s) ( + kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} + ) * on(namespace, pod, %(clusterLabel)s) group_left() max by (namespace, pod, %(clusterLabel)s) ( + kube_pod_status_phase{phase=~"Pending|Running"} == 1 + ) + ) + ) + ||| % $._config, + }, { record: 'cluster:namespace:pod_cpu:active:kube_pod_resource_limit_or_kube_pod_container_resource_limits', expr: |||