Skip to content

Add a read-only dashboard - #16

Merged
sahilkalgutkar merged 3 commits into
mainfrom
feature/dashboard
Aug 31, 2026
Merged

sahilkalgutkar merged 3 commits into
mainfrom
feature/dashboard

Conversation

@sahilkalgutkar

Copy link
Copy Markdown
Owner

/ lists the models; /models/{name} shows one in detail. Real output from a running server with a 90/10 canary and a drifting feature:

Model         Serving          Versions  Requests  Failures  Drift
fraud-score   v1=90% v2=10%    2         1500      0         significant
churn-risk    not deployed     0         0         0         —
Version  Traffic  Digest        Features  Requests  Failures  Mean batch
v1       90%      3a0468741e67  4         1079      0         26.3
v2       10%      3a0468741e67  4         121       0         3.1

Drift · v1 over 15m0s, 1079 samples
Feature   PSI     Severity     Missing
amount    2.1556  significant  0.0%
tenure    0.0957  stable       0.0%

The split lands where the policy says, and the mean batch sizes differ for a reason worth noticing: the 10% canary fills batches more slowly, so the same window gives it 3.1 rows a call against 26.3.

Server-rendered HTML, no JavaScript — a decision, not a shortcut

html/template does contextual auto-escaping, and that is the XSS defence. It matters more here than it would have a week ago: this server hands out session cookies now, so a script injected into one of these pages would run with somebody's session. There's a test that puts <script>alert(1)</script> in a model description and asserts it comes back escaped.

Having no JavaScript is what makes the CSP meaningful:

default-src 'none'; style-src 'unsafe-inline'; form-action 'self';
base-uri 'none'; frame-ancestors 'none'

default-src 'none' with no script-src means no script can run at all — which turns "everything is escaped correctly" from a claim into something the browser enforces independently. A separate test asserts the pages contain no <script> and no inline handlers, so a future addition fails loudly rather than being silently blocked by the policy, which is a confusing way to find out.

It also means no bundler and no node in CI for a Go serving platform, and the binary stays the single self-contained artifact everything else here assumes. Templates are go:embed-ed and parsed at startup, so a broken one fails the build rather than the first request.

A browser gets a redirect; an API client gets a 401

The one place the HTML surface should behave differently. A browser handed a bare 401 has nowhere to go and no way to know a sign-in exists; an API client handed a redirect follows it and tries to parse a login page as JSON. The redirect preserves where you were heading and re-validates the destination through the same open-redirect check as the login flow.

Tested both ways: /models/anything redirects to /login?next=..., /v1/models still returns 401.

Read-only, deliberately

Changing what serves production traffic is an audited act that already has a tested CLI. Putting it behind a button would widen the CSRF surface to reach a mutation nobody asked to make from a browser. There's a test asserting the pages contain no <form>.

The pages sit behind the read scope like any other read — a predict-only credential gets 403, so the UI is not a way around authorisation.

Smaller things

  • Drift panels distinguish "not enough traffic" from "no drift", since silence is not health.
  • The traffic bar uses a fixed scale rather than normalising to the largest share, so a 5% canary looks like 5% rather than filling the column.
  • Model totals sum across all versions including retired ones, whose failures are exactly what somebody is looking for after a rollback.
  • Refresh is a <meta http-equiv="refresh"> rather than a script, so the no-JavaScript policy holds.

Coverage

89.1% across internal/.

/ lists the models and /models/{name} shows one in detail: the traffic split,
per-version request and failure counts, mean batch size, and drift readings.

Server-rendered HTML with no JavaScript at all, which is a decision rather than
a shortcut. html/template does contextual auto-escaping, and that is the XSS
defence — it matters more now than it would have before, because this server
hands out session cookies and a script injected into one of these pages would
run with somebody's session. Having no JavaScript is also what makes the
Content-Security-Policy meaningful: default-src 'none' with no script-src means
no script can run at all, which turns "everything is escaped correctly" from a
claim into something the browser enforces. A test asserts the pages contain no
script tags and no inline handlers, so a future addition fails loudly rather
than being silently blocked.

It also means no bundler and no node in CI for a Go serving platform, and the
binary stays the single self-contained artifact the rest of the design assumes.
Templates are embedded and parsed at startup, so a broken one fails the build
rather than the first request.

A browser gets a redirect to sign in where an API client gets a 401. That split
is the one place the HTML surface should differ: a browser handed a bare 401 has
nowhere to go and no way to know a sign-in exists, while an API client handed a
redirect follows it and tries to parse a login page as JSON. The redirect
preserves the destination and re-validates it through the same open-redirect
check.

Read-only, deliberately. Changing what serves production traffic is an audited
act that already has a tested CLI, and putting it behind a button would widen
the CSRF surface to reach a mutation nobody asked to make from a browser. The
pages sit behind the read scope like any other read, so a predict-only
credential gets 403.

Coverage across internal/ is 89.1%.
@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.05031% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/api/dashboard.go 87.89% 14 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

The patch coverage check flagged the new code. These reach the paths the
page-level tests do not: the severity mapping that drives the colour and the
index rollup, the weight arithmetic behind the traffic bar, the shared
open-redirect guard, and a version with enough traffic to actually report drift
rather than only the not-enough-data branch.
@sahilkalgutkar
sahilkalgutkar merged commit d507760 into main Aug 31, 2026
2 checks passed
@sahilkalgutkar
sahilkalgutkar deleted the feature/dashboard branch August 31, 2026 23:39
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