Skip to content

feat(sketch-db): GET /api/v1/db/schemas — §15.2 registry read API - #23

Merged
zzylol merged 1 commit into
mainfrom
sketchdb/schemas-endpoint
Apr 17, 2026
Merged

zzylol merged 1 commit into
mainfrom
sketchdb/schemas-endpoint

Conversation

@zzylol

@zzylol zzylol commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New endpoint GET /api/v1/db/schemas (design doc §15.2) returns the current SchemaRegistry state as JSON: one row per schema with agg_id, metric_name, status, created/retired/expires timestamps, and aggregation_type.
  • Query param ?status=active|retired|expired|all filters (default all). Unknown values → 400.
  • Returns 503 when HttpServer was built without with_schemas, matching the existing /streaming-config endpoint's missing-handle behaviour.
  • Entries sorted by agg_id for stable diffs.

Why

Operators and the controller currently have no way to inspect the registry without a debugger. This is the read-only half of the §15 controller-facing API surface — enough to answer "which aggregations exist, which are retired, and when do they expire?" from a curl.

Test plan

  • Two integration tests: full lifecycle (active + retired + filter + bogus-filter 400) and missing-registry (503).
  • 561 lib tests pass.
  • clippy + fmt clean.

🤖 Generated with Claude Code

Adds an HTTP endpoint that exposes the `SchemaRegistry` state to
operators and the controller (design doc §15.2). Matches the
per-`agg_id` lifecycle lifecycle view that the design doc promised:
one row per schema with `agg_id`, `metric_name`, `status`,
`created_at_ms`, `retired_at_ms`, `expires_at_ms`, and
`aggregation_type`.

Query param `?status=active|retired|expired|all` (default `all`)
filters; unknown values return 400. When the HTTP server was built
without `with_schemas` the endpoint returns 503 — same shape as the
`/api/v1/streaming-config` endpoint without a hot-reload handle, so
operators can probe capability.

Entries are sorted by `agg_id` so the response ordering is stable
across calls (and easy to diff from the CLI).

Two integration tests cover:
* two-aggregation lifecycle + `status` filter (active, retired, all,
  plus a 400 for a bogus filter),
* 503 when no registry is attached.

561 lib tests pass; clippy/fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit ca65b04 into main Apr 17, 2026
@zzylol
zzylol deleted the sketchdb/schemas-endpoint branch April 17, 2026 21:01
zzylol added a commit that referenced this pull request Apr 17, 2026
… API

Companion to PR #23's `/api/v1/db/schemas`. Exposes
`SchemaRegistry::timeline_for_metric` over HTTP so operators and
external tooling can answer "which agg_id served this slice of
history?" without attaching a debugger.

Required params: `metric` (string), `start_ms` (u64 millis),
`end_ms` (u64 millis). Missing or unparsable params return 400;
unattached registry returns 503 (matches the schemas endpoint).
Response includes per-segment `{agg_id, start_ms, end_ms, status,
coverage}` — the same shape `timeline_for_metric` already returns
to Rust callers.

3 new integration tests cover:
* end-to-end reconfigure: two POSTs to `/api/v1/streaming-config`,
  then assert `timeline?metric=...&start=...&end=...` returns the
  retired + active segment pair (with a 5ms spacing between posts so
  neither schema ends up with zero-width ownership at ms resolution),
* missing/malformed params → 400,
* missing registry → 503.

570 lib tests pass (up from 567); clippy + fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Apr 17, 2026
… API (#25)

Companion to PR #23's `/api/v1/db/schemas`. Exposes
`SchemaRegistry::timeline_for_metric` over HTTP so operators and
external tooling can answer "which agg_id served this slice of
history?" without attaching a debugger.

Required params: `metric` (string), `start_ms` (u64 millis),
`end_ms` (u64 millis). Missing or unparsable params return 400;
unattached registry returns 503 (matches the schemas endpoint).
Response includes per-segment `{agg_id, start_ms, end_ms, status,
coverage}` — the same shape `timeline_for_metric` already returns
to Rust callers.

3 new integration tests cover:
* end-to-end reconfigure: two POSTs to `/api/v1/streaming-config`,
  then assert `timeline?metric=...&start=...&end=...` returns the
  retired + active segment pair (with a 5ms spacing between posts so
  neither schema ends up with zero-width ownership at ms resolution),
* missing/malformed params → 400,
* missing registry → 503.

570 lib tests pass (up from 567); clippy + fmt clean.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Apr 17, 2026
Operator + controller-facing HTTP surface for §10.2 backfill jobs.
Endpoints return a stable JSON shape so the DC controller can
POST jobs + poll progress without attaching a debugger, and the
`/jobs/:id` detail is the same data Phase 5f's coverage tracker
will consult.

## New endpoints

| Method | Path | Purpose |
|---|---|---|
| POST   | `/api/v1/db/backfill`         | Create a queued job. Body `{agg_id, start_ms, end_ms, source, windows_total}`. Returns 201 with `{job_id}`. |
| GET    | `/api/v1/db/backfill/jobs`    | List, optional `?status=queued|running|complete|failed|cancelled|all` filter. Sorted by job_id. |
| GET    | `/api/v1/db/backfill/jobs/:id`| Detail (including `progress`, `windows_done`, timestamps, and any `error_message`). |
| DELETE | `/api/v1/db/backfill/jobs/:id`| Cancel non-terminal job. 200 on success, 404 unknown, 409 if already terminal. |

Consistent with the §15.2/§15.3 endpoints from PR #23 / PR #25:
- 503 when `HttpServer` wasn't built with `with_backfill_registry`.
- 400 on malformed body or inverted range.
- Response JSON tagged `{status: "success"|"error", ...}`.

## Wire-up

* `HttpServer` gains `with_backfill_registry()` alongside
  `with_schemas()` / `with_hot_reload_config()`.
* `AppState` carries an `Option<Arc<BackfillRegistry>>` so each
  handler can bail to 503 cleanly when the registry isn't
  attached.
* `main.rs` always creates a fresh `Arc<BackfillRegistry>` and
  attaches it — no CLI flag required. Without Phase 5e's worker
  pool, jobs stay `Queued` forever but are still visible + can be
  cancelled, which is useful shadow-mode for validating the DC
  controller's REFRESH dispatch logic before the worker arrives.

## Test plan

- [x] 5 new integration tests:
  * Full lifecycle: POST → GET one → GET list → GET filtered lists
    (both `queued` matches and `running` is zero) → DELETE cancels
    → second DELETE is 409.
  * POST with inverted range → 400.
  * GET on unknown id → 404.
  * All endpoints return 503 when no registry is attached.
  * GET `jobs?status=junk` → 400.
- [x] 625 lib tests pass (up from 620).
- [x] clippy + fmt clean.

## Next phase

5e: real `WindowProcessor` that builds the target sketch from raw
samples and writes per-window precomputes into the store through
the §6.3 schema barrier. When 5e merges, POSTing a backfill job
will actually rebuild history.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Apr 17, 2026
Operator + controller-facing HTTP surface for §10.2 backfill jobs.
Endpoints return a stable JSON shape so the DC controller can
POST jobs + poll progress without attaching a debugger, and the
`/jobs/:id` detail is the same data Phase 5f's coverage tracker
will consult.

## New endpoints

| Method | Path | Purpose |
|---|---|---|
| POST   | `/api/v1/db/backfill`         | Create a queued job. Body `{agg_id, start_ms, end_ms, source, windows_total}`. Returns 201 with `{job_id}`. |
| GET    | `/api/v1/db/backfill/jobs`    | List, optional `?status=queued|running|complete|failed|cancelled|all` filter. Sorted by job_id. |
| GET    | `/api/v1/db/backfill/jobs/:id`| Detail (including `progress`, `windows_done`, timestamps, and any `error_message`). |
| DELETE | `/api/v1/db/backfill/jobs/:id`| Cancel non-terminal job. 200 on success, 404 unknown, 409 if already terminal. |

Consistent with the §15.2/§15.3 endpoints from PR #23 / PR #25:
- 503 when `HttpServer` wasn't built with `with_backfill_registry`.
- 400 on malformed body or inverted range.
- Response JSON tagged `{status: "success"|"error", ...}`.

## Wire-up

* `HttpServer` gains `with_backfill_registry()` alongside
  `with_schemas()` / `with_hot_reload_config()`.
* `AppState` carries an `Option<Arc<BackfillRegistry>>` so each
  handler can bail to 503 cleanly when the registry isn't
  attached.
* `main.rs` always creates a fresh `Arc<BackfillRegistry>` and
  attaches it — no CLI flag required. Without Phase 5e's worker
  pool, jobs stay `Queued` forever but are still visible + can be
  cancelled, which is useful shadow-mode for validating the DC
  controller's REFRESH dispatch logic before the worker arrives.

## Test plan

- [x] 5 new integration tests:
  * Full lifecycle: POST → GET one → GET list → GET filtered lists
    (both `queued` matches and `running` is zero) → DELETE cancels
    → second DELETE is 409.
  * POST with inverted range → 400.
  * GET on unknown id → 404.
  * All endpoints return 503 when no registry is attached.
  * GET `jobs?status=junk` → 400.
- [x] 625 lib tests pass (up from 620).
- [x] clippy + fmt clean.

## Next phase

5e: real `WindowProcessor` that builds the target sketch from raw
samples and writes per-window precomputes into the store through
the §6.3 schema barrier. When 5e merges, POSTing a backfill job
will actually rebuild history.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

1 participant