OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.14k stars 587 forks source link

BETA BLOG - Fault Tolerance 4.1 #29122

Open benjamin-confino opened 1 month ago

benjamin-confino commented 1 month ago
<GHA-BLOG-SUMMARY>

MicroProfile Fault Tolerance allows users to easily apply strategies for mitigating failures in their code. It provides annotations which you can add to methods to use bulkhead, circuit breaker, retry, timeout and fallback strategies.

The new mpFaultTolerance-4.1 feature provides integration with mpTelemetry-2.0 allowing Fault Tolerance to export metric data to Open Telemetry. With this change, and other changes in mpTelemetry-2.0 you can now use Open Telemetry as one single source for logging, metrics, and tracing, making it easier to manage and configure your application's observability.

To enable this functionality simply enable mpFaultTolerance-4.1 and mpTelemetry-2.0 in your server.xml then configure mpTelemetry-2.0 to export metrics. Here is a minimal configuration that will configure Open Telemetry to export to your messages.log file and a class which will generate Fault Tolerance metrics (it must be accessed as a CDI bean).

server.xml

<featureManager>
  <feature>mpFaultTolerance-4.1</feature>
  <feature>mpTelemetry-2.0</feature>
</featureManager>

bootstrap.properties This will configure Open Telemetry to only output metrics, you will find them in messages.log

otel.sdk.disabled=false
otel.metrics.exporter=logging
otel.logs.exporter=none
otel.traces.exporter=none
TODO; set the timeout to a low number so people will see the metrics quickly. Then mention why you did so in the paragraph apart

Example class Ensure this class is injected as a CDI bean and invoked by the user in whatever way you prefer.

import org.eclipse.microprofile.faulttolerance.Retry;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class Example Class {

    @Retry
    public int exampleMethod(String name) {
        return 1;
    }
}

Further resources:

benjamin-confino commented 1 month ago

This is part of https://github.com/OpenLiberty/open-liberty/issues/27107