Skip to content

feat(mqtt): drive telemetry collection on the broker worker - #14115

Merged
ArnabChatterjee20k merged 2 commits into
mainfrom
feat/mqtt-telemetry-collect
Oct 5, 2026
Merged

ArnabChatterjee20k merged 2 commits into
mainfrom
feat/mqtt-telemetry-collect

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

The MQTT broker records mqtt.* instruments but never exports them — the series are absent in Grafana.

The OpenTelemetry adapter uses an ExportingReader, which only exports when collect() is called. Every other entrypoint drives it with a Timer::tick(60_000, fn () => $telemetry->collect()) in its worker start (app/http.php, app/realtime.php, app/worker.php, app/cli.php). The broker's onWorkerStart already ticks for the per-project usage flush, but it never captured $telemetry and never called collect().

Change

Capture $telemetry in onWorkerStart and tick collect() every 60s, right next to the existing usage flush. The broker is SWOOLE_BASE single-process, so the top-level $telemetry instance is the same one the instruments record into — collecting it in-worker flushes the real data. collect() is a no-op on NoTelemetry, so this is safe when no exporter is configured (the default).

This is the server-ce half of the fix; the cloud entrypoint that constructs the broker's OpenTelemetry adapter is appwrite-labs/cloud#6288, which tracks server-ce via dev-main and will pull this once merged. Together they make mqtt_* populate the dashboard in appwrite-labs/monitoring#568.

Verification

  • php -l clean, composer lint passes.
  • collect() is defined on the telemetry adapter and already driven identically by the other four entrypoints.

Co-Authored-By: Claude Opus 4.8 [email protected]

🤖 Generated with Claude Code

The broker's OpenTelemetry adapter uses an ExportingReader, which only
exports when collect() is called. onWorkerStart scheduled the per-project
usage flush but never drove telemetry collection, so http/realtime/worker/
cli all exported while the broker's mqtt.* instruments never reached the
endpoint.

Capture $telemetry in onWorkerStart and tick collect() every 60s next to
the usage flush, matching the other entrypoints. collect() is a no-op on
NoTelemetry, so this is safe when no exporter is configured.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ghost

ghost commented Oct 5, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new guard safely avoids a redundant timer without changing collection for active telemetry adapters.

The MQTT broker captures its telemetry adapter in the worker-start callback and schedules collection every 60 seconds when telemetry is enabled. The existing usage flush and Redis subscription bridge remain unchanged.

Latest changes: The newest commit skips registering the collection timer for the no-op telemetry adapter.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
app/mqtt.php Capture telemetry on worker start and register a 60-second collection timer only for non-no-op adapters.

Reviewed the commits since 439f5c6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost 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.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/mqtt-telemetry-collect (after).

Metric Before After Change
🚀 Requests/sec 185.22 207.44 🟢 +12%
⏱️ Latency P50 92.82 ms 82.93 ms 🟢 -10.7%
⏱️ Latency P95 218.37 ms 194.29 ms 🟢 -11%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 82.93 194.29 12,825 207.44 -24.09
Account 159.77 297.77 675 11.19 -72.6
TablesDB 79.37 149.3 6,975 114.64 -29.56
Storage 78.98 178.44 3,375 57.59 -7.44
Functions 121.48 232.15 1,800 31.41 -32.53

Top API waits (after)

API request Max wait (ms)
account.name.update 467.03
functions.variables.update 444.67
functions.create 417.78
account.prefs.update 380.88
functions.variables.create 359.31

CE always resolves telemetry to NoTelemetry (app/init/resources.php),
so an unconditional collect() tick is a no-op timer self-hosted. Gate it
on a real adapter; cloud binds OpenTelemetry on the container, so the
tick arms there and stays off everywhere else.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ArnabChatterjee20k
ArnabChatterjee20k merged commit 0ed7232 into main Oct 5, 2026
49 checks passed
abnegate added a commit that referenced this pull request Oct 5, 2026
Merges main a2cca78 (#14009, #14106, #14117, #14115, #14119, #14114,
#14101, #14125, #14129, #14127) so cloud#5410 can require a train head
that contains main at or after 0ed7232.

Conflicts: none.

Database 8.0 port: none needed. Main's new code only uses Document
getAttribute/setAttribute and Query::equal/lessThan/orderAsc/limit
(Tasks/Interval.php), all unchanged in database 8.0; no removed
Database::* constants, config collections, or model magic reads.
composer.json and composer.lock are untouched by main, so the train's
database and migration pins stay as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant