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.

`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)
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)
@mergify mergify bot added the make label Nov 26, 2025
@michaelklishin michaelklishin added this to the 4.2.2 milestone Nov 26, 2025
@michaelklishin michaelklishin merged commit 07a1593 into v4.2.x Nov 26, 2025
289 checks passed
@michaelklishin michaelklishin deleted the mergify/bp/v4.2.x/pr-14885 branch November 26, 2025 00:43
@michaelklishin
Copy link
Collaborator

@Mergifyio backport v4.1.x

@mergify
Copy link
Author

mergify bot commented Nov 26, 2025

backport v4.1.x

✅ Backports have been created

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants