Skip to content

feat(mqtt): emit an always-on broker uptime gauge for liveness - #14188

Merged
ArnabChatterjee20k merged 2 commits into
mainfrom
feat/mqtt-uptime-gauge
Oct 7, 2026
Merged

ArnabChatterjee20k merged 2 commits into
mainfrom
feat/mqtt-uptime-gauge

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

Why

The MQTT broker-not-reporting liveness alert pages on healthy brokers after a rollout.

Every broker metric is a synchronous instrument (mqtt.connections.opened, mqtt.connections.active, mqtt.packets.received, mqtt.subscriptions, the adapter's mqtt.messages.* / histograms). OpenTelemetry exports no series for a synchronous instrument until its first add()/record() — i.e. until a client does something. A rollout restarts the broker and resets the meter, so in a quiet region (e.g. tor1) the fresh pods export nothing until the first CONNECT, which can exceed the alert's 15-minute window. The dead-man can't tell that from the broker being down, so it fires on a healthy rollout.

Change

Register an observable gauge mqtt.server.uptime (seconds) in onWorkerStart, observed on every telemetry collect():

$workerStartedAt = microtime(true);
$uptime = $telemetry->createObservableGauge('mqtt.server.uptime', 's', 'Seconds since the broker worker started.');
$uptime->observe(fn (callable $observe) => $observe(microtime(true) - $workerStartedAt));

Because it's observed on the collect tick (not on a client action), the broker reports within one cycle of a worker starting, regardless of traffic, and the value resets to zero on restart. This mirrors how app/realtime.php keeps realtime.server.active_workers off the request path. There's no onWorkerStop on the broker adapter, so a gauge (which simply stops being observed when the worker dies) is the right shape rather than an up/down counter.

Follow-up

The monitoring repo's mqtt-broker-not-reporting dead-man will be re-anchored from mqtt_connections_opened_total to mqtt_server_uptime_seconds and restored to critical once this ships. (It was temporarily downgraded to warning to stop the false pages.)

🤖 Generated with Claude Code

Every broker metric is a synchronous counter or histogram, recorded
only when a client acts (CONNECT, packet, subscription). So a freshly
rolled worker in a quiet region exports nothing until the first client
connects, which can be many minutes. A metrics dead-man cannot tell that
apart from the broker being down, and pages on healthy rollouts.

Register an observable gauge mqtt.server.uptime, observed on every
telemetry collect from onWorkerStart. It reports within one cycle of a
worker starting regardless of traffic, and resets to zero on restart.
This mirrors how realtime keeps realtime.server.active_workers off the
request path. The broker-not-reporting alert will anchor on this series.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The change registers an observable uptime gauge in onWorkerStart, capturing the worker start time once and computing elapsed seconds on each telemetry collect, resetting to zero on worker restart as intended. The gauge is off the client packet path, guarded by the existing NoTelemetry check, and matches the observable-gauge pattern used elsewhere in the repo.

Files Change
app/mqtt.php Adds a per-worker uptime observable gauge and keeps the existing 60s Timer::tick collect cadence, so quiet regions export a non-empty series and alerting no longer mistakes a rollout for an outage.

One lower-confidence observation (kept at summary level): the collect tick callback calls $telemetry->collect() without a try/catch, and a throwable escaping a Swoole timer coroutine is fatal to the worker; the adjacent usage-flush tick already demonstrates the wrapped pattern.

Reviewed commit: c2ce13d

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change matches the telemetry observer contract and introduces no identified defects.

Adds an observable mqtt.server.uptime gauge when a broker worker starts with telemetry enabled. It reports elapsed seconds on the existing collection timer, providing a liveness series even without client traffic.

Latest changes: The latest commit passes an explicit empty attributes array to the uptime observer.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 1
File Change
app/mqtt.php Registers worker-local uptime observations for periodic telemetry collection, with explicit empty attributes.

Reviewed the commits since c2ce13d · 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 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

PHPStan reads the observer callable as (float|int $value, iterable
$attributes): void with both required, so observing with one argument
failed arguments.count. Pass an empty attributes array explicitly.

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

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/mqtt-uptime-gauge (after).

Metric Before After Change
🚀 Requests/sec 184.78 204.61 🟢 +10.7%
⏱️ Latency P50 93.2 ms 84.65 ms 🟢 -9.2%
⏱️ Latency P95 224.25 ms 196 ms 🟢 -12.6%
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 84.65 196 12,597 204.61 -28.25
Account 160.42 306.84 663 10.97 -35.95
TablesDB 82.43 160.79 6,851 112.52 -23.08
Storage 75.96 167.73 3,315 56.57 -18.42
Functions 120.69 232.03 1,768 30.79 -36.28

Top API waits (after)

API request Max wait (ms)
account.name.update 497.13
account.prefs.update 427.32
tablesdb.rows.get 377.15
tablesdb.rows.create 371.11
tablesdb.rows.update 369

@ArnabChatterjee20k
ArnabChatterjee20k merged commit e070bd3 into main Oct 7, 2026
51 checks 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.

1 participant