Skip to content

feat(server): add Server.Hooks() accessor for external hook authors#158

Merged
wind-c merged 1 commit intowind-c:mainfrom
debsahu:feat/server-hooks-accessor
May 9, 2026
Merged

feat(server): add Server.Hooks() accessor for external hook authors#158
wind-c merged 1 commit intowind-c:mainfrom
debsahu:feat/server-hooks-accessor

Conversation

@debsahu
Copy link
Copy Markdown
Contributor

@debsahu debsahu commented May 8, 2026

Adds a small read-only accessor to *mqtt.Server:

func (s *Server) Hooks() *Hooks {
    return s.hooks
}

Rationale

External hook authors and monitoring tooling sometimes need to read state that hooks themselves store. The session storage chain is the concrete motivating case: a hook implementing StoredClients, StoredSubscriptions, StoredRetainedMessages, etc. is the source of truth for offline session inspection, and there is currently no in-tree way to reach the hook bus to query it without unsafe access to unexported fields.

The accessor is a getter for an existing pointer, not new behavior. Hooks already mutate state through s.hooks internally; this just exposes a read-only path for code outside the package.

Scope

  • 7 lines (5 of code, 3 of doc comment).
  • No behavior change.
  • No new dependencies.
  • Public API addition only; no rename or break.

Context

Split out from #151 per maintainer feedback that the dashboard PR was too large to evaluate. The dashboard work itself will move to a separate add-on module (debsahu/comqtt-dashboard) so comqtt remains focused on the broker. This accessor is the only upstream change that work needs from comqtt.

External hook authors and monitoring/observability tools currently
have no read-only path to the registered hook bus. Reading state
that hooks store (the session storage chain in particular) requires
reaching into unexported fields, which is fragile.

Adds a 7-line accessor that returns the hook bus pointer. No
behavior change inside the broker; hooks already mutate their own
state through this same pointer.
debsahu added a commit to debsahu/comqtt-dashboard that referenced this pull request May 8, 2026
Web dashboard add-on for comqtt MQTT broker, shipped as a separate Go
module so stock comqtt stays focused on the broker.

Originally proposed in wind-c/comqtt#151. Per maintainer preference,
keeping comqtt lightweight, the dashboard moved here.

This v0.1.0 covers single-mode broker only:

- dashboard/ package: auth (HMAC-signed cookie sessions, file + Redis
  cred stores, lockout, CSRF, RBAC middleware), handlers, SSE pipeline
  (ring-buffered hub, mqtt-hook bridge, /dashboard/events handler),
  HTML templates, embedded static assets (htmx, htmx-sse, tailwind.css,
  theme.js).
- rest/ package: dashboard-specific REST endpoints layered on top of
  upstream comqtt /api/v1/mqtt/* (paginated client list with prefix
  search, subscriptions, topics tree, retained list with payload
  preview, sessions; plus DELETE for unsubscribe / clear-retained /
  disconnect-session).
- cmd/comqtt-dashboard: single-mode broker driver wiring upstream
  comqtt (storage, auth, bridge, listeners) + the dashboard. Drop-in
  replacement for upstream comqtt-single on the same flags.

Build is fully self-contained: go build produces a 40 MB single
binary including all dashboard assets.

Tests: 151 pass under -race across dashboard and rest packages.

Soft-fork note:
go.mod uses a replace directive to pin comqtt at the same commit
pushed in wind-c/comqtt#158 (Server.Hooks() accessor). The replace
will be dropped once an upstream release includes the accessor.

Deferred to v0.2.0:
- Cluster-mode binary with cluster/rest mirrors for cross-node
  aggregation.
- Helm chart (deploy/helm/comqtt-dashboard/).
- CI workflows + Docker image publishing.
@wind-c wind-c merged commit 2c92a3a into wind-c:main May 9, 2026
1 check passed
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.

2 participants