Skip to content

Conversation

@mergify
Copy link

@mergify mergify bot commented Nov 26, 2025

prometheus_text_format:format/1 produces a binary of the format for the entire registry. For clusters with many resources, this can lead to large replies from /metrics/[:registry] especially for large registries like per-object. Instead of formatting the response and then sending it, we can stream the response by taking advantage of the new format_into/3 callback (which needs to be added upstream to the prometheus dep). This uses cowboy_req:stream_body/3 to stream the iodata as prometheus works through the registry.

This should hopefully be a nice memory improvement. The other benefit is that results are sent eagerly. For a stress-testing example,

  1. make run-broker
  2. rabbitmqctl import_definitions path/to/100k-classic-queues.json
  3. curl -s localhost:15692/metrics/per-object

Before this change curl would wait for around 8 seconds and then the entire response would arrive. With this change the results start streaming in immediately.

Discussed in #14865


This is an automatic backport of pull request #14885 done by Mergify.
This is an automatic backport of pull request #15018 done by Mergify.

`prometheus_text_format:format/1` produces a binary of the format for
the entire registry. For clusters with many resources, this can lead to
large replies from `/metrics/[:registry]` especially for large
registries like `per-object`. Instead of formatting the response and
then sending it, we can stream the response by taking advantage of the
new `format_into/3` callback (which needs to be added upstream to the
`prometheus` dep). This uses `cowboy_req:stream_body/3` to stream the
iodata as `prometheus` works through the registry.

This should hopefully be a nice memory improvement. The other benefit
is that results are sent eagerly. For a stress-testing example,

1. `make run-broker`
2. `rabbitmqctl import_definitions path/to/100k-classic-queues.json`
3. `curl -s localhost:15692/metrics/per-object`

Before this change `curl` would wait for around 8 seconds and then the
entire response would arrive. With this change the results start
streaming in immediately.

(cherry picked from commit 93a014c)
(cherry picked from commit 8e15d15)

# Conflicts:
#	rabbitmq-components.mk
The Cowboy stream handler `cowboy_compress_h` is already enabled for
this endpoint so there's no need to perform gzipping manually.

This change deletes the custom handling of accept-encoding. We
previously returned a content-encoding of "identity" for non-gzipped
requests, but according to
<https://www.rfc-editor.org/rfc/rfc9110.html#section-8.4>, the
content-encoding response header should not be set to identity. The test
case is accurate anyways: the response is text, not something
compressed.

(cherry picked from commit eca7881)
(cherry picked from commit d6dd60e)

# Conflicts:
#	rabbitmq-components.mk
@mergify mergify bot added the conflicts label Nov 26, 2025
@mergify
Copy link
Author

mergify bot commented Nov 26, 2025

Cherry-pick of 8e15d15 has failed:

On branch mergify/bp/v4.1.x/pr-15018
Your branch is up to date with 'origin/v4.1.x'.

You are currently cherry-picking commit 8e15d152b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   deps/rabbitmq_prometheus/src/rabbit_prometheus_handler.erl

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   rabbitmq-components.mk

Cherry-pick of d6dd60e has failed:

On branch mergify/bp/v4.1.x/pr-15018
Your branch is ahead of 'origin/v4.1.x' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit d6dd60e8b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   deps/rabbitmq_prometheus/Makefile
	modified:   deps/rabbitmq_prometheus/src/rabbit_prometheus_handler.erl
	modified:   deps/rabbitmq_prometheus/test/rabbit_prometheus_http_SUITE.erl

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   rabbitmq-components.mk

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@michaelklishin
Copy link
Collaborator

Relevant dependency series have changed between 4.1 and 4.2, 4.3 so this is more risky than it seemed at first. Fair enough, this change will be available in the 4.2.x series anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants