From d73936e577fc79079a3a7711e30c2cb2a15deb9c Mon Sep 17 00:00:00 2001 From: Benji Banwart <70287143+BenjaminBanwart@users.noreply.github.com> Date: Tue, 20 May 2025 11:48:45 -0500 Subject: [PATCH] fix/ add namespace to PVC rules to avoid many-to-many joins Signed-off-by: Benji Banwart <70287143+BenjaminBanwart@users.noreply.github.com> fix/ update expression in jsonnet dir Signed-off-by: Benji Banwart <70287143+BenjaminBanwart@users.noreply.github.com> fix/ implement count by() on the right side of the expression The count by() returns one series per claim. This makes the join key unique on both sides. Signed-off-by: Benji Banwart <70287143+BenjaminBanwart@users.noreply.github.com> fix/ simplify and fix the expression here introduce count by() to allow for unique join keys Signed-off-by: Benji Banwart <70287143+BenjaminBanwart@users.noreply.github.com> fix: add namespace to PVC joins Avoid many-to-many errors when the same PVC name exists in multiple namespaces by joining on namespace. --- deploy/charts/rules/volume/volume-rules.json | 2 +- jsonnet/openebs-mixin/rules/volume/volume-rules.libsonnet | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/charts/rules/volume/volume-rules.json b/deploy/charts/rules/volume/volume-rules.json index 8ab6cff..f0ac99e 100644 --- a/deploy/charts/rules/volume/volume-rules.json +++ b/deploy/charts/rules/volume/volume-rules.json @@ -9,7 +9,7 @@ "description": "Persistent Volume Claim '{{ $labels.persistentvolumeclaim }}' has no consumer", "summary": "Persistent Volume Claim '{{ $labels.persistentvolumeclaim }}' in namespace '{{ $labels.namespace }}' is not consumed by any pod in any namespace" }, - "expr": "kube_persistentvolumeclaim_info unless (kube_persistentvolumeclaim_info * on(persistentvolumeclaim) group_left (max by (persistentvolumeclaim) (kube_pod_spec_volumes_persistentvolumeclaims_info)))) == 1", + "expr": "kube_persistentvolumeclaim_info UNLESS ON (namespace, persistentvolumeclaim) count by (namespace, persistentvolumeclaim) (kube_pod_spec_volumes_persistentvolumeclaims_info) == 1", "for": "5m", "labels": { "severity": "info" diff --git a/jsonnet/openebs-mixin/rules/volume/volume-rules.libsonnet b/jsonnet/openebs-mixin/rules/volume/volume-rules.libsonnet index 5d91913..f3ee8bf 100644 --- a/jsonnet/openebs-mixin/rules/volume/volume-rules.libsonnet +++ b/jsonnet/openebs-mixin/rules/volume/volume-rules.libsonnet @@ -14,7 +14,7 @@ function(param) { summary: "Persistent Volume Claim '{{ $labels.persistentvolumeclaim }}' in namespace '{{ $labels.namespace }}' is not consumed by any pod in any namespace", description: "Persistent Volume Claim '{{ $labels.persistentvolumeclaim }}' has no consumer", }, - expr: 'kube_persistentvolumeclaim_info unless (kube_persistentvolumeclaim_info * on(persistentvolumeclaim) group_left kube_pod_spec_volumes_persistentvolumeclaims_info) == 1', + expr: 'kube_persistentvolumeclaim_info UNLESS ON (namespace, persistentvolumeclaim) count by (namespace, persistentvolumeclaim) (kube_pod_spec_volumes_persistentvolumeclaims_info) == 1', 'for': '5m', labels: { severity: 'info',