Skip to content

feat(admin): add observability dashboard UI with Grafana embeds - #666

Merged
cameri merged 12 commits into
cameri:mainfrom
Ferryx349:UI-DASH
Jul 19, 2026
Merged

feat(admin): add observability dashboard UI with Grafana embeds#666
cameri merged 12 commits into
cameri:mainfrom
Ferryx349:UI-DASH

Conversation

@Ferryx349

@Ferryx349Ferryx349 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Summary

  • Add admin observability dashboard at /admin with live health, throughput, events, and resource cards
  • Stream metrics via existing /admin/metrics SSE endpoint with stale-data and fault indicators
  • Embed Grafana solo panels (events/sec, websocket connections, CPU, memory) with provisioned nostream-overview dashboard
  • Add logout route, session cookie handling, and CSP/frame-src support for Grafana
  • Harden admin health/metrics timeouts and fail-open rate limiting when Redis is unavailable
  • Keep admin console opt-in (admin.enabled: false by default)

Related Issue

Fixes :- #663

How Has This Been Tested?

  • Set admin.enabled: true & ADMIN_PASSWORD in settings/env, sign in at /admin
  • Verify health cards update live (SYS/PROM/DB/RDS)
  • Stop Redis -> Redis shows [FAULT], dashboard stays reachable
  • Start docker compose up -d otel-collector prometheus grafana -> Grafana panels load
  • Run pnpm test:unit for admin routes, grafana utils, event handler, and metrics specs

Video

https://www.youtube.com/watch?v=cRzJ61NDu0o

Note - I have recorded this video before final UI structure, so screens in attached SS and video might differ but functionalities are same.

Screenshots (if appropriate):

Auth

Screenshot 2026-07-06 at 14 36 29

Metrices Dashboard

Screenshot 2026-07-06 at 14 38 11

Graphs

Screenshot 2026-07-06 at 14 38 24

Hamburger (Light Mode)

Screenshot 2026-07-06 at 14 38 51

Grafana dashboard

Screenshot 2026-07-06 at 14 39 14

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

@changeset-bot

changeset-botBot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d9e8af7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
nostreamMinor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment threadsrc/routes/admin/index.ts Fixed
@coveralls

coveralls commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 67.884% (+0.1%) from 67.789% — Ferryx349:UI-DASH into cameri:main

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in admin observability console at /admin that streams live health/throughput/resource metrics via SSE and embeds Grafana panels for richer charts, including local docker-compose provisioning for Prometheus+Grafana.

Changes:

  • Introduces /admin dashboard shell + static assets, plus /admin/metrics SSE streaming and Prometheus query utilities.
  • Adds Grafana URL helpers and docker-compose provisioning for a nostream-overview dashboard and Prometheus datasource.
  • Hardens admin dependency/metrics timeouts and makes Redis-backed rate limiting fail-open on backend outages.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
test/unit/utils/prometheus-client.spec.tsUnit tests for Prometheus URL normalization, scalar parsing, and instant query behavior.
test/unit/utils/admin-metrics.spec.tsUnit tests for admin metrics snapshot composition, degraded/unavailable states, and caching.
test/unit/utils/admin-grafana.spec.tsUnit tests for Grafana URL helpers and env var normalization.
test/unit/routes/admin.spec.tsRoute-level tests for admin enablement, dashboard shell, auth gating, and SSE content-type.
test/unit/handlers/event-message-handler.spec.tsTest coverage for fail-open behavior when rate limiter backend fails.
src/utils/prometheus-client.tsPrometheus instant-query client with parsing + timeout and warning logs.
src/utils/admin-session.tsAdds helper for clearing the admin session cookie on logout.
src/utils/admin-metrics.tsCollects and caches admin metrics snapshots from Prometheus + dependency health.
src/utils/admin-health.tsParallel dependency pings with configurable timeouts.
src/utils/admin-grafana.tsGrafana base/dashboard/embed URL utilities and origin extraction for CSP.
src/routes/admin/index.tsAdmin router wiring: static assets, dashboard routes, logout, health, metrics SSE.
src/handlers/request-handlers/get-admin-dashboard-request-handler.tsServes the admin dashboard HTML template with injected settings/URLs.
src/handlers/event-message-handler.tsRate limiter failures are treated as fail-open (do not reject events on Redis outages).
src/factories/web-app-factory.tsCSP updates (incl. frame-src) and protocol fix for derived web relay URL.
src/factories/controllers/post-admin-logout-controller-factory.tsFactory for admin logout controller.
src/factories/controllers/get-admin-metrics-controller-factory.tsFactory for admin metrics SSE controller.
src/controllers/admin/post-logout-controller.tsLogout controller delegating to auth provider.
src/controllers/admin/get-metrics-controller.tsSSE controller that streams metrics snapshots at a configured interval.
src/app/app.tsSafer centering logic when terminal width is smaller than text length.
src/admin/password-admin-auth-provider.tsImplements logout by clearing the session cookie and returning { authenticated: false }.
src/@types/admin.tsExtends admin auth provider interface with handleLogout.
resources/admin/dashboard.htmlNew admin dashboard HTML shell with login + KPI cards + Grafana iframes.
resources/admin/assets/dashboard.jsFrontend logic for login/session, SSE streaming, staleness detection, theme toggle, and embeds.
resources/admin/assets/dashboard.cssStyling for the admin console UI in light/dark themes.
grafana/provisioning/datasources/prometheus.yamlProvisioned Prometheus datasource for Grafana.
grafana/provisioning/dashboards/default.yamlProvisioned dashboard provider configuration.
grafana/dashboards/nostream-overview.jsonProvisioned Grafana dashboard definition used by the admin embeds.
docs/REDIS.mdDocuments fail-open rate limiting behavior during Redis outages.
docker-compose.ymlAdds Grafana service + env vars for Prometheus/admin metrics configuration.
CONFIGURATION.mdDocuments new observability/admin-related environment variables.
.env.exampleAdds example env vars for Prometheus/Grafana/admin console setup.
.changeset/admin-metrics-sse-endpoint.mdChangeset for admin metrics SSE endpoint feature.
.changeset/admin-dashboard-ui.mdChangeset for admin dashboard UI + Grafana embed feature.
Comments suppressed due to low confidence (1)

src/factories/web-app-factory.ts:35

  • Admin dashboard loads IBM Plex Mono from https://fonts.googleapis.com / https://fonts.gstatic.com (resources/admin/dashboard.html), but the global CSP currently only allows styles/fonts from self and jsdelivr. This will block the Google Fonts stylesheet and font files in the browser.

Allow these origins in the relevant CSP directives (or alternatively vend the font locally).

 const directives = {
'img-src': ["'self'", 'data:', 'https://cdn.zebedee.io/an/nostr/'],
'connect-src': ["'self'", settings.info.relay_url as string, webRelayUrl.toString()],
'default-src': ["'self'"],
'frame-src': ["'self'", getGrafanaFrameOrigin()],
'script-src-attr': [`'nonce-${nonce}'`],
'script-src': [
"'self'",
`'nonce-${nonce}'`,
'https://cdn.jsdelivr.net/npm/',
'https://unpkg.com/',
'https://cdnjs.cloudflare.com/ajax/libs/',
],
'style-src': ["'self'", 'https://cdn.jsdelivr.net/npm/'],
'font-src': ["'self'", 'https://cdn.jsdelivr.net/npm/'],

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/controllers/admin/get-metrics-controller.ts
@Justxd22

Copy link
Copy Markdown
Collaborator

Hello, im wondering why Grafana? and not raw tailwind components? i've the code for the original screens at #594 i was waiting for ground work, Good job on the other PRs!

@Ferryx349

Copy link
Copy Markdown
CollaboratorAuthor

@Justxd22 Sure, we can replace the screen with tailwind components. Actually styling was handled with Bootstrap and custom CSS by me, and Grafana was added specifically for the charting layer.

@Ferryx349

Ferryx349 commented Jul 6, 2026

Copy link
Copy Markdown
CollaboratorAuthor

Will it work for you to push tailwind code in seperate PR, then we can make changes accordingly in this PR..
@cameri wdyt?

Resolve conflicts by keeping dashboard SSE fallback snapshots and snapshot
timeout on top of the merged /admin/metrics SSE foundation from cameri#662.
@cameri

Copy link
Copy Markdown
Owner

@Ferryx349@Justxd22 let's do the Tailwind components in a separate PR as it was not an original requirement of this work.

@Ferryx349

Copy link
Copy Markdown
CollaboratorAuthor

Fixed Conflicts

Comment threaddocker-compose.yml Outdated
Comment threadsrc/handlers/event-message-handler.ts Outdated
Comment threadsrc/utils/admin-health.ts Outdated
Comment threadsrc/utils/admin-health.ts Outdated
Comment threaddocs/REDIS.md Outdated
@cameri
cameri merged commit 44f3bb4 into cameri:mainJul 19, 2026
11 checks passed
@Ferryx349
Ferryx349 deleted the UI-DASH branch July 19, 2026 02:38
Sign up for freeto 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.

6 participants

@Ferryx349@coveralls@Justxd22@cameri@github-advanced-security