Skip to content

Admin API: WebSocket manage#9

Open
pr0head wants to merge 7 commits intogetmockd:mainfrom
pr0head:feature/admin-websocket
Open

Admin API: WebSocket manage#9
pr0head wants to merge 7 commits intogetmockd:mainfrom
pr0head:feature/admin-websocket

Conversation

@pr0head
Copy link
Copy Markdown

@pr0head pr0head commented Apr 4, 2026

Description

Adds a WebSocket connection management API to the Admin API and Engine Control API,
providing real-time visibility and control over active WebSocket connections —
mirroring the existing SSE connection management surface.

New Admin API endpoints (pkg/admin/):

  • GET /websocket/connections — list all active connections with aggregate stats
  • GET /websocket/connections/{id} — inspect a single connection (path, connected time, messages sent/received)
  • DELETE /websocket/connections/{id} — forcibly close a connection
  • POST /websocket/connections/{id}/send — push a text or binary message to a specific client
  • GET /websocket/stats — aggregate counters (total/active connections, messages sent/received, per-mock breakdown)

Engine Control API (pkg/engine/):

  • Added routes and handlers in pkg/engine/api/server.go and handlers.go
  • Added ListWebSocketConnections, GetWebSocketConnection, CloseWebSocketConnection,
    SendToWebSocketConnection, and GetWebSocketStats to ControlAPIAdapter in control_api.go

Engine client (pkg/admin/engineclient/):

  • Added client methods to proxy all five new engine endpoints
  • Added WebSocketConnection, WebSocketStats, and WebSocketConnectionListResponse type aliases

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Tests (adding or updating tests)

Related Issues

Fixes #8

Checklist

  • My code follows the project's style guidelines
  • I have run go fmt and go vet
  • I have added tests covering my changes
  • All new and existing tests pass (go test ./...)
  • I have updated documentation if needed
  • I have checked for breaking changes

Testing

Unit tests added in pkg/admin/websocket_handlers_test.go and
pkg/admin/engineclient/client_test.go; engine-side tests in
pkg/engine/api/handlers_test.go. Coverage includes:

  • Graceful fallback when no engine is attached (empty list / 404)
  • 503 when the engine is unreachable
  • 400 on missing connection ID
  • 404 on unknown connection ID
  • Happy-path responses for list, get, close, and send operations

@pr0head pr0head force-pushed the feature/admin-websocket branch 2 times, most recently from 9ac9ddd to ff60321 Compare April 5, 2026 02:51
@pr0head pr0head force-pushed the feature/admin-websocket branch from ff60321 to 0e665cb Compare April 5, 2026 03:17
@zach-snell
Copy link
Copy Markdown
Contributor

I'll take a look at this but may be tomorrow - thanks for the contribution.

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.

[FEATURE] Admin API WebSocket management

2 participants