-
Notifications
You must be signed in to change notification settings - Fork 306
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
APPSERV-59 Updates to MicroProfile Metrics 2.3 #4582
Conversation
…cType when INVALID
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
…copyright headers Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
Signed-off-by: Jan Bernitt <[email protected]>
…ting for 'all metrics by scope'
…les and CDI setup (mostly)
…otation Nonbinding
…sistency Signed-off-by: Jan Bernitt <[email protected]>
jenkins test please |
jenkins test please |
jenkins test please |
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.
Some discussion points
...icroprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/AnnotationReader.java
Outdated
Show resolved
Hide resolved
...oprofile/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/MetricGetOrRegister.java
Outdated
Show resolved
Hide resolved
@@ -96,10 +101,13 @@ private Object timeoutInvocation(InvocationContext context) throws Exception { | |||
private <E extends Member & AnnotatedElement> Object preInterceptor(InvocationContext context, E element) throws Exception { | |||
initService(); | |||
if (metricsService.isEnabled()) { | |||
//FIXME there is an issue here: the element does not correctly reflect the updated annotations |
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.
How much effort is it to do this?
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.
I opted to not open that box because of the change of behaviour it might bring. I don't think it is much work but it is this ugly inconsistency in CDI where you cannot ask for the Bean
that is intercepted. Weld has a non standard way around it which allows to access the CDI level abstraction which has the correct picture. To be clear: this is just the difference between dynamic adds/removes of annotations on CDI level considered or not.
...file/metrics/src/main/java/fish/payara/microprofile/metrics/cdi/producer/MetricProducer.java
Show resolved
Hide resolved
...r-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/EWMA.java
Show resolved
Hide resolved
...oprofile/metrics/src/main/java/fish/payara/microprofile/metrics/impl/MetricRegistryImpl.java
Show resolved
Hide resolved
jenkins test please |
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.
Points discussed.
APPSERV-59 Updates to MicroProfile Metrics 2.3 Conflicts: appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/rest/MetricsResource.java pom.xml
Summary
Updates Payara to conform to the MicroProfile Metrics 2.3 standard.
New Features and Additions:
SimpleTimer
metric type and@SinplyTimed
annotationMetadata
now has usesOptional
s to distinguish between not set values for unit, description or display name from intentionally set values including the empty string. This requires to change howMetadata
is build from annotations.MetricRegistry
now uses aClock
so theMetric
s it creates that use aClock
use the one passed to the registry so it becomes unit testableConcurrentGaugeImpl
now uses aClock
for deciding when to roll over the min/max state so this becomes unit testable without waiting a minute.TimerImpl
can now be created with a customClock
for unit testingLongAdded
withAtomicLong
in some places. While it is true that the adder has better throughput due to smaller risk of thread contention it is only used on paths that will also use at least one but often several other atomic primitives so if there ever were a thread contention it would simply occur on one of those CAS instead. With that in mindAtomicLong
seems the better choice as it is more lightweight in both memory and CPU usage. Also should there be a hot loop with many threads involved using a metric (e.g. a counter) the bottleneck of thread contention on an atomic CAS operation will be the least of our problems. There are many other (in comparison) heavy weight operations in the path that should pop up as problem before the CAS.MinMax
updating ofConcurrentGaugeImpl
was fixed.MetricsWriter
now usesMetricRegistry.Type
for the scope (which was misunderstood asregistryName
before (Scope only allowsbase
,vendor
,application
whereas the registry name is base, vendor or that of a particular application).null
. This behaviour is not yet standard but suggested to be (see Fixes GaugeInjectionBeanTest setup eclipse/microprofile-metrics#563 (comment))NoSuchRegistryException
made aRuntimeException
(otherwise cause ugly try-catch cascades for no reason)Related Issues
Testing
Tests Added
The Metrics module was sparsely tested. Since the existing code was hard to follow, at times seemed duplicated and inconsistent I decided to change code so that it became unit-testable and easier to follow so I could write test to make sure we are complaint with the specification.
All extracting data from annotations and annotated member is replaced by the
AnnotationReader
class which is tested with a coverage > 88%. This replaces different utilities that would each have their own inconsistent logic (which isn't correct).The export to JSON is done by
JsonExporter
(coverage > 97%), the export to OpenMetrics is done byOpenMetricsExporter
(coverage > 98%). These operate on the level of individual metrics which in a case for multiple metrics for the same name must be exported following one another. Extracting the data for export from one or more registries and feeding individual metrics in right grouping into the exporter is done by theMetricsWriterImpl
(tests need to be created).Unit and component tests were added to cover the important and complex parts.
This includes:
Metadata
from annotationsThe formatting is both tested with examples found in the spec. These (and some more) are added as text files (OpenMetrics format) and JSON files (JSON format). Some of these examples contained inconsistencies with the specification which were corrected in eclipse/microprofile-metrics#555
The added tests only take a few seconds to run so they are no problem for the build process.
Tests Performed
Besides the over 150 new unit tests manual testing was done using the endpoints
To test both JSON and OpenMetrics some browser addon can be used to set the
Accept
header toapplication/json
and test bothGET
andOPTIONS
for the above URLs.Running the TCK with updates in payara/MicroProfile-TCK-Runners#103 against local server instance using:
Remember that
MP_METRICS_TAGS
needs to be set totier=integration
when running against remote server usingexport MP_METRICS_TAGS=tier=integration
in the shell that is used to start the server.