Skip to content

feat(admin): add GET /admin/network-health endpoint - #753

Merged
Ferryx349 merged 6 commits into
mainfrom
feat/admin-network-health-api
Sep 20, 2026
Merged

Ferryx349 merged 6 commits into
mainfrom
feat/admin-network-health-api

Conversation

@Ferryx349

Copy link
Copy Markdown
Collaborator

Description

Adds GET /admin/network-health for authenticated admin clients.

Related Issue

Stacked on #741 and closes #697

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

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.

After each probe run, sign and store NIP-66 relay discovery and monitor announcement events from the monitor identity, bootstrap kind 0/10002 on first run, and persist via the parameterized replaceable event path.

Fixes #696
Knex already parses jsonb event_tags as an array; JSON.parse on that value caused CI failures. Assert the d tag via the event_tags table instead.
@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: df0a802

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

This PR includes changesets to release 1 package
Name Type
nostream Minor

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

@Ferryx349 Ferryx349 changed the title Feat/admin network health api feat(admin): add GET /admin/network-health endpoint (#697) Sep 3, 2026
@Ferryx349 Ferryx349 changed the title feat(admin): add GET /admin/network-health endpoint (#697) feat(admin): add GET /admin/network-health endpoint Sep 3, 2026
Comment thread src/routes/admin/index.ts
router.get(
'/network-health',
adminRateLimitMiddleware,
adminAuthMiddleware,
@coveralls

coveralls commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 72.266% (+0.03%) from 72.236% — feat/admin-network-health-api into main

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The new controller unit test likely fails in isolation due to missing sinon-chai setup, and the NIP-66 bootstrap logic can skip bootstrapping on monitor key rotation and can choose an invalid target URL for the relay list.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds an authenticated admin endpoint to expose the latest relay-probe snapshot (“network health”), and extends the relay monitor worker to publish/store NIP-66 events after probe runs (including one-time monitor identity bootstrap).

Changes:

  • Add GET /admin/network-health (admin-authenticated + admin rate-limited) returning the latest stored probe snapshot.
  • Publish NIP-66 kind 30166 (relay discovery) and 10166 (monitor announcement) events after each probe run, including bootstrapping kind 0/10002 for the monitor identity.
  • Add unit/integration coverage for NIP-66 event building/publishing and the new admin route/controller.
File Description
test/​unit/​utils/​nip66-events.spec.ts Unit tests for NIP-66 event builders and URL normalization.
test/​unit/​routes/​admin.spec.ts Extends admin router tests to cover /network-health protection and middleware counts.
test/​unit/​controllers/​admin/​get-network-health-controller.spec.ts Adds unit test coverage for the new controller (currently missing sinon-chai setup).
test/​unit/​app/​relay-monitor-worker.spec.ts Verifies the worker invokes the NIP-66 publisher after saving snapshots.
test/​integration/​features/​nip-66/​nip-66.feature.ts Integration step definitions now validate that kind 30166 is persisted for the monitor identity.
test/​integration/​features/​nip-66/​nip-66.feature Adds scenario asserting a probe run stores a kind 30166 event.
src/​utils/​nip66-events.ts Implements NIP-66 event builders and relay URL normalization for d tag usage.
src/​utils/​monitor-identity.ts Adds cached env-backed monitor private key accessor + reset for tests.
src/​services/​nip66-event-publisher.ts Implements publishing/signing/upserting NIP-66 events and bootstrap logic.
src/​routes/​admin/​index.ts Registers GET /admin/network-health under existing admin auth + rate limiting.
src/​factories/​relay-monitor-worker-factory.ts Wires DB + cache-backed NIP-66 publisher into the relay monitor worker.
src/​factories/​controllers/​get-admin-network-health-controller-factory.ts Factory to create the new controller backed by Redis snapshot store.
src/​controllers/​admin/​get-network-health-controller.ts Controller returning { snapshot } as JSON from snapshot store.
src/​constants/​base.ts Adds event kind constants for NIP-66 kinds 10166 and 30166.
src/​app/​relay-monitor-worker.ts Publishes NIP-66 events after snapshot save with error isolation.
.changeset/​nip66-publish-events.md Changeset entry for NIP-66 event publishing feature.
.changeset/​admin-network-health-endpoint.md Changeset entry for the new admin endpoint.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/services/nip66-event-publisher.ts Outdated
Comment thread test/unit/controllers/admin/get-network-health-controller.spec.ts Outdated
@Ferryx349

Copy link
Copy Markdown
Collaborator Author

Merging as #764 got approved.

@Ferryx349
Ferryx349 merged commit 7c2875e into main Sep 20, 2026
16 checks passed
@Ferryx349
Ferryx349 deleted the feat/admin-network-health-api branch September 20, 2026 13:40
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.

feat(admin): add GET /admin/network-health endpoint

4 participants