← Status board  /  Phase 8

Phase 8 — Dashboard API · Spring Boot A read-only service that turns the engine's answers into JSON, because a browser cannot speak the protocol StarRocks listens on. Four endpoints at closure — Phase 9 added seven more for the dashboard — no scheduled refresh, and a 503 that says what broke.

Status complete Endpoints 4 → 11 Tests 8 passing Refresh manual only Next Phase 9 · React

1 Why this tier is not optional

Two independent facts force a server between the browser and the engine, and both were measured before the phase started.

FactConsequence
StarRocks answers on port 9030 with the binary MySQL protocolNo browser implements it. The frontend cannot open that socket from JavaScript, with or without CORS.
The FE's HTTP shortcut POST /api/query returns 501 Not Implemented on 3.5.21There is no HTTP escape hatch in this build either. The tier is the only path.
Note

Phase 9 needed ten charts, which four queries cannot feed, so seven consolidations were added later (resumen, por-fuente, por-anio-fuente, por-mes, por-rango-valor, por-contratista, por-municipio). The table below is what closed this phase; the full list lives in the Phase 9 report.

2 The four endpoints at closure

EndpointReturns
GET /api/v1/consolidados/por-anioContracts and exact value per year — 29 rows, including the year 0 that means "no usable date".
GET /api/v1/consolidados/por-entidad?anio=2024&limit=20Top entity codes by contracted value for one year.
GET /api/v1/consolidados/por-departamento?anio=2024Value per department for one year.
GET /api/v1/consolidados/texto?termino=computadoresContracts whose object text contains the term, case-folded.

Every response shares one envelope, so the page never parses two formats:

{ "data": [ … ], "generatedAt": "2026-11-25T20:41:12Z",
  "source": "starrocks 3.5.21-85fccf8", "cached": false, "rows": 29 }

source is the engine's own current_version(), asked once and cached. A screenshot cannot claim a number came from somewhere else.

The three conventions carried over from the benchmark

These are not stylistic: each one prevents a specific wrong answer. SUM(CAST(valor AS DECIMAL(20,0))) keeps the sum exact instead of order-dependent doubles. LOWER() on both sides of the LIKE is mandatory because StarRocks compares byte-exact and the stored text is uppercase — without it the search returns zero. Grouping is on codes, not names, so no collation rule can merge two entities into one group.

3 Read-only, and proven to be

The service connects as secop_reader, never as root. The grant and the refusal were both captured:

SHOW GRANTS FOR 'secop_reader';
  GRANT SELECT ON ALL TABLES IN DATABASE secop TO USER 'secop_reader'@'%'

CREATE TABLE secop.prohibido (a int);        -- executed as secop_reader
  ERROR 5203: Access denied; you need (at least one of) the
              CREATE TABLE privilege(s) on DATABASE secop

Credentials arrive as SR_URL, SR_USER and SR_PASSWORD, and the application refuses to start without them — see section 7, where that claim had to be earned twice.

4 Verified against the engine, number by number

Each endpoint was compared with the same aggregation run directly on StarRocks as the same read-only user. Not "looks plausible" — equal to the last digit.

EndpointAPIDirect SQL on 9030
por-entidad 2024, top 1702,066,010 · 867 · 542,835,589,430702,066,010 · 867 · 542,835,589,430
por-departamento 2023, top 1Bogotá D.C. · 19,106 · 5,079,420,810,687Bogotá D.C. · 19,106 · 5,079,420,810,687
por-anio, year 0120,778120,778
por-anio 202471,90171,901
texto = computadores2,0182,018

Two of those numbers are also cross-checks against earlier phases: 120,778 is the count of null date markers from Phase 4, and 2,018 is exactly what Q2a measured in Phase 5. The API is not a second opinion, it is the same answer through another door.

5 Cache and freshness — no schedule anywhere

There is no materialised view, no cron and no polling. Each request reads the engine; the heaviest consolidation measured 334 ms in Phase 5, so that is already interactive. In front of it sits a 60-second courtesy cache, and ?refresh=true always bypasses it.

RequestcachedMeaning
First call, key never seenfalseAnswered by StarRocks.
Immediate repeat, same keytrueServed from memory; the flag says so instead of pretending.
Same key with ?refresh=truefalseCache skipped, engine asked again.
Why no materialised view

At 334 ms a pre-aggregated copy would add a staleness window and buy no visible time. It stays a documented option with a threshold: the day a consolidation crosses about 2 s, the view comes back — and Phase 5's profile already shows where that time would come from.

6 Failure behaviour

With a second instance pointed at a dead port, the API answered:

HTTP/1.1 503
{ "error": "engine_unavailable", "engine": "starrocks",
  "message": "StarRocks did not answer: Connection refused", "at": "…" }

CORS was checked in both directions: localhost:5173 gets 200 with Access-Control-Allow-Origin, any other origin gets 403 and no header. The engine itself stays bound to loopback.

One measured caveat worth writing down: the container needs roughly 13–15 s before it answers. A curl fired at 14 s returned an empty reply — not a 503, not a 500. An empty socket is what a client sees when it arrives before Tomcat is listening, and confusing that with an application error costs an hour.

7 Two mistakes this phase made, and what they changed

The fail-fast that was not fast, and not fail

The plan said the app must refuse to start without credentials. The first build started anyway without SR_URL and sat there answering 503 to everything — a service that looks healthy and answers nothing, which is the exact opposite of the requirement. Spring leaves an unresolved ${SR_URL} in place longer than the phrase "fail fast" suggests.

Fixed with an explicit StartupCheck that inspects the environment during context creation and throws. Measured afterwards, in both directions:

without SR_URL / SR_USER / SR_PASSWORD
  Exited (1)
  IllegalStateException: Missing required environment variables: SR_URL, SR_USER, SR_PASSWORD

with the three variables
  200 · rows=29 · source=starrocks 3.5.21-85fccf8 · cached=false

A probe that wrote to the database as root

To prove the reader could not create tables, I put SHOW GRANTS and CREATE TABLE in one file and ran it as root — which created the very table the test was meant to be denied. The next attempt then failed with "table already exists", which looks like a permission error and is not one. The table was dropped (secop is back to contratos and entidades) and the test re-run with the DDL as the only statement, as the reader: ERROR 5203 Access denied.

The lesson is the same one Phase 4 taught with the null markers: a test that shares its setup with its subject proves nothing.

8 Tests and fixtures

Four payloads were captured from the running API into src/test/resources/golden/. They are not invented; they are today's answers, frozen so the React page can be built against them before it exists.

TestWhat it pins
Envelope, 4 payloadsThe five keys exist, rows == data.size(), source names the engine, generatedAt is an ISO instant.
Aggregation shape, 3 payloadsEach row has a key, a positive contratos, and valor as a JSON number — the page plots it directly.
Figures still true71,901 contracts in 2024 · 2,018 text matches · 29 distinct years. A SQL change that moves an answer breaks the build.

mvn test → 8 tests, 0 failures.

9 Gate

Gate met

All four endpoints return numbers identical to a direct query on 9030. The application refuses to start without its credentials (exit 1, named variables) and starts when they are present. With the engine unreachable it answers 503 with a body that names the engine, not a stack trace. The read-only user is proven read-only. The JSON contract is frozen in fixtures with three figures pinned. Credentials live nowhere in the repository.

Not in this phase: the React page (Phase 9) and the compose packaging (Phase 10). The API currently runs as a container on the lab network, started by hand; making that one command is F10's job.