Collect Spring Cloud Resilience4J Circuit Breaker Metrics with Micrometer (Preview)

Note

Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.

This article applies to: ✔️ Basic/Standard ✔️ Enterprise

This article shows you how to collect Spring Cloud Resilience4j Circuit Breaker Metrics with Application Insights Java in-process agent. With this feature, you can monitor the metrics of Resilience4j circuit breaker from Application Insights with Micrometer.

The demo spring-cloud-circuit-breaker-demo shows how the monitoring works.

Prerequisites

Build and deploy apps

Use the following steps to build and deploy the sample applications.

  1. Clone and build the demo repository.

    git clone https://github.com/spring-cloud-samples/spring-cloud-circuitbreaker-demo.git
    cd spring-cloud-circuitbreaker-demo && mvn clean package -DskipTests
    
  2. Create applications with endpoints.

    az spring app create \
        --resource-group ${resource-group-name} \
        --service ${Azure-Spring-Apps-instance-name} \
        --name resilience4j \
        --assign-endpoint
    az spring app create \
        --resource-group ${resource-group-name} \
        --service ${Azure-Spring-Apps-instance-name} \
        --name reactive-resilience4j \
        --assign-endpoint
    
  3. Deploy applications.

    az spring app deploy \
        --resource-group ${resource-group-name} \
        --service ${Azure-Spring-Apps-instance-name} \
        --name resilience4j \
        --artifact-path ./spring-cloud-circuitbreaker-demo-resilience4j/target/spring-cloud-circuitbreaker-demo-resilience4j-0.0.1-SNAPSHOT.jar
    az spring app deploy \
        --resource-group ${resource-group-name} \
        --service ${Azure-Spring-Apps-instance-name} \
        --name reactive-resilience4j \
        --artifact-path ./spring-cloud-circuitbreaker-demo-reactive-resilience4j/target/spring-cloud-circuitbreaker-demo-reactive-resilience4j-0.0.1-SNAPSHOT.jar
    

Note

  • Include the required dependency for Resilience4j:

    <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-micrometer</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
    </dependency>
    
  • Your code must use the CircuitBreakerFactory API, which is implemented as a bean automatically created when you include a Spring Cloud Circuit Breaker starter. For more information, see Spring Cloud Circuit Breaker.

  • The following two dependencies have conflicts with Resilient4j packages. Be sure you don't include them.

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zipkin</artifactId>
    </dependency>
    

Navigate to the URL provided by gateway applications, and access the endpoint from spring-cloud-circuit-breaker-demo as follows:

/get
/delay/{seconds}
/fluxdelay/{seconds}

Locate Resilence4j Metrics on the Azure portal

  1. In your Azure Spring Apps instance, select Application Insights in the navigation pane and then select Application Insights on the page.

    Screenshot of the Azure portal showing the Azure Spring Apps Application Insights page with the Application Insights on the button bar highlighted.

  2. Select Metrics in the navigation pane. The Metrics page provides dropdown menus and options to define the charts in this procedure. For all charts, set Metric Namespace to azure.applicationinsights.

    Screenshot of the Azure portal Application Insights Metrics page, with Metrics highlighted in the navigation pane, and with azure-applicationinsights highlighted in the Metric Namespace dropdown menu.

  3. Set Metric to resilience4j_circuitbreaker_buffered_calls, and then set Aggregation to Avg.

    Screenshot of the Azure portal Application Insights Metrics page showing a chart with Metric set to circuit breaker buffered calls and Aggregation set to Average.

  4. Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg.

    Screenshot of the Azure portal Application Insights Metrics page showing a chart with Metric set to circuit breaker calls and Aggregation set to Average.

  5. Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Add filter and set Name to Delay.

    Screenshot of the Azure portal Application Insights Metrics page showing a chart with Metric set to circuit breaker calls and Aggregation set to Average, and with Filter set to the name Delay.

  6. Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Apply splitting and set Split by to kind.

    Screenshot of the Azure portal Application Insights Metrics page showing a chart with Metric set to circuit breaker calls and Aggregation set to Average, and with Apply splitting selected with Split by set to kind.

  7. Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Add metric and set Metric to resilience4j_circuitbreaker_buffered_calls, and then set Aggregation to Avg. Select Add metric again and set Metric to resilience4j_circuitbreaker_slow_calls, and then set Aggregation set to Avg.

    Screenshot of the Azure portal Application Insights Metrics page showing three charts: A chart with Metric set to circuit breaker calls and Aggregation set to Average. A chart with Metric set to circuit breaker calls buffered and Aggregation set to Average. A chart with Metric set to circuit breaker slow calls  and Aggregation set to Average.

Next steps