MQ-1202 Include metrics metadata in queue() handler message batch#6339
Conversation
|
/bigbonk review this |
There was a problem hiding this comment.
Review summary
Overall this is a solid, well-structured change. The compat flag gating, capnp schema additions, and test coverage are all done correctly. A few items to address:
- [Medium]
backlogCountandbacklogByteswould read more naturally as integer types rather thandoubleat the JS API level — consider whether the upstream data truly requires floating-point representation. - [Low]
QueueEvent::getMetadata()andQueueController::getMetadata()returnMessageBatchMetadataby value, creating a copy on every property access. For a struct of three doubles this is cheap, but worth noting for consistency with lazy-evaluation patterns used formessages. - [Low] The
Fetcher::queue()TS override showsmetadata?: MessageBatchMetadataunconditionally, meaning the type signature is visible in tooling even for workers without thequeue_batch_metadataflag. This is fine for a testing API, but worth confirming it's intentional. - [Low] The disabled-flag test service could use a
compatibilityDateto be more explicit.
This review was generated by an AI assistant and may contain inaccuracies. Please verify all suggestions before applying.
|
Review posted successfully. Here's a summary of the findings: Key findings posted on PR #6339:
No safety, memory, or correctness issues were found. The capnp ordinal ( |
6ea1850 to
c232a53
Compare
c232a53 to
244cd5c
Compare
244cd5c to
c395270
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6339 +/- ##
==========================================
- Coverage 70.70% 70.70% -0.01%
==========================================
Files 427 427
Lines 117285 117313 +28
Branches 18905 18907 +2
==========================================
+ Hits 82926 82944 +18
- Misses 23103 23114 +11
+ Partials 11256 11255 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c395270 to
8676265
Compare
| struct MessageBatchMetrics { | ||
| double backlogCount; | ||
| double backlogBytes; | ||
| double oldestMessageTimestamp; |
There was a problem hiding this comment.
If you buy my argument on #6246 (comment), then this should be a Date here too. As well as in any equivalent new data types introduced in #6354.
Although I'm not totally sure why we're using a different struct here than on the "metrics" endpoint in the first place. Are we worried that eventually we'll end up exposing different metrics from each place?
There was a problem hiding this comment.
Agreed with the comment! All of these changes are behind the experimental flag right now. Would it be alright if I modified all of them to use Date in a follow-up PR after #6354 is in?
That was my thought process, although I imagined they would likely stay in sync, I didn't want to permanently tie all of the metrics types together.
There was a problem hiding this comment.
That's totally fine, thanks!
Summary
Adds a new metadata property to queue message batches (
MessageBatch/QueueEvent), exposing queue metrics with each batch delivered to a worker'squeue()handler.Changes
This PR includes changes to
queue.c++andqueue.hto include metrics on each message batch. The metadata contains three metrics from the upstream queue broker worker (backlogCount,backlogBytes,oldestMessageTimestamp). Below is what the generated types will look like:The new type changes are gated behind a
queue_batch_metadatacompat flag so that it can be tested internally before release. Additionally, changes were made tohttp.c++andhttp.hso that theFetcherused for testing can accept an optionalmetadataargument.Upstream changes can be found here: https://gitlab.cfdata.org/cloudflare/mq/queue-broker-worker/-/merge_requests/1765
Testing
bazel test //src/workerd/api/tests:queue-test@bazel test //src/workerd/api/tests:queue-test@all-compat-flagsbazel test //src/workerd/api/tests:queue-metadata-test@bazel test //src/workerd/api/tests:queue-metadata-test@all-compat-flagsbazel test //types:test/types/rpc