Skip to content

Commit 22dc5c9

Browse files
authored
Enhance metrics doc and Javadoc on Helidon metrics API types (#9635)
* Enhance metrics doc and Javadoc on Helidon metrics API types --------- Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
1 parent 867a60e commit 22dc5c9

File tree

11 files changed

+155
-27
lines changed

11 files changed

+155
-27
lines changed

applications/parent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<version.plugin.dependency>3.6.0</version.plugin.dependency>
4242
<version.plugin.exec>3.1.0</version.plugin.exec>
4343
<version.plugin.failsafe>3.1.2</version.plugin.failsafe>
44-
<version.plugin.helidon>4.0.14</version.plugin.helidon>
45-
<version.plugin.helidon-cli>4.0.14</version.plugin.helidon-cli>
44+
<version.plugin.helidon>4.0.15</version.plugin.helidon>
45+
<version.plugin.helidon-cli>4.0.15</version.plugin.helidon-cli>
4646
<version.plugin.jar>3.3.0</version.plugin.jar>
4747
<version.plugin.nativeimage>0.10.2</version.plugin.nativeimage>
4848
<version.plugin.os>1.5.0.Final</version.plugin.os>

docs/src/main/asciidoc/includes/attributes.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ endif::[]
277277
:oracle-ucp-javadoc-base-url: https://docs.oracle.com/en/database/oracle/oracle-database/{version-lib-oracle-ucp}/jjuar
278278
279279
:micrometer-url: https://micrometer.io
280-
:micrometer-api-url: https://docs.micrometer.io/micrometer/reference/concepts.html
280+
:micrometer-api-url: https://docs.micrometer.io/micrometer/reference/concepts
281281
:micrometer-javadoc-base-url: https://javadoc.io/doc/io.micrometer
282282
:micrometer-javadoc-registry-prometheus-base-url: {micrometer-javadoc-base-url}/micrometer-registry-prometheus/{version-lib-micrometer}/io/micrometer/prometheus
283283
@@ -290,6 +290,10 @@ endif::[]
290290
:openapi-generator-tool-generators-docs-url: {openapi-generator-tool-docs-url}/generators
291291
:openapi-generator-tool-site-url: https://openapi-generator.tech
292292
293+
// Exposition formats for metrics
294+
:prometheus-exposition-format-doc-url: https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md
295+
:openmetrics-format-doc-url: https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md
296+
293297
// GraalVM
294298
:graalvm-jdk-version: 21
295299
:graalvm-doc-url: https://www.graalvm.org/jdk{graalvm-jdk-version}/

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

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
22

3-
Copyright (c) 2021, 2024 Oracle and/or its affiliates.
3+
Copyright (c) 2021, 2025 Oracle and/or its affiliates.
44

55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@ ifndef::flavor-lc[:flavor-lc: se]
2323
:description: Helidon metrics
2424
:keywords: helidon, metrics
2525
:writing-code-content: code which explicitly invokes the metrics API to register {metrics}, retrieve previously-registered {metrics}, and update {metric} values.
26+
ifdef::se-flavor[:prom-output-scope-prefix: ]
27+
ifdef::mp-flavor[:prom-output-scope-prefix: mp_]
2628
2729
* a unified way for
2830
ifdef::mp-flavor[MicroProfile]
@@ -73,16 +75,66 @@ Later sections of this document describe how to do
7375
ifdef::mp-flavor[each of these.]
7476
ifdef::se-flavor[this.]
7577
78+
// tag::meter-types-summary[]
79+
=== {metric_uc} Types
80+
81+
Helidon supports meters
82+
ifdef::se-flavor[inspired by link:{micrometer-url}[Micrometer]]
83+
ifdef::mp-flavor[described by the link:{microprofile-metrics-spec-url}[MicroProfile Metrics] spec]
84+
and summarized in the following table:
85+
86+
.Types of {metrics_uc}
87+
[cols="3,8,2"]
88+
|====
89+
| {metric_uc} Type | Description |
90+
ifdef::se-flavor[Micrometer reference]
91+
ifdef::mp-flavor[Related MicroProfile annotation]
92+
93+
|
94+
ifdef::se-flavor[link:{metrics-javadoc-base-url}/io/helidon/metrics/api/Counter.html[`Counter`]]
95+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-metric-url}/Counter.html[`Counter`]]
96+
| Monotonically-increasing `long` value. |
97+
ifdef::se-flavor[link:{micrometer-api-url}/counters.html[Counters]]
98+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-annotation-url}/Counted.html[`@Counted`]]
99+
100+
|
101+
ifdef::se-flavor[link:{metrics-javadoc-base-url}/io/helidon/metrics/api/DistributionSummary.html[`DistributionSummary`]]
102+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-metric-url}/Histogram.html[`Histogram`]]
103+
104+
| Summary of samples each with a `long` value. Reports aggregate information over all samples (count, total, mean, max) as well as the distribution of sample values using percentiles and bucket counts. |
105+
ifdef::se-flavor[link:{micrometer-api-url}/distribution-summaries.html[Distribution summaries]]
106+
ifdef::mp-flavor[(none)]
107+
108+
|
109+
ifdef::se-flavor[link:{metrics-javadoc-base-url}/io/helidon/metrics/api/Timer.html[`Timer`]]
110+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-metric-url}/Timer.html[`Timer`]]
111+
| Accumulation of short-duration (typically under a minute) intervals. Typically updated using a Java link:{jdk-javadoc-url}/java.base/java/time/Duration.html[`Duration`] or by recording the time taken by a method invocation or lambda. Reports the count, total time, max, and mean; provides a
112+
ifdef::se-flavor[distribution summary]
113+
ifdef::mp-flavor[histogram]
114+
of the samples. |
115+
ifdef::se-flavor[link:{micrometer-api-url}/timers.html[Timers]]
116+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-annotation-url}/Timed.html[`@Timed`]]
117+
118+
|
119+
ifdef::se-flavor[link:{metrics-javadoc-base-url}/io/helidon/metrics/api/Gauge.html[`Gauge<? extends Number>`]]
120+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-metric-url}/Gauge.html[`Gauge<? extends Number>`]]
121+
| View of a value that is assignment-compatible with a subtype of Java link:{jdk-javadoc-url}/java.base/java.lang.Number.html[`Number`]. The underlying value is updated by code elsewhere in the system, not by invoking methods on the gauge itself. |
122+
ifdef::se-flavor[link:{micrometer-api-url}/gauges.html[Gauges]]
123+
ifdef::mp-flavor[link:{microprofile-metrics-javadoc-annotation-url}/Gauge.html[`@Gauge`]]
124+
|====
125+
126+
// end::meter-types-summary[]
127+
76128
=== Categorizing Types of {Metrics_uc}
77-
Helidon distinguishes among _scopes_, or types, of
129+
Helidon distinguishes among _scopes_, or categories, of
78130
ifdef::se-flavor[{metrics}.]
79131
ifdef::mp-flavor[{metrics} as described in the link:{microprofile-metrics-spec-url}[MP metrics specification].]
80132
81133
Helidon includes {metrics} in the built-in scopes described below.
82134
Applications often register their own {metrics} in the `application` scope but can create their own scopes and register {metrics} within them.
83135
84136
.Built-in {metric} scopes
85-
[%autowidth]
137+
[cols="2,8"]
86138
|====
87139
| Built-in Scope | Typical Usage
88140
@@ -134,12 +186,13 @@ Further, clients can narrow down to a specific metric name by adding the name as
134186
curl -s -H 'Accept: text/plain' -X GET http://localhost:8080{metrics-endpoint}
135187
----
136188
137-
[source,text]
189+
[source,text,subs="attributes+"]
138190
----
139-
# TYPE base:classloader_total_loaded_class_count counter
140-
# HELP base:classloader_total_loaded_class_count Displays the total number of classes that have been loaded since the Java virtual machine has started execution.
141-
base:classloader_total_loaded_class_count 3157
191+
# HELP classloader_loadedClasses_count Displays the number of classes that are currently loaded in the Java virtual machine.
192+
# TYPE classloader_loadedClasses_count gauge
193+
classloader_loadedClasses_count{{prom-output-scope-prefix}scope="base",} 5297.0
142194
----
195+
See the summary of the <<OpenMetrics and Prometheus Format, OpenMetrics and Prometheus Format>> for more information.
143196
144197
[source,bash,subs="attributes+"]
145198
.Example Reporting: JSON format
@@ -161,6 +214,59 @@ curl -s -H 'Accept: application/json' -X GET http://localhost:8080{metrics-endpo
161214
In addition to your application {metrics}, the reports contain other
162215
{metrics} of interest such as system and VM information.
163216
217+
==== OpenMetrics and Prometheus Format
218+
The link:{openmetrics-format-doc-url}[OpenMetrics format] and the link:{prometheus-exposition-format-doc-url}[Prometheus exposition format] are very similar in most important respects but are not identical. This brief summary treats them as the same.
219+
220+
The OpenMetrics/Prometheus format represents each {metric} using three lines of output as summarized in the following table.
221+
222+
.OpenMetrics/Prometheus format
223+
[cols="1,6,6"]
224+
|====
225+
| Line prefix | Purpose | Format
226+
227+
| `# TYPE` | Displays the scope, name, and type of the {metric} | `TYPE <scope>:<output-name> <{metric}-type>`
228+
| `# HELP` | Displays the scope, name, and description of the {metric} | `HELP <scope>:<output-name> <registered description>`
229+
| (none) | Displays the scope, {metric} ID, and current value of the {metric} | `<scope>:<output-name> <current value>`
230+
|====
231+
The OpenMetrics/Prometheus output converts {metric} IDs in these ways:
232+
233+
* Names in camel case are converted to "snake case" and dots are converted to underscores.
234+
* Names include any units specified for the {metric}.
235+
* For percentiles, the ID includes a tag identifying which percentile the line of output describes.
236+
237+
As the earlier example output showed, for a {metric} with multiple values, such as a timer or a
238+
ifdef::se-flavor[distribution summary,]
239+
ifdef::mp-flavor[histogram,]
240+
(with, among others, `max`, `mean`, and `count`), the OpenMetrics/Prometheus output reports a "metric family" which includes a separate family member {metric} for each of the multiple values. The name for each member in the family is derived from the registered name for the {metric} plus a suffix indicating which one of the {metric}'s multiple values the line refers to.
241+
242+
The following table summarizes the naming for each {metric} type.
243+
244+
.OpenMetrics/Prometheus {metric_uc} Naming
245+
|====
246+
| {metric_uc} Type | Example registered name | {metric_uc} family member | Name Suffix | Example displayed name
247+
248+
.1+| `Counter` | `requests.count` | count | `_total` | `requests_count_total`
249+
250+
.4+|
251+
ifdef::se-flavor[`DistributionSummary`]
252+
ifdef::mp-flavor[`Histogram`]
253+
.4+| `nameLengths`
254+
| count | `_count` | `nameLengths_count`
255+
| sum | `_sum` | `nameLengths_sum`
256+
| max | `_max` | `nameLengths_max`
257+
| percentile | none | `nameLengths{{prom-output-scope-prefix}scope="base",quantile="0.5",}`
258+
259+
.1+| `Gauge` | `classloader.loadedClasses.count` | value | none | `classloader_loadedClasses_count`
260+
261+
.4+| `Timer` ^1^
262+
.4+| `vthreads.recentPinned`
263+
| count | `_count` | `vthreads_recentPinned_seconds_count`
264+
| sum | `_sum` | `vthreads_recentPinned_seconds_sum`
265+
| max | `_max` | `vthreads_recentPinned_seconds_max`
266+
| percentile | none | `vthreads_recentPinned_seconds{{prom-output-scope-prefix}scope="base",quantile="0.5",}`
267+
|====
268+
^1^ The OpenMetrics/Prometheus output format reports a timer as a `summary` with units of `seconds`.
269+
164270
// end::usage-retrieving[]
165271
166272
// tag::metric-registry-api[]
@@ -223,3 +329,9 @@ ifdef::se-flavor[]
223329
endif::[]
224330
225331
// end::example-apps[]
332+
333+
// tag::format-refcs-no-heading[]
334+
link:{openmetrics-format-doc-url}[OpenMetrics format]
335+
336+
link:{prometheus-exposition-format-doc-url}[Prometheus exposition format]
337+
// end::format-refcs-no-heading[]

docs/src/main/asciidoc/mp/metrics/metrics.adoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
22

3-
Copyright (c) 2022, 2024 Oracle and/or its affiliates.
3+
Copyright (c) 2022, 2025 Oracle and/or its affiliates.
44

55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -86,17 +86,16 @@ The MicroProfile Metrics specification describes several metric types you can cr
8686
| Annotation | Usage
8787
8888
| link:{microprofile-metrics-javadoc-annotation-url}/Counted.html[`@Counted`]
89-
| Monotonically increasing count of events.
89+
| Automatically registers a monotonically-increasing `Counter` and increments it with each invocation of the annotated constructor or method. ^1^
9090
9191
| link:{microprofile-metrics-javadoc-annotation-url}/Gauge.html[`@Gauge`]
92-
| Access to a value managed by other code in the service.
92+
| Automatically registers a `Gauge` whose value is provided by the annotated method. Code elsewhere in the system updates the underlying value.
9393
9494
| link:{microprofile-metrics-javadoc-annotation-url}/Timed.html[`@Timed`]
95-
| Frequency of invocations and the distribution of how long the invocations take.
95+
| Automatically registers a `Timer` and updates it with each invocation of the annotated constructor or method. ^1^
9696
9797
|====
98-
99-
Place annotations on constructors or methods to measure those specific executables. If you annotate the class instead, Helidon applies that annotation to all constructors and methods which the class declares.
98+
^1^ Place annotations on constructors or methods to measure those specific executables. If you annotate the class instead, Helidon applies that annotation to all constructors and methods which the class declares.
10099
101100
==== Metric-referencing Annotations
102101
To get a reference to a specific metric, use a metric-referencing annotation in any bean, including your REST resource classes.
@@ -405,3 +404,5 @@ include::{rootdir}/includes/guides/metrics.adoc[tag=k8s-and-prometheus-integrati
405404
link:{microprofile-metrics-spec-url}[MicroProfile Metrics specification]
406405
407406
link:{microprofile-metrics-javadoc-url}/org/eclipse/microprofile/metrics/package-summary.html[MicroProfile Metrics API]
407+
408+
include::{rootdir}/includes/metrics/metrics-shared.adoc[tag=format-refcs-no-heading]

docs/src/main/asciidoc/se/metrics/metrics.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
22

3-
Copyright (c) 2018, 2024 Oracle and/or its affiliates.
3+
Copyright (c) 2018, 2025 Oracle and/or its affiliates.
44

55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ include::{rootdir}/includes/se.adoc[]
4545
** <<Example Application Code, Example Application Code>>
4646
** <<Example Configuration, Example Configuration>>
4747
- <<Additional Information, Additional Information>>
48+
** <<References, References>>
4849
** <<Support for the Prometheus Metrics API, Support for the Prometheus Metrics API>>
4950
5051
== Overview
@@ -270,6 +271,12 @@ include::{rootdir}/includes/metrics/metrics-config.adoc[tag=config-examples]
270271
271272
== Additional Information
272273
274+
=== References
275+
276+
link:{micrometer-api-url}[Micrometer Metrics concepts documentation]
277+
278+
include::{rootdir}/includes/metrics/metrics-shared.adoc[tag=format-refcs-no-heading]
279+
273280
=== Support for the Prometheus Metrics API
274281
- <<Maven Coordinates, Maven Coordinates>>
275282
- <<Usage, Usage>>

metrics/api/src/main/java/io/helidon/metrics/api/Counter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
package io.helidon.metrics.api;
1717

1818
/**
19-
* Records a monotonically increasing value.
19+
* Records a monotonically increasing value that is updated by invoking methods on the {@code Counter} instance.
2020
*/
2121
public interface Counter extends Meter {
2222

metrics/api/src/main/java/io/helidon/metrics/api/DistributionSummary.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,9 @@
1818
import java.util.Optional;
1919

2020
/**
21-
* Records a distribution of values (e.g., sizes of responses returned by a server).
21+
* Records a distribution of samples (e.g., sizes of responses returned by a server), each with a {@code long} value, and
22+
* reports statistics over all samples (count, total, mean, max) as well as grouping samples using percentiles or bucket
23+
* boundaries.
2224
*/
2325
public interface DistributionSummary extends Meter {
2426

metrics/api/src/main/java/io/helidon/metrics/api/Gauge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import java.util.function.ToDoubleFunction;
2020

2121
/**
22-
* Measures a value that can increase or decrease and is updated by external logic, not by explicit invocations
22+
* Exposes as a meter a value that can increase or decrease and is updated by external logic, not by explicit invocations
2323
* of methods on this type.
2424
*
2525
* @param <N> subtype of {@link Number} which a specific gauge reports

metrics/api/src/main/java/io/helidon/metrics/api/Timer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,9 @@
2222
import java.util.function.Supplier;
2323

2424
/**
25-
* Records timing information about large numbers of short-running events (e.g., HTTP requests).
25+
* Accumulates timing information about large numbers of short-running events (e.g., HTTP requests), each with a
26+
* {@link java.time.Duration} value, and reports statistics over all samples (count, total time, mean, max) as well as grouping
27+
* samples using percentiles or bucket boundaries.
2628
*/
2729
public interface Timer extends Meter, HistogramSupport {
2830

parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
<plugin>
169169
<groupId>io.helidon.build-tools</groupId>
170170
<artifactId>helidon-build-cache-maven-plugin</artifactId>
171-
<version>4.0.14</version>
171+
<version>4.0.15</version>
172172
</plugin>
173173
</plugins>
174174
</pluginManagement>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<version.plugin.exec>3.1.0</version.plugin.exec>
125125
<version.plugin.failsafe>3.1.2</version.plugin.failsafe>
126126
<version.plugin.glassfish-copyright>2.3</version.plugin.glassfish-copyright>
127-
<version.plugin.helidon-build-tools>4.0.14</version.plugin.helidon-build-tools>
127+
<version.plugin.helidon-build-tools>4.0.15</version.plugin.helidon-build-tools>
128128
<version.plugin.hibernate-enhance>${version.lib.hibernate}</version.plugin.hibernate-enhance>
129129
<version.plugin.install>3.1.2</version.plugin.install>
130130
<version.plugin.invoker>3.2.2</version.plugin.invoker>

0 commit comments

Comments
 (0)