Skip to content

Commit 9033d41

Browse files
committed
test(postgres): assert the job pin on each autoscaler selector, not once for the query
The pin check matched job="kube-state-metrics" anywhere in the trigger query, so one pinned selector satisfied it no matter what the other three did: unpinning $joinReplica, $idleFloor or $joinCluster individually left the suite green while the join went back to matching any exporter's series. Anchor one assertion per selector on the label that identifies its site so a single dropped pin fails. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent 0d8b249 commit 9033d41

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎packages/apps/postgres/tests/autoscaling_test.yaml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,18 @@ tests:
182182
- matchRegex:
183183
path: spec.triggers[0].metadata.query
184184
pattern: label_cnpg_io_instance_role="replica"
185-
# the kube_pod_labels join pins job="kube-state-metrics", parity with the alert
186-
# rules, so a duplicate kube_pod_labels series from another exporter cannot
187-
# multiply the join.
185+
# every kube_pod_labels selector pins job="kube-state-metrics", parity with the
186+
# alert rules, so a duplicate kube_pod_labels series from another exporter cannot
187+
# multiply the join. Assert the pin on each selector by its own identifying label
188+
# (a bare presence match would pass with only one of them pinned): the read-load
189+
# join keys on instance_role="replica"...
188190
- matchRegex:
189191
path: spec.triggers[0].metadata.query
190-
pattern: kube_pod_labels\{job="kube-state-metrics"
192+
pattern: kube_pod_labels\{job="kube-state-metrics",namespace="tenant-acme",label_cnpg_io_cluster="postgres-db",label_cnpg_io_instance_role="replica"\}
193+
# ...and the fail-safe idle floor gates on any instance_role (=~".+")
194+
- matchRegex:
195+
path: spec.triggers[0].metadata.query
196+
pattern: count\(kube_pod_labels\{job="kube-state-metrics",namespace="tenant-acme",label_cnpg_io_cluster="postgres-db",label_cnpg_io_instance_role=~".\+"\}\) > 0
191197
# ...and scoped to THIS cluster by release name, so a namespace with multiple
192198
# postgres clusters does not cross-count. The dashboard read-load panel mirrors
193199
# this per-cluster scoping (label_cnpg_io_cluster).
@@ -573,6 +579,12 @@ tests:
573579
- matchRegex:
574580
path: spec.triggers[0].metadata.query
575581
pattern: count\(kube_pod_labels.*\* 150\).*or vector\(0\)\)$
582+
# the cluster-wide lag/WAL join is the fourth kube_pod_labels selector; it pins
583+
# job="kube-state-metrics" too and carries no instance_role (closes right after
584+
# the cluster label), so assert it distinctly from the role-scoped selectors
585+
- matchRegex:
586+
path: spec.triggers[0].metadata.query
587+
pattern: kube_pod_labels\{job="kube-state-metrics",namespace="tenant-acme",label_cnpg_io_cluster="postgres-db"\}
576588

577589
- it: fails closed when the monitoring namespace is not set
578590
templates:

0 commit comments

Comments
 (0)