Skip to content

Commit b1b0efa

Browse files
committed
Improve doc of auto and paths
1 parent 609581b commit b1b0efa

4 files changed

Lines changed: 66 additions & 20 deletions

File tree

docs/src/main/asciidoc/includes/metrics/metrics-config.adoc

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,50 @@ endif::se-flavor[]
9191
==== Selecting REST Endpoints for Automatic Measurement
9292
You can choose which endpoints to include in Helidon's automatic measurements using the `auto` config section.
9393
94-
If you omit the `auto` section, Helidon measures all endpoints.
94+
include::{rootdir}/config/io_helidon_webserver_observe_metrics_AutoHttpMetricsConfig.adoc[tag=config,leveloffset=+2]
9595
96-
If you specify the `auto` section, by default Helidon does not measure built-in endpoints such as metrics, health, and openapi. You can add items under `auto.paths` to control more exactly which endpoints to measure.
96+
The `paths` section contains zero or more entries, each entry having the following settings:
9797
98-
If you include the `paths` section, a given request matches an entry if its path matches the path pattern and its HTTP method is in the `methods` list. If there is no `methods` list for an entry, all HTTP methods match the entry.
98+
--
99+
.`path` entry settings
100+
[cols="4,2,4,20"]
101+
|====
102+
|Key | Required | Default Value | Usage
103+
104+
| `path`
105+
| yes
106+
| {nbsp}
107+
a| Path-matching expression:
108+
109+
* an exact match (`/greet`)
110+
* a prefix match (`/greet/*`)
111+
* a pattern match (`/greet/{name}`)
112+
113+
| `methods` | {nbsp} | all HTTP method types | Which HTTP methods match this entry
99114
100-
If a request matches an entry, the request is measured if the entry's `enabled` setting is true (the default).
115+
| `enabled` | {nbsp} | `true` | Whether this entry votes to match requests which match the entry
116+
|====
117+
--
101118
102-
If a request matches multiple entries, the last one matched wins.
119+
Helidon decides whether to measure incoming requests as follows:
103120
104-
If a request matches no entries, it is measured.
121+
* If you omit the `auto` configuration, Helidon measures all endpoints.
122+
* If you specify the `auto` configuration, by default Helidon does not measure built-in endpoints such as metrics, health, and openapi. You can add items under `auto.paths` to control more exactly which endpoints to measure.
123+
* If you include the `paths` section, Helidon checks a request against the path entries in order. A given request matches an entry if its path matches the path pattern and its HTTP method is in the `methods` list. If there is no `methods` list for an entry, all HTTP methods match the entry.
124+
* If a request matches an entry, the entry "votes" whether the request should be measured based on the entry's `enabled` setting.
125+
* If a request matches multiple entries, the last one voting wins.
126+
* If a request matches no entries, it is measured.
105127
106-
You can also control which sockets are included in the measurements.
128+
The `auto.sockets` setting controls which sockets are included in the measurements; if not set, Helidon measures requests on all sockets.
107129
130+
ifdef::se-flavor[]
108131
[source,yaml]
132+
endif::se-flavor[]
133+
ifdef::mp-flavor[]
134+
[source,properties]
135+
endif::mp-flavor[]
109136
.Including and Excluding Endpoints from Automatic Measurement
137+
ifdef::se-flavor[]
110138
----
111139
server:
112140
features:
@@ -121,6 +149,18 @@ server:
121149
enabled: false
122150
sockets: ["@default","private"] # <3>
123151
----
152+
endif::se-flavor[]
153+
ifdef::mp-flavor[]
154+
----
155+
server.features.observe.observers.metrics.auto.paths.0.path=/greet # <1>
156+
server.features.observe.observers.metrics.auto.paths.0.methods=GET,HEAD
157+
158+
server.features.observe.observers.metrics.auto.paths.1.path=/greet/{name} # <2>
159+
server.features.observe.observers.metrics.auto.paths.1.enabled=false
160+
161+
server.features.observe.observers.metrics.auto.sockets=@default,private # <3>
162+
----
163+
endif::mp-flavor[]
124164
<1> Measure `/greet` for only `GET` and `HEAD` requests.
125165
<2> Do not measure the personalized greeting requests.
126166
<3> Measure only endpoints on the default socket and the socket named `private`. Endpoints on other sockets (such as if you had an `admin` socket) are not measured.

microprofile/metrics/src/test/java/io/helidon/microprofile/metrics/HelloWorldPathMethodSelectionTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@
5959
*/
6060
@HelidonTest
6161
@AddConfig(key = "metrics." + MetricsCdiExtension.REST_ENDPOINTS_METRIC_ENABLED_PROPERTY_NAME, value = "true")
62-
@AddConfig(key = "metrics.permit-all", value = "true")
63-
@AddConfigBlock(type = "yaml", value = """
64-
metrics:
65-
auto:
66-
paths:
67-
- path: "/"
68-
methods: ["HEAD"]
69-
- path: "/withArg/{name}"
70-
enabled: false
62+
@AddConfigBlock(value = """
63+
metrics.auto.paths.0.path=/
64+
metrics.auto.paths.0.methods=HEAD,OPTIONS
65+
metrics.auto.paths.1.path=/withArg/{name}
66+
metrics.auto.paths.1.enabled=false
7167
""")
68+
7269
@AddBean(CatchAllExceptionMapper.class)
7370
class HelloWorldPathMethodSelectionTest {
7471

webserver/observe/metrics/src/main/java/io/helidon/webserver/observe/metrics/AutoHttpMetricsConfigBlueprint.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ interface AutoHttpMetricsConfigBlueprint {
4949

5050
/**
5151
* Automatic metrics collection settings. Default excludes built-in Helidon paths (e.g., metrics, health).
52+
* A request's path and HTTP method are checked against each entry under {@code paths} in order.
53+
* <ul>
54+
* <li>If a request matches no entry, then the request is measured.</li>
55+
* <li>If a request matches multiple entries, then the last match wins.</li>
56+
* </ul>
5257
*
5358
* @return automatic metrics collection settings
5459
*/

webserver/observe/metrics/src/main/java/io/helidon/webserver/observe/metrics/AutoHttpMetricsPathConfigBlueprint.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
/**
2929
* Settings for path-based automatic metrics configuration.
3030
* <p>
31-
* The {@link #enabled} setting (true or false) applies to any request which matches the {@linkplain #path() path matcher} and the
32-
* {@linkplain #methods() HTTP methods} specified.
31+
* An HTTP request matches a path entry if the request path matches the entry's path pattern and the request's HTTP method
32+
* matches one of the entry's methods. If there no {@code methods} list for the entry, then all HTTP methods match the entry.
33+
* <p>
34+
* If a request matches an entry, then the entry's {@code enabled} value (which defaults to {@code}) determines the entry's vote
35+
* whether the request should be measured. If a request matches multiple entries, the vote of the last matched entry wins.
3336
*
3437
*/
3538
@Prototype.Configured
@@ -51,7 +54,8 @@ static AutoHttpMetricsPathConfig disabled(String path) {
5154
}
5255

5356
/**
54-
* Whether automatic metrics are to be enabled for the specified {@link io.helidon.http.PathMatcher} and HTTP methods.
57+
* Whether automatic metrics are to be enabled for requests which match the specified {@link io.helidon.http.PathMatcher}
58+
* and HTTP methods.
5559
*
5660
* @return whether auto metrics are to be enabled for this path config's path matcher and HTTP methods
5761
*/
@@ -68,7 +72,7 @@ static AutoHttpMetricsPathConfig disabled(String path) {
6872
PathMatcher path();
6973

7074
/**
71-
* HTTP methods for which this path config applies.
75+
* HTTP methods for which this path config applies; default is to match all HTTP methods.
7276
*
7377
* @return HTTP methods
7478
*/

0 commit comments

Comments
 (0)