From 8a685c708133c5e1118598e7fcab7eb88d208db1 Mon Sep 17 00:00:00 2001 From: frezes Date: Tue, 9 Jul 2024 15:18:23 +0800 Subject: [PATCH] [kube-prometheus-stack] add recording rule pod_start_time:kube_node_info: Signed-off-by: frezes --- charts/kube-prometheus-stack/Chart.yaml | 2 +- .../whizard-telemetry-cluster.rules.yaml | 18 ++++++++++++++++++ .../rules/custom.libsonnet | 13 +++++++++++++ .../whizard-telemetry-prometheusRule.yaml | 9 +++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index a508814dfba3..b3dad5309a1f 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -21,7 +21,7 @@ name: kube-prometheus-stack sources: - https://github.com/prometheus-community/helm-charts - https://github.com/prometheus-operator/kube-prometheus -version: 52.2.1 +version: 52.2.2 appVersion: v0.68.0 kubeVersion: ">=1.19.0-0" home: https://github.com/prometheus-operator/kube-prometheus diff --git a/charts/kube-prometheus-stack/templates/prometheus/rules-1.14/whizard-telemetry-cluster.rules.yaml b/charts/kube-prometheus-stack/templates/prometheus/rules-1.14/whizard-telemetry-cluster.rules.yaml index 9319d3d226cf..36d95440f3c2 100644 --- a/charts/kube-prometheus-stack/templates/prometheus/rules-1.14/whizard-telemetry-cluster.rules.yaml +++ b/charts/kube-prometheus-stack/templates/prometheus/rules-1.14/whizard-telemetry-cluster.rules.yaml @@ -111,4 +111,22 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} {{- end }} + - expr: |- + max by (cluster, namespace, pod, pod_ip, host_ip, node) ( + kube_pod_info{job="kube-state-metrics"} + * on (cluster, namespace, pod, uid) group_left () + kube_pod_start_time{job="kube-state-metrics"} + ) + * on (cluster, namespace, pod) group_left (workspace, qos_class, phase) + workspace_workload_node:kube_pod_info: + record: 'pod_start_time:kube_pod_info:' + {{- if or .Values.defaultRules.additionalRuleLabels .Values.defaultRules.additionalRuleGroupLabels.whizardTelemetry }} + labels: + {{- with .Values.defaultRules.additionalRuleLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.defaultRules.additionalRuleGroupLabels.whizardTelemetry }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} {{- end }} \ No newline at end of file diff --git a/ks-prometheus/components/whizard-telemetry-mixin/rules/custom.libsonnet b/ks-prometheus/components/whizard-telemetry-mixin/rules/custom.libsonnet index d842aff337ba..d53e3b129535 100644 --- a/ks-prometheus/components/whizard-telemetry-mixin/rules/custom.libsonnet +++ b/ks-prometheus/components/whizard-telemetry-mixin/rules/custom.libsonnet @@ -100,6 +100,19 @@ ) ||| % $._config }, + { + // + record: 'pod_start_time:kube_pod_info:', + expr: ||| + max by (cluster, namespace, pod, pod_ip, host_ip, node) ( + kube_pod_info{%(kubeStateMetricsSelector)s} + * on (cluster, namespace, pod, uid) group_left () + kube_pod_start_time{%(kubeStateMetricsSelector)s} + ) + * on (cluster, namespace, pod) group_left (workspace, qos_class, phase) + workspace_workload_node:kube_pod_info: + ||| % $._config + }, ], }, { diff --git a/ks-prometheus/manifests/whizard-telemetry-prometheusRule.yaml b/ks-prometheus/manifests/whizard-telemetry-prometheusRule.yaml index bfc6bc3e6b69..f8ff7e31d900 100644 --- a/ks-prometheus/manifests/whizard-telemetry-prometheusRule.yaml +++ b/ks-prometheus/manifests/whizard-telemetry-prometheusRule.yaml @@ -81,6 +81,15 @@ spec: "(.*)" ) record: 'node_role_ip:kube_node_info:' + - expr: | + max by (cluster, namespace, pod, pod_ip, host_ip, node) ( + kube_pod_info{job="kube-state-metrics"} + * on (cluster, namespace, pod, uid) group_left () + kube_pod_start_time{job="kube-state-metrics"} + ) + * on (cluster, namespace, pod) group_left (workspace, qos_class, phase) + workspace_workload_node:kube_pod_info: + record: 'pod_start_time:kube_pod_info:' - name: whizard-telemetry-node.rules rules: - expr: |