Repository navigation
feat(mqtt): broker telemetry and per-project usage - #14043
Conversation
… outcomes New instruments on the Mqtt adapter and their hooks in the Handler/adapter: - mqtt.connections.active (UpDownCounter): +1 on an accepted CONNECT, -1 on disconnect - mqtt.connect.result (accepted/not_authorized/rate_limited) and mqtt.subscribe.outcome (granted/denied) - mqtt.delivery.latency: publish-to-deliver seconds, carried as publishedAt through the pub/sub envelope - mqtt.replay.backlog: pending messages replayed on reconnect - mqtt.ledger.duration: the push-ledger write in the adapter
Accumulate per-project connections and deliveries in the broker worker and flush them to the stats-usage queue every 10s, so push-broker activity shows up in project usage. Adds METRIC_MQTT_CONNECTIONS and METRIC_MQTT_MESSAGES_DELIVERED (cumulative, summed by StatsUsage), a publisherForUsage resource in the broker, and recordConnection/recordDeliveries/flushUsage on the Mqtt adapter.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🟢 Tier S · Ready to merge
Adds MQTT delivery, replay, connection-refusal, and ledger telemetry, along with per-project connection and delivery usage accumulated in the broker and queued periodically. Publication timestamps travel through pub/sub for delivery-latency measurement, and unit and end-to-end tests cover usage accounting. The broker now flushes usage every 60 seconds and records failed push attempts in a dedicated counter. Latest changes: The newest commits extend the usage flush interval to 60 seconds, adjust the end-to-end polling window accordingly, and add an MQTT failed-message counter for push errors.
📂 Walkthrough · 7
Reviewed the commits since |
…liveries The broker Server already owns mqtt.connections.active, mqtt.connections.opened and mqtt.subscriptions via setTelemetry, so the Handler's connections.active, connect.result and subscribe.outcome double-counted (and the disconnect decrement could go negative, since identity is set before the abuse check). Remove them and leave that accounting to the broker. Replay re-deliveries now count toward both the delivered counter and per-project usage, which previously missed them.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The broker counts accepted/rejected CONNECTs but not why a refusal happened. Re-add a refusal-reason counter (mqtt.connect.refused, reason=not_authorized or rate_limited) emitted only on the refuse paths, so the auth-failure vs rate-limit distinction survives without duplicating the broker's totals.
e2e: a user-targeted push to a live subscriber must surface as non-empty mqtt.messages.delivered and mqtt.connections usage series for the project, covering the broker-side flush. Skips where the stack has no usage pipeline.
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
The usage assertion ran against the shared test project, which earlier tests already fill with deliveries, so it passed even if live accounting were removed. Use getProject(fresh: true): a project with no prior MQTT traffic, so a non-zero mqtt.messages.delivered/mqtt.connections series can only come from this test.
A 10s flush cycles the queue/DB work six times more often than needed for usage aggregation. Widen it to 60s and loosen the e2e usage wait accordingly.
Add mqtt.messages.failed, incremented when a per-target publish/persist throws in the Appwrite push adapter, so failed sends are observable alongside published/delivered/dropped.
What
Adds observability to the MQTT push broker in two layers.
Telemetry (OpenTelemetry, in the broker)
New instruments on the
Mqttadapter, hooked in the Handler/adapter:mqtt.connections.active(UpDownCounter) —+1on an accepted CONNECT,-1on disconnectmqtt.connect.result—accepted/not_authorized/rate_limitedmqtt.subscribe.outcome—granted/deniedmqtt.delivery.latency— publish→deliver seconds, carried aspublishedAtthrough the pub/sub envelope (clamped for clock skew)mqtt.replay.backlog— pending messages replayed on reconnectmqtt.ledger.duration— the push-ledger write in the adapterLow-cardinality attributes only (
qos,result) — noprojectIdlabel (cardinality).Per-project usage (billing/dashboards, via queueForUsage)
Per-project
projectIdbelongs in the usage pipeline, not metric labels. The broker (single worker) accumulates per-project connections and deliveries in memory and flushes them to the stats-usage queue every 10s:METRIC_MQTT_CONNECTIONS,METRIC_MQTT_MESSAGES_DELIVERED(cumulative, summed byStatsUsage)publisherForUsageresource in the broker (mirrors realtime)Notes
publisherForUsagefrom_APP_CONNECTIONS_QUEUE_STATS_USAGE, periodic flush).