---
id: w3/m10/t004
title: "DB replication-lag series — gated on w1/m22 (Postgres HA); implement the query path now, surface N/A/hidden until HA ships"
worker: worker3
status: todo
estimate: 30m
depends_on: []
---

## Objective

Wire the replication-lag metric query path now, so it activates automatically once `w1/m22` (Postgres HA) ships replicas — without needing a second milestone later.

## Context

- `w1/m22` — Managed Postgres HA (failover + read replicas) — not yet shipped; `highAvailabilityEnabled` reports `false` today (per `docs/ADR018-render-parity.md`).
- CNPG exposes replication-lag metrics on clusters with replicas configured.

## Steps

1. Add a `replicationLag` field to the resource-metrics API for Postgres resources, querying CNPG's replication-lag metric.
2. For instances without replicas (the only kind that exist today, pre-`w1/m22`), return the field omitted/absent rather than a fake zero.
3. Document in the API/field comment that this activates once `w1/m22` ships HA.

## Files

- `lego/backend/internal/metrics/`

## Acceptance criteria

- [ ] The field is present in the API contract and omitted (not a fake value) for every instance today.
- [ ] The query path is correct against CNPG's replication-lag metric name/shape (verified by reading CNPG's metrics reference, even without a live replica to test against).

## Out of scope

- Building `w1/m22` itself — this task only avoids a second milestone once it ships.
