Skip to content

feat(metrics): report the attached synchronous standbys as observed - #11990

Merged
leonardoce merged 4 commits into
mainfrom
dev/11309-b
Nov 24, 2026
Merged

leonardoce merged 4 commits into
mainfrom
dev/11309-b

Conversation

@gbartolini

Copy link
Copy Markdown
Contributor

The observed value of cnpg_collector_sync_replicas was the number parsed from synchronous_standby_names, so it described what was requested and kept reporting a healthy value while commits were blocked waiting for standbys that were down.

Count instead the standbys attached to the primary with a sync or quorum state in pg_stat_replication. With quorum-based replication every attached candidate is reported as quorum, so the value can be higher than the expected number, and observed < expected is the condition to alert on.

Deprecate the min and max values, which are removed in 1.33.0, along with the legacy synchronous replication method they come from. Until then they stay populated with both configuration methods.

Document the meaning of the expected, observed, min and max values and the recommended alert in the monitoring page, and the changes in the upgrade notes.

Closes #11309

Assisted-by: Claude

@gbartolini
gbartolini requested a review from a team as a code owner November 23, 2026 07:08
@gbartolini gbartolini added the do not backport This PR must not be backported - it will be in the next minor release label Nov 23, 2026
@gbartolini

Copy link
Copy Markdown
Contributor Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Nov 23, 2026
@armru

armru commented Nov 23, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@leonardoce
leonardoce force-pushed the dev/11309 branch 2 times, most recently from bd8bbe4 to ca0e396 Compare November 24, 2026 08:46
Base automatically changed from dev/11309 to main November 24, 2026 10:29
@leonardoce

Copy link
Copy Markdown
Contributor

/time

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

gbartolini and others added 4 commits November 24, 2026 14:23
The `observed` value of `cnpg_collector_sync_replicas` was the number
parsed from `synchronous_standby_names`, so it described what was
requested and kept reporting a healthy value while commits were blocked
waiting for standbys that were down.

Count instead the standbys attached to the primary with a `sync` or
`quorum` state in `pg_stat_replication`. With quorum-based replication
every attached candidate is reported as `quorum`, so the value can be
higher than the expected number, and `observed < expected` is the
condition to alert on.

Deprecate the `min` and `max` values, which are removed in 1.33.0, along
with the legacy synchronous replication method they come from. Until
then they stay populated with both configuration methods.

Document the meaning of the `expected`, `observed`, `min` and `max`
values and the recommended alert in the monitoring page, and the changes
in the upgrade notes.

Closes #11309

Assisted-by: Claude

Signed-off-by: Gabriele Bartolini <[email protected]>
The recommended alert compared the `observed` and `expected` values of
`cnpg_collector_sync_replicas` without ignoring the `value` label that
tells them apart, so the two sides never matched and the alert could
not fire. Match them with `ignoring(value)`.

State that only the primary exposes `observed`, while every instance
exposes the other values, and that with the legacy method `expected`
never exceeds the number of ready replicas, so the alert does not fire
when replicas are down.

Signed-off-by: Armando Ruocco <[email protected]>
When a cluster is turned into a replica cluster, its primary becomes a
standby without restarting the instance manager. The `observed` value of
`cnpg_collector_sync_replicas` is only refreshed on a primary, so the
instance kept exposing the last value it had collected.

Remove the value when the instance is not a primary.

Signed-off-by: Armando Ruocco <[email protected]>
Move the metrics collected only on a primary into their own function,
so that a unit test can drive it, and verify that the `observed` value
of `cnpg_collector_sync_replicas` is no longer exposed once the instance
has become a standby.

Signed-off-by: Armando Ruocco <[email protected]>
@leonardoce
leonardoce merged commit b3f7c8c into main Nov 24, 2026
37 checks passed
@leonardoce
leonardoce deleted the dev/11309-b branch November 24, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release ok to merge 👌 This PR can be merged

Development

Successfully merging this pull request may close these issues.

[Bug]: cnpg_collector_sync_replicas{min,max} report stale/incorrect values when using the new synchronous replication API

4 participants