Skip to content

Time the requests served on the internal listener #220

Description

@HMarzban

Problem

The internal listener records no request duration.

The REST app times every route: app.use('*', httpMetricsMiddleware()) (apps/hocuspocus.server/src/index.ts:38). The internal Hono app does not (apps/hocuspocus.server/src/hocuspocus.server.ts:596-601), and it is served by its own Bun.serve (apps/hocuspocus.server/src/hocuspocus.server.ts:608).

That listener carries content apply, checkpoint and restore, on the port set by HOCUSPOCUS_INTERNAL_HTTP_PORT: numericString('4003') (apps/hocuspocus.server/src/config/env.schema.ts:49). Those calls run in the WebSocket process, beside the live Y.Doc, so they are the ones most able to stall other people's typing.

When someone reports a slow content apply, an operator has no latency number to look at.

What to do

Mount the same middleware on the internal app, right after it is created:

internalApp.use('*', httpMetricsMiddleware())

Add httpMetricsMiddleware to the existing ./lib/metrics import at apps/hocuspocus.server/src/hocuspocus.server.ts:21-34.

Acceptance

  • After one content apply, /metrics shows an http_request_duration_seconds sample for that route.
  • /metrics itself still answers, because it is handled before the Hono dispatch.

Notes

The histogram already carries a route label (apps/hocuspocus.server/src/lib/metrics.ts:28-30), so the new samples separate apply from checkpoint and restore with no extra work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions