---
id: w3/m2/t002
title: REST adapter for resource metrics
worker: worker3
status: done
estimate: 40m
depends_on: [w3/m2/t001]
---

## Objective

Expose resource metrics (`cpu`, `memory`, `instance_count`) as a Render-compatible REST endpoint with percentage/total mode, time range, and resolution.

## Context

- REST adapter is `operator/internal/api/rest.go`, pure presentation over `Core.Metrics`.
- Render's `/metrics` page toggles Percentage/Total and picks a time range with a fixed resolution note ("one data point per hour"); mirror those params.
- Verify response shape against `render-public-api-1.json` where a metrics shape exists.

## Steps

1. Add `GET /v1/metrics` (resource series) in `rest.go`; params: `resource`, `metric` (cpu/memory/instance_count), `mode` (percentage/total), `startTime`/`endTime`, `resolution`.
2. Map to `Core.Metrics`; compute percentage from usage/limit when `mode=percentage`.
3. Return the Render-shaped series envelope.

## Files

- `operator/internal/api/rest.go`, `operator/internal/api/server.go`

## Acceptance criteria

- [ ] `GET /v1/metrics?resource=<app>&metric=cpu&mode=percentage` returns a time series.
- [ ] Memory, instance_count, and total-vs-percentage modes work over a chosen time range.

## Out of scope

- Request metrics (t003/t004), GraphQL for request metrics (t004).
