Skip to content

Commit

Permalink
SE metrics doc reorg (helidon-io#4543)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjquinno authored and romain-grecourt committed Jul 21, 2022
1 parent e1e9505 commit 0651f13
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 211 deletions.
2 changes: 2 additions & 0 deletions docs/includes/attributes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ endif::[]
:microprofile-metrics-spec-url: {microprofile-metrics-base-url}/microprofile-metrics-spec-{version-lib-microprofile-metrics-api}.html
:microprofile-metrics-javadoc-url: {microprofile-metrics-base-url}/apidocs
:microprofile-metrics-javadoc-annotation-url: {microprofile-metrics-javadoc-url}/org/eclipse/microprofile/metrics/annotation
:microprofile-metrics-javadoc-metric-url: {microprofile-metrics-javadoc-url}/org/eclipse/microprofile/metrics
:microprofile-tracing-base-url: {microprofile-base-url}/microprofile-tracing-{version-lib-microprofile-tracing}
:microprofile-tracing-spec-url: {microprofile-tracing-base-url}/microprofile-tracing-spec-{version-lib-microprofile-tracing}.html
Expand Down Expand Up @@ -187,6 +188,7 @@ endif::[]
:metrics-mp-javadoc-base-url: {javadoc-base-url}/io.helidon.microprofile.metrics
:metrics-serviceapi-javadoc-base-url: {javadoc-base-url}/io.helidon.metrics.serviceapi
:micrometer-javadoc-base-url: {javadoc-base-url}/io.helidon.integrations.micrometer
:prometheus-javadoc-base-url: {javadoc-base-url}/io.helidon.metrics.prometheus
:mp-cors-javadoc-base-url: {javadoc-base-url}/io.helidon.microprofile.cors
:mp-tyrus-javadoc-base-url: {javadoc-base-url}/io.helidon.microprofile.tyrus
:mp-restclient-javadoc-base-url: {javadoc-base-url}/io.helidon.microprofile.restclient
Expand Down
4 changes: 2 additions & 2 deletions docs/includes/metrics/metrics-capable-components.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This document explains Helidon {h1-prefix} metrics-capable components and applic
// end::preamble[]
// tag::all-beginning-text[]
== Introduction
Think of Helidon metrics in three related but different parts:
* The Helidon metrics API.
Expand Down Expand Up @@ -170,7 +170,7 @@ Doing so allows your code to operate regardless of whether the full-featured met
----
This module defines the metrics API: `RegistryFactory`, `MetricRegistry`, and the various metrics themselves.
ifeval::["{h1-prefix}" == "SE"]
ifdef::se-flavor[]
. To permit the use of the built-in metrics web service support for the `/metrics` endpoint, add this dependency:
+
[source,xml]
Expand Down
21 changes: 8 additions & 13 deletions docs/includes/metrics/metrics-config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ The rest of this section illustrates some of the most common scenarios:
* <<config-disable,Disable metrics entirely.>>
* <<config-selective,Selectively enable or disable metrics by metric registry type and, within type, by name.>>
* <<config-kpi,Choose whether to collect extended key performance indicator metrics.>>
ifdef::mp-flavor[]
* <<config-rest-request,Control `REST.request` metrics collection.>>
[[config-disable]]
endif::[]
[#config-disable]
==== Disable Metrics Subsystem
.Disabling metrics entirely
Expand All @@ -64,7 +66,7 @@ metrics:
endif::[]
Helidon does not update metrics, and the `/metrics` endpoints respond with `404` plus a message that the metrics subsystem is disabled.
[[config-selective]]
[#config-selective]
==== Disable Selected Metrics
You can be even more selective. Within a registry type you can configure up to two regular expression patterns:
Expand Down Expand Up @@ -110,7 +112,7 @@ endif::[]
This setting excludes metrics with names starting with `myapp.supplier` _except_ for the metric `myapp.supplier.updates`. The `exclude` and `include` values are regular expressions.
[[config-kpi]]
[#config-kpi]
==== Collecting Basic and Extended Key Performance Indicator (KPI) Metrics
Any time you include the Helidon metrics module in your application, Helidon tracks two basic performance indicator metrics:
Expand Down Expand Up @@ -146,23 +148,16 @@ metrics:
----
endif::[]
[[config-rest-request]]
[#config-rest-request]
ifdef::mp-flavor[]
==== Enable `REST.request` metrics
.Controlling REST request metrics
ifdef::mp-flavor[]
[source,properties]
----
metrics.rest-request-enabled=true
----
endif::[]
ifdef::se-flavor[]
[source,yaml]
----
metrics:
rest-request-enabled: true
----
endif::[]
Helidon will automatically register and update `SimpleTimer` metrics for every REST endpoint in your service.
endif::[]
// end::config-examples[]
171 changes: 171 additions & 0 deletions docs/includes/metrics/metrics-shared.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2021, 2022 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

///////////////////////////////////////////////////////////////////////////////
// tag::overview[]
ifndef::rootdir[:rootdir: {docdir}/../..]
ifndef::flavor-lc[:flavor-lc: se]
:description: Helidon metrics
:keywords: helidon, metrics
:writing-code-content: code which explicitly invokes the metrics API to register metrics, retrieve previously-registered metrics, and update metric values.
* a unified way for
ifdef::mp-flavor[MicroProfile]
ifdef::se-flavor[Helidon]
servers to export monitoring data--telemetry--to management agents, and
* a unified Java API which all application programmers can use to register and update metrics to expose telemetry data from their services.
ifdef::mp-flavor[]
* support for metrics-related annotations.
endif::[]
Learn more about the https://github.com/eclipse/microprofile-metrics/releases/tag/{version-lib-microprofile-metrics-api}[MicroProfile Metrics specification].
// end::overview[]
// tag::usage-body[]
=== Instrumenting Your Service
You add metrics to your service
ifdef::se-flavor[]
by writing {writing-code-content}
endif::[]
ifdef::mp-flavor[]
in these ways:
* Annotate bean methods--typically your REST resource endpoint methods (the Java code that receives incoming REST requests); Helidon automatically registers these metrics and updates them when the annotated methods are invoked via CDI.
* Write {writing-code-content}
* Configure some simple `REST.request` metrics which Helidon automatically registers and updates for all REST resource endpoints.
endif::[]
Later sections of this document describe how to do
ifdef::mp-flavor[each of these.]
ifdef::se-flavor[this.]
=== Categorizing Types of Metrics
Helidon distinguishes among three general _types_, or scopes, of metrics, as described in the MP metrics specification.
.Types (scopes) of metrics
[%autowidth]
|====
| Type/scope | Typical Usage
| base | Mandated by the MP metrics specification, such as OS or Java runtime measurements (available heap, disk space, etc.).
| vendor | Implemented by vendors, including the `REST.request` metrics and other key performance indicator measurements (described in later sections).
| application | Declared via annotations or programmatically registered by your service code.
|====
When you add metrics annotations to your service code, Helidon registers the resulting metrics as type `application`.
=== Metric Registries
A _metric registry_ collects registered metrics of a given type. Helidon supports three registries, one for each of the three metrics types.
When you add code to your service to create a metric programmatically, the code first locates the appropriate registry and then registers the metric with that registry.
=== Retrieving Metrics Reports from your Service
When you add the metrics dependency to your project, Helidon automatically provides a built-in REST endpoint `/metrics` which responds with a report of the registered metrics and their values.
Clients can request a particular output format.
.Formats for `/metrics` output
[%autowidth]
|====
| Format | Requested by
| OpenMetrics (Prometheus) | default (`text/plain`)
| JSON | Header `Accept: application/json`
|====
Clients can also limit the report by appending the metric type to the path:
* `/metrics/base`
* `/metrics/vendor`
* `/metrics/application`
Further, clients can narrow down to a specific metric name by adding the name as a subpath such as `/metrics/application/myCount`.
[source,bash]
.Example Reporting: Prometheus format
----
curl -s -H 'Accept: text/plain' -X GET http://localhost:8080/metrics/
----
[listing]
----
# TYPE base:classloader_total_loaded_class_count counter
# 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.
base:classloader_total_loaded_class_count 3157
----
.Example Reporting: JSON format
[source,bash]
----
curl -s -H 'Accept: application/json' -X GET http://localhost:8080/metrics/
----
[listing]
----
{
"base" : {
"memory.maxHeap" : 3817865216,
"memory.committedHeap" : 335544320,
}
}
----
In addition to your application metrics the reports contain other
metrics of interest such as system and VM information.
// end::usage-body[]
// tag::metric-registry-api[]
=== The `MetricRegistry` API
To register or look up metrics programmatically, your service code uses one of the three link:{microprofile-metrics-javadoc-url}/org/eclipse/microprofile/metrics/MetricRegistry.html[`MetricRegistry`] instances (base, vendor, and application) which Helidon furnishes automatically.
ifdef::mp-flavor[]
To get a `MetricRegistry` reference
* `@Inject` the metric registry you want, perhaps also using the link:{microprofile-metrics-javadoc-annotation-url}/RegistryType.html[`@RegistryType`] annotation to select the registry type, or
* Get a Helidon link:{metrics-javadoc-base-url}/RegistryFactory.html[`RegistryFactory`]; either
+
--
** `@Inject` `RegistryFactory` or
** Invoke one of the static `getInstance` methods on `RegistryFactory`
--
+
Then invoke `getRegistry` on the `RegistryFactory` instance.
endif::[]
ifdef::se-flavor[]
To get a `MetricRegistry` reference, first get a Helidon link:{metrics-javadoc-base-url}/RegistryFactory.html[`RegistryFactory`].
Then invoke `getRegistry` on the `RegistryFactory` instance.
endif::[]
The `MetricRegistry` allows your code to register new metrics, look up previously-registered metrics, and remove metrics.
// end::metric-registry-api[]
// tag::example-apps[]
Helidon {flavor-uc} includes several prewritten example applications illustrating aspects of metrics:
* link:{helidon-github-tree-url}/examples/metrics/filtering/{flavor-lc}[Enabling/disabling metrics] using
ifdef::se-flavor[`MetricsSettings`]
ifdef::mp-flavor[configuration]
ifdef::se-flavor[]
* link:{helidon-github-tree-url}/examples/metrics/kpi[Controlling key performance indicator metrics] using configuration and `KeyPerformanceIndicatorMetricsSettings`.
endif::[]
// end::example-apps[]
15 changes: 11 additions & 4 deletions docs/includes/metrics/micrometer-shared.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,23 @@ meter registries.
// tag::accessing-endpoint-intro[]
=== Accessing the Helidon Micrometer Endpoint
Helidon automatically creates a REST endpoint which clients can access to retrieve Micrometer metrics, by default at the `/micrometer` endpoint.
ifdef::mp-flavor[Helidon MP Micrometer integration automatically creates]
ifdef::se-flavor[Your application can easily have Helidon create]
a REST endpoint which clients can access to retrieve Micrometer metrics, by default at the `/micrometer` endpoint.
ifdef::se-flavor[]
Within Helidon, each type of meter registry is paired with code that examines the incoming HTTP request and decides
Within Helidon, each type of meter registry is paired with some code that examines the incoming HTTP request to `/micrometer` and decides
whether the request matches up with the associated meter registry. The first pairing that accepts the request
returns the response.
returns the response. You will need to take advantage of this if your application uses additional meter registries beyond what Helidon automatically provides _and_ you want those meter registries reflected in the output from the `/micrometer` REST endpoint.
endif::[]
// end::accessing-endpoint-intro[]
// tag::configuring-endpoint[]
== Configuration
You can configure the Helidon Micrometer REST service as you can other built-in Helidon services by adding configuration settings under the `micrometer` top-level key.
include::{rootdir}/config/io_helidon_integrations_micrometer_MicrometerSupport.adoc[leveloffset=+1]
include::{rootdir}/config/io_helidon_integrations_micrometer_MicrometerSupport.adoc[tag=config,leveloffset=+1]
By default, Helidon Micrometer integration exposes the `/micrometer` endpoint.
You can override the path using
Expand Down Expand Up @@ -183,5 +186,9 @@ endif::[]
can create, look up, and update metrics programmatically using the Micrometer `MeterRegistry` API. The link:{micrometer-api-url}[Micrometer concepts document] provides a good starting point for learning how to use Micrometer's interfaces and classes.
// end::use-micrometer-api[]
// tag::example-apps[]
Helidon {flavor-uc} includes an link:{helidon-github-tree-url}/examples/integrations/micrometer/{flavor-lc}[example application] which uses Micrometer support.
// end::example-apps[]
// end::all-micrometer[]
12 changes: 9 additions & 3 deletions docs/includes/metrics/prometheus-exemplar-support.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ link:https://www.merriam-webster.com/dictionary/exemplar[_exemplar_] - one that
-- Merriam-Webster Dictionary
--
In the context of metrics, an _exemplar_ for a given metric is a specific trace which, in some sense, made a typical contribution to the metric's value. For example, an exemplar for a `SimpleTimer` might be a trace in which the duration it contributed to the value of a `SimpleTimer` is near the mean of the durations over all traces.
In the context of metrics, an _exemplar_ for a given metric is a specific sample which, in some sense, made a typical contribution to the metric's value. For example, an exemplar for a `SimpleTimer` might be a sample in which the duration it contributed to the value of a `SimpleTimer` is near the mean of the durations over all samples. The metrics output identifies the exemplar sample using the trace ID of the trace which triggered that sample.
include::{rootdir}/includes/dependencies.adoc[]
Expand Down Expand Up @@ -91,13 +91,13 @@ Helidon chooses the representative examplar for each value using information tha
.Selection of exemplars for types of metrics
[%autowidth]
|====
|Metric Type| Example | Sample Selected as Exemplar
|Metric Value Type| Example | Sample Selected as Exemplar
| corresponds directly to a specific sample
| minimum or maximum of a value
| any sample with that exact value
| collecs samples into bins (quantiles)
| collects samples into bins (quantiles)
| histogram (as with timers)
| any sample from the bin
Expand Down Expand Up @@ -126,6 +126,12 @@ But some consumers, such as trace collectors and their U/Is, understand the exem
== Examples
ifdef::se-flavor[]
Helidon includes an link:{helidon-github-tree-url}/examples/metrics/exemplar[example application], based on the QuickStart application, which illustrates exemplar support.
endif::[]
Once you enable exemplar support you can see the exemplars in the metrics output.
.Exemplar output - `Timer`
[listing,subs="quotes"]
----
Expand Down
Loading

0 comments on commit 0651f13

Please sign in to comment.