title | description | author | ms.author | ms.service | ms.topic | ms.date | ms.custom | zone_pivot_groups |
---|---|---|---|---|---|---|---|---|
Collect Spring Cloud Resilience4J Circuit Breaker Metrics with Micrometer |
How to collect Spring Cloud Resilience4J Circuit Breaker Metrics with Micrometer in Azure Spring Apps. |
KarlErickson |
karler |
spring-apps |
how-to |
02/21/2024 |
devx-track-java, devx-track-extended-java, devx-track-azurecli |
spring-apps-tier-selection |
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.
- Install Git, Maven, and Java, if not already installed on the development computer.
Use the following steps to build and deploy the sample applications.
-
Use the following command to 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
::: zone pivot="sc-standard"
-
Use the following command to create an Azure Spring Apps service instance:
az spring create \ --resource-group ${resource-group-name} \ --name ${Azure-Spring-Apps-instance-name}
-
Use the following commands to create the 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
-
Use the following commands to deploy the applications:
az spring app deploy \ --resource-group ${resource-group-name} \ --service ${Azure-Spring-Apps-instance-name} \ --name resilience4j \ --env resilience4j.circuitbreaker.instances.backendA.registerHealthIndicator=true \ --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 \ --env resilience4j.circuitbreaker.instances.backendA.registerHealthIndicator=true \ --artifact-path ./spring-cloud-circuitbreaker-demo-reactive-resilience4j/target/spring-cloud-circuitbreaker-demo-reactive-resilience4j-0.0.1-SNAPSHOT.jar
::: zone-end
::: zone pivot="sc-enterprise"
-
Use the following command to create an Azure Spring Apps service instance:
[!NOTE] If your subscription has never been used to create an Enterprise plan instance of Azure Spring Apps, you must run the following command:
az term accept \ --publisher vmware-inc --product azure-spring-cloud-vmware-tanzu-2 --plan asa-ent-hr-mtr
az spring create \ --resource-group ${resource-group-name} \ --name ${Azure-Spring-Apps-instance-name} \ --sku Enterprise
-
Use the following commands to 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
-
Use the following commands to deploy the applications:
az spring app deploy \ --resource-group ${resource-group-name} \ --service ${Azure-Spring-Apps-instance-name} \ --name resilience4j \ --env resilience4j.circuitbreaker.instances.backendA.registerHealthIndicator=true \ --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 \ --env resilience4j.circuitbreaker.instances.backendA.registerHealthIndicator=true \ --artifact-path ./spring-cloud-circuitbreaker-demo-reactive-resilience4j/target/spring-cloud-circuitbreaker-demo-reactive-resilience4j-0.0.1-SNAPSHOT.jar
::: zone-end
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 abean
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}
::: zone pivot="sc-standard"
-
In your Azure Spring Apps instance, select Application Insights in the navigation pane and then select Application Insights on the page.
:::image type="content" source="media/how-to-circuit-breaker-metrics/application-insights.png" alt-text="Screenshot of the Azure portal that shows the Azure Spring Apps Application Insights page with Application Insights highlighted." lightbox="media/how-to-circuit-breaker-metrics/application-insights.png":::
[!NOTE] If you don't enable Application Insights, you can enable the Java In-Process agent. For more information, see the Manage Application Insights using the Azure portal section of Use Application Insights Java In-Process Agent in Azure Spring Apps.
-
Enable dimension collection for resilience4j metrics. For more information, see the Custom metrics dimensions and pre-aggregation section of Log-based and pre-aggregated metrics in Application Insights.
-
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.
:::image type="content" source="media/how-to-circuit-breaker-metrics/chart-menus.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page with Metric Namespace menu open and azure-applicationinsights option highlighted." lightbox="media/how-to-circuit-breaker-metrics/chart-menus.png":::
-
Set Metric to resilience4j_circuitbreaker_buffered_calls, and then set Aggregation to Avg.
:::image type="content" source="media/how-to-circuit-breaker-metrics/buffered-calls.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker buffered calls and average aggregation." lightbox="media/how-to-circuit-breaker-metrics/buffered-calls.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls and average aggregation." lightbox="media/how-to-circuit-breaker-metrics/calls.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Add filter and set Name to Delay.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls-filter.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls, average aggregation and Delay Filter." lightbox="media/how-to-circuit-breaker-metrics/calls-filter.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Apply splitting and set Split by to kind.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls-splitting.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls, average aggregation, and splitting." lightbox="media/how-to-circuit-breaker-metrics/calls-splitting.png":::
-
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.
:::image type="content" source="media/how-to-circuit-breaker-metrics/slow-calls.png" alt-text="Screenshot of the Azure portal that shows the Application Insights Metrics page with the chart described in this step." lightbox="media/how-to-circuit-breaker-metrics/slow-calls.png":::
::: zone-end
::: zone pivot="sc-enterprise"
-
In your Azure Spring Apps instance, select Application Insights in the navigation pane and then select the default Application Insights on the page.
:::image type="content" source="media/how-to-circuit-breaker-metrics/application-insights-enterprise.png" alt-text="Screenshot of the Azure portal that shows the Azure Spring Apps Application Insights page with the default Application Insights instance highlighted." lightbox="media/how-to-circuit-breaker-metrics/application-insights-enterprise.png":::
[!NOTE] If there's no default Application Insights available, you can enable the Java In-Process agent. For more information, see the Manage Application Insights using the Azure portal section of Use Application Insights Java In-Process Agent in Azure Spring Apps.
-
Enable dimension collection for resilience4j metrics. For more information, see the Custom metrics dimensions and pre-aggregation section of Log-based and pre-aggregated metrics in Application Insights.
-
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.
:::image type="content" source="media/how-to-circuit-breaker-metrics/chart-menus.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page with the Metric Namespace menu open and azure.applicationinsights highlighted." lightbox="media/how-to-circuit-breaker-metrics/chart-menus.png":::
-
Set Metric to resilience4j_circuitbreaker_buffered_calls, and then set Aggregation to Avg.
:::image type="content" source="media/how-to-circuit-breaker-metrics/buffered-calls.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker buffered calls and average aggregation." lightbox="media/how-to-circuit-breaker-metrics/buffered-calls.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls and average aggregation." lightbox="media/how-to-circuit-breaker-metrics/calls.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Add filter and set Name to Delay.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls-filter.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls, average aggregation and delay filter." lightbox="media/how-to-circuit-breaker-metrics/calls-filter.png":::
-
Set Metric to resilience4j_circuitbreaker_calls, and then set Aggregation to Avg. Select Apply splitting and set Split by to kind.
:::image type="content" source="media/how-to-circuit-breaker-metrics/calls-splitting.png" alt-text="Screenshot of the Azure portal Application Insights Metrics page that shows a chart with circuit breaker calls, average aggregation, and splitting." lightbox="media/how-to-circuit-breaker-metrics/calls-splitting.png":::
-
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.
:::image type="content" source="media/how-to-circuit-breaker-metrics/slow-calls.png" alt-text="Screenshot of the Azure portal that shows the Application Insights Metrics page with the chart described in this step." lightbox="media/how-to-circuit-breaker-metrics/slow-calls.png":::
::: zone-end