Repository navigation
feat(metrics): add role password expiry to the default metrics - #11473
Open
melancholictheory wants to merge 1 commit into
Open
melancholictheory wants to merge 1 commit into
melancholictheory wants to merge 1 commit into
Conversation
Adds a `pg_roles` query exposing the `VALID UNTIL` of login roles as a Unix timestamp. Closes cloudnative-pg#11459 Signed-off-by: Vasiliy Koshkin <[email protected]>
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
Author
|
This adds a new default metric rather than fixing one, so I don't think it should be backported. #7195 added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11459
Summary
Expose role password expiry as a Prometheus metric so operators can alert before
VALID UNTILactually bites.Managed roles and
DatabaseRolealready acceptvalidUntil, but neithercnpg_collector_*nor the default monitoring queries surface the resulting timestamp. An expired password does not kill existing sessions; the first failure happens on reconnect. Until then the expiry is invisible.Changes
Add a
pg_rolesquery to the default monitoring set:This emits:
Value is a Unix timestamp. A typical alert is:
Why the query looks like this
pg_catalog.isfinite(rolvaliduntil)instead ofIS NOT NULL. WhenvalidUntilis dropped from a role, the operator writesVALID UNTIL 'infinity'(internal/management/controller/roles/roles.go) because PostgreSQL cannot restore NULL there. Without the filter, every role that ever had an expiry would report+Inf. One predicate also drops-infinityand NULL.rolcanloginonly:VALID UNTILapplies to password authentication.pg_roles, notpg_authid, socnpg_metrics_exportercan read it without superuser or an extraGRANT.primary: true. The query is valid on standbys. fix: makepg_replication_slotsdefault metric run on replicas #2897 removed that flag frompg_replication_slotsfor the same reason. Roles live in a shared catalog, so every instance reports the same series (same pattern aspg_database).Testing
Three-instance cluster on k3d, operator 1.30.0, PostgreSQL 18.6, patched ConfigMap instead of
cnpg-default-monitoring.rolvaliduntilapp_expiringapp_expiredapp_no_expiryapp_expiringaftervalidUntilremovedinfinity(written by the operator)role_neg_inf-infinityrole_nologinNOLOGINSame series on primary and both replicas.
cnpg_collector_last_collection_errorstayed at 0 everywhere, including a cluster with no expiring roles (query returns no rows; metric is simply absent).The statement is unchanged on PostgreSQL 13 and 18 (supported range).
EXTRACTreturnsdouble precisionon 13 andnumericfrom 14 onward, same aspg_postmasterin this file.Also ran:
make generate-manifest(query lands in the generated manifest and parses)make wokego test ./pkg/management/postgres/metrics/...Spellcheck matrix does not cover
config/manager; wordlist is unchanged.Left
docs/src/monitoring.mdalone: it links to rawdefault-monitoring.yamlrather than listing queries. e2e default-metric assertions are untouched because this series only exists when a role actually has an expiry.Follow-up
cloudnative-pg/chartscopies these queries invalues.yaml. Happy to send a follow-up there once this lands.