Introduction: Observability with Microprofile

Microservice architecture is an approach that is very compliance to cloud environment, permitting us create a cloud native application. With microservice architecture, we promote resilience, fault tolerance and scale. However, this approach has a different challenges than monolithic applications.

In a monolithic application, all code and business role is inside of one application. With this, all transactions occur inside the same application. However, the microservice architecture breaking the monolithic application in services that is packaged independently and have a independent life. With this, we have several cross cutting concerns that occur in several service. In other words, we have several processes, concerns or logic that act with distributed way. One of these concerns is about monitoring and logging. With this, we have the concept of Observability.

What is Observability?

The concept of Observability is a concept came from the control theory, that is a math theory.

Formally, a system is said to be observable if, for any possible sequence of state and control vectors (the latter being variables whose values one can choose), the current state (the values of the underlying dynamically evolving variables) can be determined in finite time using only the outputs.

Wikipedia

Some developers define Observability in a microservice architecture as the set of metrics, logging and tracing tools, but I think observibility as a more generic concept. Metrics, logging and tracing is only a way to provide observvability, but in the future we can use another way.

To me, observibility is the capacity of a system expose precise information about its states with easier and faster way. Differently from monitoring, observability is about the own system. When we say about monitoring, the focal point is the tools that will be used to monitoring the system, but the system can be easy or hard to monitoring. When we say about observability, the focal point is the own system, that need provide these information with easier and faster way. Monitoring a system with observalibity is always easy, because the system expose its information facilitating the monitoring.

Observability with Microprofile

With aim to promote a easy support to observability, the Microprofile has some specs to permit the developer implement observability in our microservices. The Microprofile has 3 main specs to do that, those specs are:  Microprofile OpeanTracing, Microprofile Metrics and Microprofile HealthCheck.

Screenshot from 2019-02-27 16-44-31

Microprofile OpenTracing

Microprofile OpenTracing is a spec that permit us use distributed tracing using the OpenTracing API to trace  the flow of a request across service. This spec is compatible  to Zipkin and compatible to Jaeger , and permit us use Zipkin or Jaeger to show the information about the distributed tracing. Below we have an example of how to use Microprofile OpenTracing.

@Path("subjects")
@Traced
public class SubjectEndpoint {



}

 

Microprofile Metrics

Microprofile Metrics is a spec that permit us expose metrics information about our applications. With this, we can expose precise metrics to be consumed with easier and faster way. Below we have an example of how to use Microprofile Metrics.

@Counted
public CounterBean() {
}

Microprofile HealthCheck

Health Check is a spec that permit us expose if the application is up or down in our environment. It works as a boolean response (yes or no) to the question “Is my application still running ok?“. Below we have an example of how to use Microprofile HealthCheck.

@Health
@ApplicationScoped
public class ApplicationHealthCheck implements HealthCheck {

    @Override
    public HealthCheckResponse call() {
        return HealthCheckResponse
                .named("application-check").up()
                .withData("CPUAvailable", Runtime.getRuntime().availableProcessors())
                .withData( "MemoryFree", Runtime.getRuntime().freeMemory())
                .withData("TotalMemory", Runtime.getRuntime().totalMemory())
                .build();
    }
}

Conclusion

The Microprofile has been promote several solutions to microservice challenges, and one of those solutions are the specs to promote observability in our microservices. With this, we can use microprofile with Jaeger, Zipkin, Prometeus and others to promote better observability and monitoring. This article was only a introduction and I will post more details of these specs in the next posts.

If you want to know more about Microprofile access microprofile.io .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s