Add metricsHandlerPath and registerHealthHandler configuration options to HTTPServer#1735
Merged
zeitlinger merged 1 commit intoprometheus:mainfrom Dec 20, 2025
Conversation
88a37c6 to
c0e1019
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances the configurability of the Prometheus Java HTTP server by allowing users to customize the metrics endpoint path and control whether the health endpoint is registered. The changes maintain backward compatibility with sensible defaults (/metrics and health handler enabled by default).
Key changes:
- Added
metricsHandlerPath()builder method to customize the metrics endpoint (defaults to/metrics) - Added
registerHealthHandler()builder method to optionally disable the health endpoint (defaults totrue) - Updated
DefaultHandlerto dynamically generate HTML documentation based on the configured metrics path
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| HTTPServer.java | Added constructor parameters and builder methods for configurable metrics path and health handler registration |
| DefaultHandler.java | Updated constructor to accept metrics path parameter and generate dynamic HTML links based on the configured path |
| HTTPServerTest.java | Added tests to verify custom metrics path and health handler enable/disable functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Outdated
Show resolved
Hide resolved
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Outdated
Show resolved
Hide resolved
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Outdated
Show resolved
Hide resolved
...-exporter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/HTTPServer.java
Outdated
Show resolved
Hide resolved
...orter-httpserver/src/main/java/io/prometheus/metrics/exporter/httpserver/DefaultHandler.java
Outdated
Show resolved
Hide resolved
2d8cf20 to
b5395c3
Compare
Contributor
Author
|
I've rebased the branch and applied the review comments from Copilot. |
b5395c3 to
dfa2356
Compare
…options to HTTPServer Signed-off-by: David Sondermann <david.sondermann@hivemq.com>
dfa2356 to
1cec50b
Compare
zeitlinger
approved these changes
Dec 20, 2025
Member
|
Thanks a lot for the contribution 😄 |
sibasispadhi
pushed a commit
to sibasispadhi/client_java
that referenced
this pull request
Jan 7, 2026
…s to HTTPServer (prometheus#1735) Hey @fstab, long time no see. We would like to use this exporter in our project, but need to customize the metrics endpoint and disable the health handler. I hope this small contribution can make into a release. ## Summary This pull request enhances the configurability of the Prometheus Java HTTP server by allowing customization of the metrics endpoint path and making the health endpoint registration optional. It also updates the default HTML handler to reflect these changes and adds tests to ensure correct behavior. ### Configuration improvements * Added support for customizing the metrics endpoint via the new `metricsHandlerEndpoint` option in the `HTTPServer.Builder`. The default remains `/metrics`, but it can now be changed as needed. [[1]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eL60-R82) [[2]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eR187-R191) [[3]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eR264-R278) [[4]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eL278-R302) * Introduced a `registerHealthHandler` option in the `HTTPServer.Builder` to control whether the health endpoint (`/-/healthy`) is registered. By default, it is enabled. [[1]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eL60-R82) [[2]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eR187-R191) [[3]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eR264-R278) [[4]](diffhunk://#diff-fd57f399229770ac99d7f2b18cee74741a3f70c7c4c0800e17a04cb1b1bc321eL278-R302) ### Default handler updates * Updated the `DefaultHandler` to accept the metrics path as a parameter and generate all documentation links and examples based on the configured path, ensuring consistency in the UI and documentation. [[1]](diffhunk://#diff-99311d9bc5b7879fc572852eb8106a440466befcdc072a07632818e6425dbb07L14-R34) [[2]](diffhunk://#diff-99311d9bc5b7879fc572852eb8106a440466befcdc072a07632818e6425dbb07L53-R66) ### Testing * Added tests to verify that the metrics endpoint can be customized and that the health endpoint can be enabled or disabled as configured. [[1]](diffhunk://#diff-c5c2cdc04572f6033ea66e1b7cd4859178b7da6adea0f8fc46993ae83ce8fa6cR108-R120) [[2]](diffhunk://#diff-c5c2cdc04572f6033ea66e1b7cd4859178b7da6adea0f8fc46993ae83ce8fa6cR163-R188) Signed-off-by: David Sondermann <david.sondermann@hivemq.com> Signed-off-by: Sibasis <sibasis.padhi@gmail.com>
This file contains hidden or 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
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.
Hey @fstab, long time no see.
We would like to use this exporter in our project, but need to customize the metrics endpoint and disable the health handler. I hope this small contribution can make into a release.
Summary
This pull request enhances the configurability of the Prometheus Java HTTP server by allowing customization of the metrics endpoint path and making the health endpoint registration optional. It also updates the default HTML handler to reflect these changes and adds tests to ensure correct behavior.
Configuration improvements
metricsHandlerEndpointoption in theHTTPServer.Builder. The default remains/metrics, but it can now be changed as needed. [1] [2] [3] [4]registerHealthHandleroption in theHTTPServer.Builderto control whether the health endpoint (/-/healthy) is registered. By default, it is enabled. [1] [2] [3] [4]Default handler updates
DefaultHandlerto accept the metrics path as a parameter and generate all documentation links and examples based on the configured path, ensuring consistency in the UI and documentation. [1] [2]Testing