Skip to content

MQ-1154 Add metrics() method to Queue binding#6246

Merged
danlapid merged 1 commit intocloudflare:mainfrom
KennethRuan:kruan/MQ-952-queue-metrics-api
Mar 26, 2026
Merged

MQ-1154 Add metrics() method to Queue binding#6246
danlapid merged 1 commit intocloudflare:mainfrom
KennethRuan:kruan/MQ-952-queue-metrics-api

Conversation

@KennethRuan
Copy link
Copy Markdown
Contributor

@KennethRuan KennethRuan commented Mar 4, 2026

Summary

Adds a new metrics() method to the WorkerQueue binding. The method returns consumer backlog information via a GET subrequest to the /metrics endpoint on the upstream Queues service.

Changes

This PR introduces changes to queue.c++ and queue.h to implement the metrics() method. The new method definition is gated behind the queues_metrics_api compat flag and returns the following response type:

type QueueMetrics = {
  backlogCount: number;
  backlogBytes: number;
  oldestMessageTimestamp: number;
};

The upstream changes can be found here:
https://gitlab.cfdata.org/cloudflare/mq/queue-broker-worker/-/merge_requests/1734
https://gitlab.cfdata.org/cloudflare/mq/queue-broker-worker/-/merge_requests/1759

Testing

  • bazel test //src/workerd/api/tests:queue-test@ - queue send/sendBatch tests + error-codes tests pass
  • bazel test //src/workerd/api/tests:queue-test@all-compat-flags
  • bazel test //src/workerd/api/tests:queue-metrics-test@ - tests new api with flag enabled + flag disabled
  • bazel test //src/workerd/api/tests:queue-metrics-test@all-compat-flags

@KennethRuan KennethRuan requested review from a team as code owners March 4, 2026 23:17
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@KennethRuan
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Mar 5, 2026
@KennethRuan KennethRuan force-pushed the kruan/MQ-952-queue-metrics-api branch from 7f7bc65 to 640cb4c Compare March 5, 2026 17:43
@KennethRuan KennethRuan requested a review from sdnts March 5, 2026 17:52
@KennethRuan KennethRuan force-pushed the kruan/MQ-952-queue-metrics-api branch 4 times, most recently from a0e4962 to ce9f7b5 Compare March 18, 2026 02:59
@KennethRuan KennethRuan force-pushed the kruan/MQ-952-queue-metrics-api branch from 9824741 to 1c84049 Compare March 22, 2026 20:07
@danlapid danlapid merged commit c2e2dbc into cloudflare:main Mar 26, 2026
17 of 18 checks passed
export interface QueueMetrics {
backlogCount: number;
backlogBytes: number;
oldestMessageTimestamp: number;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for coming here late, but is the units of this timestamp documented anywhere? Times should generally either have an obvious type (like Date) or a clear unit (is this in seconds since the epoch? milliseconds? something else?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example the field 5 lines up is called delaySeconds rather than just delay. The unit doesn't have to be in the field name itself -- although that is often a good place for it -- but it does at least need to be clearly documented.

Copy link
Copy Markdown
Contributor Author

@KennethRuan KennethRuan Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it may not be very clear. On the HTTP side, it will be documented in the OpenAPI schema, what would be the best way to document it in workerd?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it more closely, the best answer here would be to actually return this as a Date type (which IIRC can be easily done by making the C++ datatype a kj::Date).

This would parallel the timestamp field in IncomingQueueMessage or a bunch of the other runtime APIs that return a Date if you look at the rest of this file.

Copy link
Copy Markdown
Contributor Author

@KennethRuan KennethRuan Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thank you for pointing it out! I will get that change made.

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.

5 participants