You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow metrics-capable components to work in absence of full-featured metrics (helidon-io#3441)
* Allow metrics-capable components to be written and executed without caring whether full-featured metrics are on the runtime path and enabled
Signed-off-by: tim.quinn@oracle.com <tim.quinn@oracle.com>
NOTE: You cannot get the individual fields of a metric. For example, you cannot target http://localhost:8080/metrics/vendor/requests.meter.count.
165
174
// end::get-single-metric[]
166
175
176
+
// tag::controlling[]
177
+
// tag::controlling-intro[]
178
+
179
+
=== Controlling Metrics Behavior
180
+
You can control how metrics behaves in several ways by adding a `metrics` section to your application configuration. You can:
181
+
182
+
* disable metrics entirely,
183
+
* disable the use of metrics from individual components, and
184
+
* control the key performance indicator metrics which Helidon collects.
185
+
186
+
// end::controlling-intro[]
187
+
188
+
// tag::enabling-disabling-whole-intro[]
189
+
==== Enabling and Disabling Metrics as a Whole
190
+
By default, if your application depends on the `helidon-metrics` Maven module then full-featured metrics are enabled.
191
+
You can disable metrics entirely using configuration:
192
+
[source,properties]
193
+
.Configuration properties file disabling metrics
194
+
----
195
+
metrics.enabled=false
196
+
----
197
+
// end::enabling-disabling-whole-intro[]
198
+
199
+
// tag::enabling-disabling-whole-summary[]
200
+
With metrics disabled, Helidon never updates any metrics and the `/metrics` endpoints respond with `404` plus a message that metrics are disabled.
201
+
// end::enabling-disabling-whole-summary[]
202
+
203
+
// tag::controlling-by-component-intro[]
204
+
==== Enabling and Disabling Metrics Usage by a Component
205
+
Helidon contains several components and integrations which register and update metrics.
206
+
Depending on how the component is written, you might be able to disable just that component's use of metrics:
207
+
[source,properties]
208
+
.Configuration properties file disabling a component's use of metrics
209
+
----
210
+
some-component.metrics.enabled=false
211
+
----
212
+
Check the documentation for a specific component to find out whether that component uses metrics and whether it allows you to disable that use.
213
+
// end::controlling-by-component-intro[]
214
+
215
+
// tag::controlling-by-component-summary[]
216
+
If you disable a component's use of metrics, Helidon does not register the component's metrics in the visible metrics registries nor do those metrics ever update their values. The response from the `/metrics` endpoint excludes that component's metrics.
217
+
218
+
Note that if you disable overall metrics, no component updates its metrics regardless of any component-level metrics settings.
219
+
// end::controlling-by-component-summary[]
220
+
167
221
// tag::KPI[]
168
222
==== Key Performance Indicator (KPI) Metrics
169
223
Any time you include the Helidon metrics module in your application, Helidon tracks two basic performance indicator metrics:
@@ -185,23 +239,8 @@ You can enable and control these metrics using configuration:
Your Helidon {h1Prefix} application can also control the behavior of the KPI metrics programmatically.
191
-
192
-
. Prepare a `KeyPerformanceIndicatorSettings` object, using its builder, and then pass the builder when invoking the `MetricsSupport.Builder#keyPerformanceIndicatorMetricsSettings()` method.
193
-
. Prepare a `Config` object and pass it to the `MetricsSupport.Builder#keyPerformanceIndicatorMetricsConfig()` method.
For the SE guide, we stitch in the shared content about controlling metrics around SE-specific content that is not shared. It makes for a bit choppy-looking source here but it renders just fine and lets us easily share the content that's common between SE and MP.
89
+
90
+
////
91
+
include::{metrics-common}[tag=controlling-intro]
92
+
93
+
Your Helidon SE application can also control metrics programmatically as described in the following sections.
<1> Create a link:{javadoc-base-url-api}/MetricsSettings.html[`MetricsSettings]` instance (via its link:{javadoc-base-url-api}/MetricsSettings.Builder.html[`Builder`]) with metrics disabled.
115
+
<2> Get a link:{javadoc-base-url-api}/MetricsSupport.html[`MetricsSupport]` service (usable in setting routing rules) that responds
116
+
to the `/metrics` endpoint with `404` and an explanatory message.
117
+
<3> Get a link:{javadoc-base-url-api}/RegistryFactory.html[`RegistryFactory]` instance that provides `MetricRegistry` instances which register
118
+
no-op metric objects (counters, timers, etc.).
119
+
120
+
These builders and interfaces also have methods which accept `Config` objects representing the `metrics` node from the application configuration.
Your Helidon SE application can also enable or disable the extended KPI metrics and control the long-running request threshold using methods on the link:{metrics-support-builder-javadoc}[MetricsSupport.Builder] class.
126
+
Your Helidon SE application can also control the KPI settings programmatically.
<1> Create a link:{javadoc-base-url-api}/KeyPerformanceIndicatorMetricsSettings.html[`KeyPerformanceIndicatorMetricsSettings]` instance (via its link:{javadoc-base-url-api}/KeyPerformanceIndicatorMetricsSettings.Builder.html[`Builder`]) with non-default values.
146
+
<2> Create a link:{javadoc-base-url-api}/MetricsSettings.html[`MetricsSettings]` instance reflecting the KPI settings.
<1> Create a link:{javadoc-base-url-api}/ComponentMetricsSettings.html[`ComponentMetricsSettings]` instance (via its link:{javadoc-base-url-api}/ComponentMetricsSettings.Builder.html[`Builder`]) indicating that metrics usage should be disabled.
169
+
<2> Create an instance of the service with its metrics usage disabled.
=== Advanced Topic: Metrics-capable Applications and Components
738
+
Metrics-capable components are written to register and update metrics but can work even if the Helidon metrics implementation _is not_ on the runtime path. Please see this additional section on <<se/guides/_metrics-capable-components.adoc,Metrics-capable components>> which describes this feature.
739
+
657
740
=== Summary
658
741
659
742
This guide demonstrated how to use metrics in a Helidon SE application using various combinations of
0 commit comments