Allow metrics-capable components to work in absence of full-featured metrics#3441
Merged
tjquinno merged 47 commits intohelidon-io:masterfrom Oct 19, 2021
tjquinno:metrics-noop
Merged
Allow metrics-capable components to work in absence of full-featured metrics#3441tjquinno merged 47 commits intohelidon-io:masterfrom tjquinno:metrics-noop
tjquinno merged 47 commits intohelidon-io:masterfrom
tjquinno:metrics-noop
Conversation
This was referenced Sep 28, 2021
ljnelson
reviewed
Sep 28, 2021
ljnelson
reviewed
Sep 28, 2021
ljnelson
reviewed
Sep 28, 2021
ljnelson
reviewed
Sep 28, 2021
ljnelson
reviewed
Sep 28, 2021
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
…aring whether full-featured metrics are on the runtime path and enabled Signed-off-by: tim.quinn@oracle.com <tim.quinn@oracle.com>
…est support for component metrics settings
…erve a (possibly incorrect) tolerance of mismatched metadata and metric type
…e overall metrics config (enable/disable)
… creating a MetricID; associated private method changes regarding metric type checking and casting
tomas-langer
requested changes
Oct 13, 2021
…he HelidonRestServiceSupport class directly implementing Service
…/minimal; remove webserver dep from metrics/api
… as its own first-class parameter to HelidonRestServiceSupport
…rics/service-api and clean up dependencies
…s impl and MP metrics CDI extension
…dep in MP full bundle for backward compatibility
…rovider and metrics support provider choices at start-up; reduce visibility of a class used only in-package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #2180
This PR creates two new components:
helidon-metrics-apiabstracts the behavior of registry factories, metrics registries, and metrics implementations. It includes "no-op" implementations of metrics which Helidon uses:helidon-metricsis not on the runtime path, orMetricsSettings.Builderor confighelidon-metrics-service-apiabstracts the behavior of theMetricsSupportwebserver-based metrics service and contains a minimal implementation which response with404to the metrics endpoints.The existing
helidon-metricscomponent remains and contains the full-featured implementations of metrics andMetricsSupport. For backward compatibility, the its formerRegistryFactoryclass is now an API-compatible interface which delegates to theRegistryFactoryinhelidon-metrics-api.See the
README.mdin thehelidon-metrics-apifor more details how metrics-capable components can be revised in small ways to take advantage of this new feature.As a general change, there are several places which used to use only
Configto locate settings (such as theweb-contextorrouting. Examples:helidon-service-common-rest,HelidonRestServiceSupport, andhelidon-microprofile-serverRoutingBuilders. For those places, this PR introduces settings POJOs and their builders which can be initialized from config as well as programmatically. A number of config-based methods are deprecated in favor of new, settings-based, alternatives.Here is a summary of the changes by component:
New component
helidon-metrics-apiMetricsSettingsPOJO which captures all the existing configurable behavior of metrics (enabled, base metric behavior, and KPI metrics settings) with implementations and factory methods.ComponentMetricsSettingswhich collects metrics behavior particular to a component, with implementations and factory methods. Currently just whether metrics should be enabled for the componentRegistryFactoryinterface and related service loading interfaceRegistryFactoryProviderinterface and loader class.BaseMetricinterface defining common behavior of full-featured and no-op metrics.AbstractRegistryimplements most ofMetricRegistrywith abstract methods for creating metrics instances; mostly a type-generalized copy of the previoushelidon-metricsRegistryclass.MetricRegistryandRegistryFactorywhich dispense the no-op metrics.README.mddescribing the revised approach and how to write or revise components to be _metrics-capableinstead ofmetrics-dependent`.New component
helidon-metrics-service-apiMetricsSupportinterface abstracting the behavior of the metrics web-based service.404on accesses to the/metricsendpoints.helidon-metricshelidon-metrics-api.MetricsSettingsinstead of the correspondingConfig(but still support assigning those settings viaConfigand the builder)RegistryFactorystatic factory methods for obtaining registry factory instances now delegate tohelidon-metrics-apifor backward compatibility and to enable migration over time of existing metrics-capable components.helidon-service-common-rest(This component contains common behavior for any SE service which adds an endpoint.)
RestServiceSettingsand itsBuilderinterfaces and implementations for them. These support as a POJO the following attributes for endpoints which a REST service provides, previously only via configuration:web-contextroutingHelidonRestServerSupport(common base forXXXSupportclasses) to use the newRestServiceSettingsclass instead of recording those values separately itself.helidon-microprofile-serverRoutingBuilders(which contain the default routing and the service endpoint routing information for a service) to accept the routing name, instead of only a config key to retrieve the routing name or aConfigobject to extract theroutingkey from. Those config-based methods remain but delegate to the new one.helidon-microprofile-metricsUse the
RegistryFactoryfrom the newhelidon-metrics-apimodule instead of the one fromhelidon-metricsin:MetricsCdiExtensionRegistryProducerThe above one-line changes plus minor changes in
pom.xmlandmodule-info.javaare all that's needed so MP metrics becomes metrics-capable.Enhanced tests
helidon-examples-metricsDocumentation
Metrics can now be controlled in new ways:
Doc changes/additions:
The metrics guides (SE and MP) now discuss these briefly.
A new, separate SE guide (currently omitted from the left-hand nav list, but the revised SE metrics guide links to it) describing how to create a metrics-capable component or app. I suppressed this from the nav list because that list is already plenty long and this new information most likely interests only a small subset of our readers. I'm not sure that's the best approach, because we want to encourage users to write metrics-capable apps instead of metrics-dependent ones.
I did a bit of refactoring of common vs. unique-to-SE content.
In the new
helidon-metrics-apimodule is an informalREADME.mdgeared to people converting existing Helidon services and components to be metrics-capable.Other modules affected
Some other components have been written to isolate their metrics dependency to a separate module (e.g.,
helidon-webclientandhelidon-webclient-metrics), leaving it to the user to include (or not) a dependency on the component's metrics component to control whether the component registers and updates its metrics. Over time, we can remove that complexity (while making sure we maintain backward compatibility for the existing usage pattern).Until then, any component or app that uses the normal techniques of obtaining a
MetricRegistry(in SE, usingRegistryFactorystatic methods; in MP, usingRegistryFactorystatic methods or CDI look-up of aMetricRegistry) essentially becomes metrics-capable without any change, meaning that themetrics.enabledsetting works and even in the absence ofhelidon-metricsat runtime the component runs correctly (just without updating metrics). This is true as long as the code does not depend on metrics' values changing at runtime; if they do, they should declare a runtime dependency onhelidon-metrics.Because these components currently depend on
helidon-metricsthe full-featured metrics implementation will be on the runtime path of any app which depends on these components unless the person packaging or deploying an app takes steps to excludehelidon-metrics.Examples
The new
helidon-metrics-service-apicomponent includes a trivial test serviceMyMetricsServiceSupportwhich follows the guidelines in the new doc content for creating or converting an SE service component.You can also see this feature at work by changing the
pom.xmlin the MP quickstart app. Add this to thehelidon-microprofilebundle dependency (that artifact depends on bothhelidon-metricsand, now,helidon-metrics-apiand `helidon-metrics-service-api):Then
In another window, access the app
curl http://localhost:8080/greetand then try to access metrics usingcurl -v http://localhost:8080/metricsand you see this output:All the MP metrics code runs (unknown to it) with the no-op implementations of
RegistryFactory,MetricRegistry, and metrics without incident.Signed-off-by: tim.quinn@oracle.com tim.quinn@oracle.com