Skip to content

[Feature]: no metric for role password expiry (VALID UNTIL) #11459

Description

@melancholictheory

Problem

Managed roles and DatabaseRole accept validUntil, but nothing exposes the resulting expiry. Neither the predefined cnpg_collector_* metrics nor the default query sets in config/manager/default-monitoring.yaml (backends, pg_database, pg_stat_*, pg_settings, pg_extensions and the rest) touch roles at all.

That makes an expiring password invisible until it bites. Expiry behaves like login: false in one important way: open sessions keep working, so nothing breaks at the moment the password lapses, and the failure surfaces later at the first reconnect, when the connection is refused (same trait discussed in #11382).

What already works

A custom query covers it and needs no extra grants. The exporter connects as cnpg_metrics_exporter, which is not a superuser, and pg_roles exposes rolvaliduntil to it, so pg_authid is not needed:

role_expiry:
  query: |
    SELECT rolname AS role,
           extract(epoch from rolvaliduntil) AS valid_until_seconds
    FROM pg_roles
    WHERE rolcanlogin AND rolvaliduntil IS NOT NULL AND rolvaliduntil <> 'infinity'
  metrics:
    - role:
        usage: "LABEL"
        description: "Role"
    - valid_until_seconds:
        usage: "GAUGE"
        description: "Password expiry as a unix timestamp"

Verified on an operator 1.30 cluster: pointing spec.monitoring.customQueriesConfigMap at this ConfigMap alongside the default one produces the metric without restarting the pod, and cnpg_collector_last_collection_error stays at 0.

Ask

Either ship it as a default query, where the cost stays near zero because roles with an expiry are rare and the filter drops everything else, or document the recipe in monitoring.md next to the custom queries section. I can send either PR.

Activity

  1. added
    observability 🔍
    good first issue
    on Sep 11, 2026
  2. gbartolini commented on Sep 11, 2026

    @gbartolini
    Contributor

    Hi @melancholictheory! Would you like to propose a patch for this? I would add it to the config map. Thanks!

  3. melancholictheory commented on Sep 11, 2026

    @melancholictheory
    Author

    Hi @gbartolini, thanks for the quick reply. I'd like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement 🪄good first issueno-staleobservability 🔍

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions