Skip to content

feat: add klio.plugin.wal.restore_duration end-to-end metric - #206

Open
hh24k wants to merge 3 commits into
cloudnative-pg:mainfrom
hh24k:dev/139
Open

feat: add klio.plugin.wal.restore_duration end-to-end metric#206
hh24k wants to merge 3 commits into
cloudnative-pg:mainfrom
hh24k:dev/139

Conversation

@hh24k

@hh24k hh24k commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

RESTORE_WAL timing only went to the log, so restore latency couldn't be graphed
or alerted on. That latency sets the replica lag when a replica cluster
replicates from an external Klio source. See #139 for the background, and for why
klio.server.wal.get_duration doesn't cover it.

This adds klio.plugin.wal.restore_duration, a histogram in nanoseconds. It uses
the same per-WAL-file buckets as the server's get and upload histograms, so the
three read alike. It is tagged with outcome, cache_hit, tier and
cluster_name.

cache_hit and tier are only known deep in the restore path, so a small
restoreOutcome carries them back up through restoreWAL. Restore records
from a defer, so failures are measured too, including the early ones that
return before any tier is tried.

A hit means the prefetch finished before PostgreSQL asked for the file. That
check is now named walEntry.isReadyPrefetch and has a table test. If the
prefetch is still running the caller waits for it, so it counts as a miss — which
is what makes the hit rate show whether prefetch is keeping up with replay.

Three dashboard panels in the Client / Plugin section: p95 latency split by
cache_hit, rate by outcome, and the prefetch hit ratio. The hit ratio is the
one to watch over time — it falling means prefetch is no longer keeping pace with
replay, which is fixable through the prefetch settings.
klio-dashboard.json is regenerated from the builder.

Closes #139

The CNPG-I plugin's RESTORE_WAL path measured its end-to-end duration but only
logged it. Expose it as an OTel histogram (klio.plugin.wal.restore_duration, ns,
per-file buckets) tagged with outcome, cache_hit, tier and cluster_name.

This is the latency PostgreSQL actually experiences when it asks for a WAL
segment. In a replica cluster whose designated primary replicates from an
external Klio source, it is the speed of the replication path itself and so
drives replica lag; during recovery it drives how fast a cluster catches up.
Neither is visible today, and the server-side get_duration cannot stand in for
it: that times only one WAL.Get call, while prefetch cache hits are served from
the local spool and never reach the server at all.

cache_hit and tier are threaded up from the prefetcher through restoreWAL via a
small restoreOutcome; Restore records on every exit path via defer so failures
are measured too.

Assisted-by: Claude

Signed-off-by: Hai He <hai.he@enterprisedb.com>
Add two panels to the Client / Plugin section for the new
klio.plugin.wal.restore_duration metric: p95 end-to-end restore latency split by
cache_hit and restore rate by outcome.

A prefetch hit is a local rename while a miss waits on a download, so the two
are orders of magnitude apart and are shown split rather than pooled; a falling
hit ratio means prefetch is not keeping ahead of replay. Regenerated
klio-dashboard.json via the builder.

Assisted-by: Claude

Signed-off-by: Hai He <hai.he@enterprisedb.com>
Keep WAL restore metrics aligned with the real restore path by retaining the last attempted tier on miss-all-tiers failures and expose a direct prefetch hit-ratio panel in the Grafana dashboard.

Assisted-by: Claude

Signed-off-by: Hai He <hai.he@enterprisedb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WAL restore: add an end-to-end restore time metric

1 participant