-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow metrics-capable components to work in absence of full-featured metrics #3441
Merged
Conversation
This file contains 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
tjquinno
changed the title
Allow metrics-capable components to work in absence of full-featured metrics
WIP - Allow metrics-capable components to work in absence of full-featured metrics
Sep 28, 2021
tjquinno
changed the title
WIP - Allow metrics-capable components to work in absence of full-featured metrics
Allow metrics-capable components to work in absence of full-featured metrics
Sep 28, 2021
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
metrics/api/src/main/java/io/helidon/metrics/api/AbstractMetric.java
Outdated
Show resolved
Hide resolved
ljnelson
reviewed
Sep 28, 2021
tjquinno
changed the title
Allow metrics-capable components to work in absence of full-featured metrics
WIP - Allow metrics-capable components to work in absence of full-featured metrics
Sep 29, 2021
tjquinno
changed the title
WIP - Allow metrics-capable components to work in absence of full-featured metrics
Allow metrics-capable components to work in absence of full-featured metrics
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
metrics/api/src/main/java/io/helidon/metrics/api/AbstractRegistry.java
Outdated
Show resolved
Hide resolved
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
metrics/api/src/main/java/io/helidon/metrics/api/AbstractRegistry.java
Outdated
Show resolved
Hide resolved
ljnelson
reviewed
Sep 29, 2021
ljnelson
reviewed
Sep 29, 2021
ljnelson
previously approved these changes
Sep 29, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments.
tjquinno
changed the title
Allow metrics-capable components to work in absence of full-featured metrics
WIP - Allow metrics-capable components to work in absence of full-featured metrics
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
examples/metrics/kpi/src/test/java/io/helidon/examples/metrics/kpi/MainTest.java
Outdated
Show resolved
Hide resolved
metrics/api/src/main/java/io/helidon/metrics/api/KeyPerformanceIndicatorMetricsSettings.java
Outdated
Show resolved
Hide resolved
metrics/api/src/main/java/io/helidon/metrics/api/MetricsSupport.java
Outdated
Show resolved
Hide resolved
metrics/api/src/main/java/io/helidon/metrics/api/MetricsSupportProvider.java
Outdated
Show resolved
Hide resolved
metrics/metrics/src/main/java/io/helidon/metrics/RegistryFactory.java
Outdated
Show resolved
Hide resolved
…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
tomas-langer
approved these changes
Oct 19, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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-api
abstracts the behavior of registry factories, metrics registries, and metrics implementations. It includes "no-op" implementations of metrics which Helidon uses:helidon-metrics
is not on the runtime path, orMetricsSettings.Builder
or confighelidon-metrics-service-api
abstracts the behavior of theMetricsSupport
webserver-based metrics service and contains a minimal implementation which response with404
to the metrics endpoints.The existing
helidon-metrics
component remains and contains the full-featured implementations of metrics andMetricsSupport
. For backward compatibility, the its formerRegistryFactory
class is now an API-compatible interface which delegates to theRegistryFactory
inhelidon-metrics-api
.See the
README.md
in thehelidon-metrics-api
for 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
Config
to locate settings (such as theweb-context
orrouting
. Examples:helidon-service-common-rest
,HelidonRestServiceSupport
, andhelidon-microprofile-server
RoutingBuilders
. 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-api
MetricsSettings
POJO which captures all the existing configurable behavior of metrics (enabled, base metric behavior, and KPI metrics settings) with implementations and factory methods.ComponentMetricsSettings
which collects metrics behavior particular to a component, with implementations and factory methods. Currently just whether metrics should be enabled for the componentRegistryFactory
interface and related service loading interfaceRegistryFactoryProvider
interface and loader class.BaseMetric
interface defining common behavior of full-featured and no-op metrics.AbstractRegistry
implements most ofMetricRegistry
with abstract methods for creating metrics instances; mostly a type-generalized copy of the previoushelidon-metrics
Registry
class.MetricRegistry
andRegistryFactory
which dispense the no-op metrics.README.md
describing the revised approach and how to write or revise components to be _metrics-capableinstead of
metrics-dependent`.New component
helidon-metrics-service-api
MetricsSupport
interface abstracting the behavior of the metrics web-based service.404
on accesses to the/metrics
endpoints.helidon-metrics
helidon-metrics-api
.MetricsSettings
instead of the correspondingConfig
(but still support assigning those settings viaConfig
and the builder)RegistryFactory
static factory methods for obtaining registry factory instances now delegate tohelidon-metrics-api
for 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.)
RestServiceSettings
and itsBuilder
interfaces and implementations for them. These support as a POJO the following attributes for endpoints which a REST service provides, previously only via configuration:web-context
routing
HelidonRestServerSupport
(common base forXXXSupport
classes) to use the newRestServiceSettings
class instead of recording those values separately itself.helidon-microprofile-server
RoutingBuilders
(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 aConfig
object to extract therouting
key from. Those config-based methods remain but delegate to the new one.helidon-microprofile-metrics
Use the
RegistryFactory
from the newhelidon-metrics-api
module instead of the one fromhelidon-metrics
in:MetricsCdiExtension
RegistryProducer
The above one-line changes plus minor changes in
pom.xml
andmodule-info.java
are all that's needed so MP metrics becomes metrics-capable.Enhanced tests
helidon-examples-metrics
Documentation
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-api
module is an informalREADME.md
geared 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-webclient
andhelidon-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, usingRegistryFactory
static methods; in MP, usingRegistryFactory
static methods or CDI look-up of aMetricRegistry
) essentially becomes metrics-capable without any change, meaning that themetrics.enabled
setting works and even in the absence ofhelidon-metrics
at 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-metrics
the 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-api
component includes a trivial test serviceMyMetricsServiceSupport
which 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.xml
in the MP quickstart app. Add this to thehelidon-microprofile
bundle dependency (that artifact depends on bothhelidon-metrics
and, now,helidon-metrics-api
and `helidon-metrics-service-api):Then
In another window, access the app
curl http://localhost:8080/greet
and then try to access metrics usingcurl -v http://localhost:8080/metrics
and 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