Commit fd7bef6
authored
Add metricsHandlerPath and registerHealthHandler configuration options to HTTPServer (#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 <[email protected]>1 parent f4640e4 commit fd7bef6
File tree
3 files changed
+94
-17
lines changed- prometheus-metrics-exporter-httpserver/src
- main/java/io/prometheus/metrics/exporter/httpserver
- test/java/io/prometheus/metrics/exporter/httpserver
3 files changed
+94
-17
lines changedLines changed: 17 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | | - | |
31 | | - | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | | - | |
| 60 | + | |
| 61 | + | |
56 | 62 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| |||
Lines changed: 38 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | | - | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
77 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
78 | 83 | | |
79 | 84 | | |
80 | 85 | | |
| |||
88 | 93 | | |
89 | 94 | | |
90 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
| |||
179 | 194 | | |
180 | 195 | | |
181 | 196 | | |
| 197 | + | |
182 | 198 | | |
183 | 199 | | |
184 | | - | |
| 200 | + | |
| 201 | + | |
185 | 202 | | |
186 | 203 | | |
187 | 204 | | |
| |||
254 | 271 | | |
255 | 272 | | |
256 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
257 | 286 | | |
258 | 287 | | |
259 | 288 | | |
| |||
275 | 304 | | |
276 | 305 | | |
277 | 306 | | |
278 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
279 | 310 | | |
280 | 311 | | |
281 | 312 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
108 | 121 | | |
109 | 122 | | |
110 | 123 | | |
| |||
147 | 160 | | |
148 | 161 | | |
149 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
150 | 189 | | |
0 commit comments