# Metrics Target Unification Plan

## Current Design

- Grafana Prometheus child metrics use `/metric/query` with the default `metrics_scope=child`.
- `o11y-global-data` parent metrics use the same `/metric/query` endpoint with `metrics_scope=parent`.
- The child path calls `ResolveMetricsTarget(child)`, but premium and nextgen-host clusters still inherit the legacy `Resolve().ClusterMetricsURL` value, which synthesizes `.../internal/v2/metrics/multitenant/...`.
- O11Y URLs already returns the canonical metrics endpoint in `internalReadUri` for dedicated, starter/essential, BYOC, premium, and nextgen clusters.

## Risks

- Keeping both synthesized metrics URLs and O11Y URL lookup lets deploy types drift independently.
- Premium/resource-pool clusters can resolve the correct O11Y cluster but still proxy to an old region-suffix host.
- Changing project-level or global logical metrics at the same time would mix independent contracts into one rollout.

## Target Contract

- TiDB cluster child metrics resolve by TiDB Cloud cluster ID through O11Y URLs and proxy to `internalReadUri`.
- Parent/global control-plane metrics keep using the existing parent resolver and `metrics_scope=parent`.
- BYOC keeps the same proxy header behavior by carrying the resolved O11Y cluster through `MetricsTarget`.
- Project/node/global legacy metrics paths are not changed in this PR.

## Implementation Steps

1. Update `resolveChildMetricsTarget` to use `resolveChildInternalReadCluster`.
2. Return `internalReadUri` and the resolved O11Y cluster in `MetricsTarget`.
3. Add a premium child metrics contract test that fails if the resolver returns a synthesized multitenant URL.
4. Run focused tests for `pkg/o11y/urls` and `pkg/proxy`.

## Verification Checklist

- `go test ./pkg/o11y/urls`
- `go test ./pkg/proxy`
- Prod/staging validation: affected premium/resource-pool dashboard child metrics should no longer hit `*-premium` or `*-ng` synthesized hosts.
