New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(http): large prometheus metrics responses split across multiple chunks #3843
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amunra
changed the title
fix(http): Chunked response metrics
fix(http): large metrics responses can be split across multiple chunks
Oct 13, 2023
amunra
changed the title
fix(http): large metrics responses can be split across multiple chunks
fix(http): large prometheus metrics responses split across multiple chunks
Oct 13, 2023
…rectCharSink which allows populating metrics from native code.
Merged latest changes. This PR is ready to be reviewed again. |
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
bluestreak01
requested changes
Oct 20, 2023
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
amunra
force-pushed
the
chunked_response_metrics
branch
from
October 23, 2023 16:23
a25d438
to
6bfaf19
Compare
…thout making any progress.
… from happening again.
ideoma
reviewed
Oct 25, 2023
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/questdb/cutlass/http/HttpResponseSink.java
Outdated
Show resolved
Hide resolved
ideoma
reviewed
Oct 25, 2023
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Show resolved
Hide resolved
core/src/main/java/io/questdb/cutlass/http/processors/PrometheusMetricsProcessor.java
Outdated
Show resolved
Hide resolved
ideoma
previously approved these changes
Oct 26, 2023
bluestreak01
previously approved these changes
Oct 26, 2023
[PR Coverage check]😍 pass : 80 / 80 (100.00%) file detail
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change
This is a minor fix for the way that we handle prometheus metrics.
Prometheus metrics are exposed as the
/metrics
URL on the http-min port.Currently we don't report enough metrics to cause a problem, but if we were to expand the amount of metrics we produce we'd run out of the fixed buffer size (defaults to 1MiB).
The buffer size is fixed, because we return responeses with the "chunked" transfer encoding (HTTP 1.1).
This PR also includes test enhancements that perform parallel requests to the Prometheus endpoint.
Implementation
This fix first encodes all the metrics to a separate buffer, then copies that buffer to as many chunk as required.
The serialization buffer, along with a
written
counter tracking how many bytes got copied to http chunks is tracked insideRequestState
objects. To avoid continuously callingmalloc
andfree
for potentially larger buffers, these objects are pooled and reused.The pool is shared across all instances of the
PrometheusMetricsProcessor
(one per worker).This avoids allocating multiple large buffers in case of sparse requests (which is the default use case for the
/metrics
URL).Additionally, the
Scrapable
metrics interface has been updated from usingCharSink
toDirectUtf8CharSink
which allows borrowing the writable buffer as a Cquestdb_byte_sink_t*
and adding metrics from native code.