What’s new with MicroProfile 6.1?

Photo of Alfonso Altamirano by Alfonso Altamirano

The latest release of MicroProfile - 6.1 - was delivered in October and it comes with some changes and new fuctionalities - we will take you through those in this article, so carry on reading if you want to find out more on what's new in MicroProfile!

The new release of MicroProfile 6.1 brings a few little changes and is considered a minor release. To see exactly what changed, have a look at the diagram below:

MicroProfile6.1

For more information, please check official site for MicroProfile 6.1

Specs that changed

As you saw from the previous diagram only few specs changed. In the next sections I will show what changes were added on each of them.

MicroProfile Config 3.1

For this specification most of the changes added were regarding the following:

  • TCK Improvements
  • Upgrade of documentation to clarify usage

To review full list of changes please check official site for MicroProfile Config 3.1

MicroProfile Telemetry 1.1

Here one of the most important changes were the upgrade of the OpenTelemetry Java V1.29.0 that is used now internally and the usage of the OpenTelemetry Tracing v1.26.0. Additional to the previous, Telemetry 1.1 have the following:

  • TCK improvements
  • Upgrade documentation to clarify usage

To review full list of changes please check official site for MicroProfile Telemetry 1.1

MicroProfile Metrics 5.1

In this specification more interesting changes beyond the TCK Improvements and the documentation changes were added.

Now with metrics we can customize percentiles and buckets, these values are used commonly with Histogram and Timer metrics.

To show how this works, see the following example:

First, we need a Rest endpoint for each of the metrics that we need. Here the class:

@Path("/metric")
@ApplicationScoped
public class MetricController {

private Logger logger = Logger.getLogger(MetricController.class.getName());

@Inject
HistogramConfigBean bean;

@Inject
TimerConfigBean timerBean;

@Path("histogram")
@GET
public String callHistogram() {
bean.injectedHistogram.update((int)(Math.random() * 10000.0));
return "Histogram called";
}

@Path("timer")
@GET
public String callTimer() {
LocalDateTime starting = LocalDateTime.now();
int wait = new Random().nextInt(5000);
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
e.printStackTrace();
}
LocalDateTime end = LocalDateTime.now();
Duration d = Duration.between(starting, end);
timerBean.injectedTimer.update(d);
logger.info("Duration for timer:"+d.toString());
return "calling timer";
}

}

This class need the following two classes: HistogramConfigBean and TimerConfigBean, since those define each specific metric and those are injected into the MetricController class.

Here the code of both:

@Dependent
public class HistogramConfigBean {
@Inject
@Metric(name = "injectedHistogram")
public Histogram injectedHistogram;
}
@Dependent
public class TimerConfigBean {
@Inject
@Metric(name="injectedTimer")
public Timer injectedTimer;
}

Then, we need to indicate that we want to use our custom percentiles and custom buckets by adding the following properties on our microprofile-config.properties file:

  • new properties
    • mp.metrics.distribution.histogram.buckets
    • mp.metrics.distribution.percentiles
    • mp.metrics.distribution.timer.buckets

The rules to apply each of them are explained in the documentation here

With each of them we are telling to get and use values to configure custom percentiles and custom buckets for each of the metrics. For our example here the values of the properties:

mp.metrics.distribution.percentiles=com.microprofile.example.demo.metric.HistogramConfigBean.injectedHistogram=0.2,0.4,0.6;com.microprofile.example.demo.metric.TimerConfigBean.injectedTimer=0.1,0.2,0.5,0.7,0.95
mp.metrics.distribution.histogram.buckets=com.microprofile.example.demo.metric.HistogramConfigBean.injectedHistogram=1000.0,6000.0,4000.0,2500.0,9000.0
mp.metrics.distribution.timer.buckets=com.microprofile.example.demo.metric.TimerConfigBean.injectedTimer=10s,5s,1s,4s,3s,2s

I'm configuring for the metric HistogramConfigBean.injectedHistogram 3 custom percentiles and for TimerConfigBean.injectedTimer  5 custom percentiles. In the case of buckets I'm adding for HistogramConfigBean.injectedHistogram 5 custom buckets and for TimerConfigBean.injectedTimer  6 custom buckets.

Difference between percentile and buckets

An important thing to explain is the difference between percentile and a bucket. A percentile is a value that represents a percentage from the amount of data to evaluate, while the bucket is a specific value that contains the total amount of occurrences from the values that is less or equal to the bucket value. 

To test our example we just need to start our application with Payara Micro and we need to call multiple times each of the endpoints.

Payara Micro startup with demo application:

Calling timer endpoint:

Calling histogram endpoint:

Finally we can open the applications metrics to see the Prometheus format of the metrics

If you want to check more details of the Prometheus format please check following page

Monitor the metrics with different tools

As you saw from the resulting output, that is not very readable. That is why you can configure other tools like Prometheus UI tool and Graphana to have a more readable way to explore metrics. Here are the links to review how to install those tools:

After doing configuration and installation then you can see the previous data on a very interesting view:

Prometheus quantile review

Prometheus bucket review

Graphana quantile review

Prometheus bucket review

To review full list of changes please check official site for MicroProfile Metrics 5.1

Conclusion

You can see that although little changes were added to the new release of MicroProfile 6.1, it is important to understand and use the new capabilities. For the best results, make sure you use MicroProfile 6.1 with the latest version of Payara Platform - download here!

 

Want to learn more about using MicroProfile? Check out our guides and other educational resources!

MicroProfile Resources

 

Related Posts

Comments