The third MicroProfile release of 2019 is now available: MicroProfile 3.1. With the last release of MicroProfile 3.0 in June, the MicroProfile community continues with its last release for this year. Both the Eclipse MicroProfile Metrics and MicroProfile Health specification got an update to version 2.1. Even though this release is a rather small one (compared to the release last June) I want to share with you the spec updates.
As of now, there is no application server, which implements MicroProfile 3.1. For a first impression of the updates with MicroProfile 3.1, you can use a development build of Open Liberty or wait until version 19.0.0.11.
Updates for Eclipse MicroProfile Metrics
The first update for Metrics is a clarification for the implementation of the MetricRegistry, as they now emphasize thread-safety:
The implementation must make sure that metric registries are thread-safe, in other words, concurrent calls to methods of MetricRegistry must not leave the registry in an inconsistent state.
Next, Gauge metrics must now return values that extend java.lang.Number
:
1 2 3 4 5 6 7 8 9 | @FunctionalInterface public interface Gauge<T extends Number> extends Metric { /** * Returns the metric's current value. * * @return the metric's current value */ T getValue(); } |
In previous versions of Eclipse MicroProfile Metrics, the Gauge interface could return any value:
1 2 3 4 5 6 7 8 9 | @FunctionalInterface public interface Gauge<T> extends Metric { /** * Returns the metric's current value. * * @return the metric's current value */ T getValue(); } |
Furthermore, we now have a reusable(boolean)
method for the MetadataBuilder
. In Metrics 2.0 there was only .notReusable()
and .reusable()
. If reusable is set to true, then you can register metrics multiple times under the same MetricID:
1 2 3 4 5 6 7 8 9 10 11 | Metadata metadata = Metadata .builder() .reusable(true) .withName("myMetric") .withUnit("seconds") .withDescription("counting seconds") .withType(MetricType.COUNTER) .build(); Counter counterOne = metricRegistry.counter(metadata); Counter counterTwo = metricRegistry.counter(metadata); |
For metrics declared using annotations the default is false to prevent copy & paste errors. Programmatically created metrics are reusable by default. Keep in mind that Gauges are not reusable.
Further updates to the spec are the following:
- Clarified that implementations can, for JSON export of scopes containing no metrics, omit them, or be present with empty values
- TCKs are updated to use RestAssured 4.0
- Exclusion of the transitive dependency on
javax.el-api
from the build of the specification. It wasn’t actually used anywhere in the build so there should be no impact - More text was added to the specification about programmatic (no annotations) creation of metrics
You can find the specification document for Eclipse MicroProfile Metrics 2.1 here.
Updates for Eclipse MicroProfile Health
The first update targets out-of-the-box health check procedures. The specification says the following for proprietary health check provided e.g. by the application server vendor:
A producer SHOULD support reasonable out-of-the-box procedures
With MicroProfile Health 2.1 we now get a config variable to disable such out-of-the-box procedures:
1 | mp.health.disable-default-procedures=true |
Next, we get a new method to create a named HealthCheckResponse
without using the builder. The HealthCheckResponse
class now offers two static methods .up(name)
and .down(name)
to create a response more easily:
1 2 3 4 5 6 7 8 9 10 | @Liveness public class HealthUpdates implements HealthCheck { @Override public HealthCheckResponse call() { // before MP Health 2.1: HealthCheckResponse.named("my-liveness-check").up().build(); // before MP Health 2.1: HealthCheckResponse.builder().name("my-liveness-check").up().build(); return HealthCheckResponse.up("my-liveness-check"); } } |
Further updates to the spec are the following:
- The Javadoc for this specification got improvements
- Several updates to the test setup
- Removal of the duplicate Arquillian import
- Remove EL API transitive dependency like in MicroProfile Metrics 2.1
You can find the specification document for Eclipse MicroProfile Health 2.1 here.
Last but not least, you can find the code examples on GitHub.
Have fun using MicroProfile 3.1,
Phil