Skip to content

Commit 27adc51

Browse files
Merge pull request #313680 from v-thpra/tjp-fresh-azcontapps-006
Q&M Freshness - Azure Container Apps - TJP006
2 parents e6623bb + d18230d commit 27adc51

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

articles/container-apps/java-metrics-scale-with-keda.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.custom: devx-track-extended-java
88
ms.topic: tutorial
9-
ms.date: 12/23/2024
9+
ms.date: 03/25/2026
1010
ms.author: cshoe
1111
#customer intent: As a developer, I want to set up auto scale using Java metrics exposed from Azure Container Apps
1212
---
@@ -19,9 +19,9 @@ In this tutorial, you add a custom scale rule to scale your container app with J
1919

2020
## Prerequisites
2121

22-
* An Azure account with an active subscription. If you don't already have one, you can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
23-
* [Azure CLI](/cli/azure/install-azure-cli).
24-
* [A Java application deployed in Azure Container Apps](java-get-started.md).
22+
- An Azure account with an active subscription. If you don't already have one, you can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
23+
- [Azure CLI](/cli/azure/install-azure-cli).
24+
- [A Java application deployed in Azure Container Apps](java-get-started.md).
2525

2626
## Set up the environment
2727

@@ -42,7 +42,7 @@ Use the following steps to define environment variables and set up the environme
4242
|-------------------------|------------------------------------------------------------------------------------|
4343
| `LOCATION` | The Azure region location where you create your Azure Container Apps. |
4444
| `TENANT_ID` | Your tenant's ID. |
45-
| `SUBSCRIPTION_ID` | The subscription ID which you use to create your Azure Container Apps. |
45+
| `SUBSCRIPTION_ID` | The subscription ID, which you use to create your Azure Container Apps. |
4646
| `RESOURCE_GROUP` | The Azure resource group name for your Azure Container Apps. |
4747
| `APP_NAME` | The app name for your Azure Container Apps. |
4848
| `IDENTITY_NAME` | The name for your managed identity, which is assigned to your Azure Container Apps.|
@@ -54,25 +54,27 @@ Use the following steps to define environment variables and set up the environme
5454
```
5555
5656
## Set up a managed identity for your Azure Container Apps
57+
5758
To scale with Azure Container Apps platform metrics, you need a managed identity to access metrics from Azure Monitor.
5859
5960
1. Create a user-assigned identity and assign it to your Azure Container Apps. You can follow the doc [add a user-assigned identity](./managed-identity.md#add-a-user-assigned-identity). After you create the identity, run the CLI command to set the identity ID.
6061
61-
```azurecli
62-
USER_ASSIGNED_IDENTITY_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "id" --output tsv)
63-
```
62+
```azurecli
63+
USER_ASSIGNED_IDENTITY_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "id" --output tsv)
64+
```
6465
6566
2. Grant the `Monitoring Reader` role for your managed identity to read data from Azure Monitor. You can find more details about the roles for Azure Monitor in [Azure built-in roles for Monitor](../role-based-access-control/built-in-roles/monitor.md#monitoring-reader).
6667
67-
```azurecli
68-
# Get the principal ID for your managed identity
69-
PRINCIPAL_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "principalId" --output tsv)
68+
```azurecli
69+
# Get the principal ID for your managed identity
70+
PRINCIPAL_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "principalId" --output tsv)
7071
71-
az role assignment create --assignee $PRINCIPAL_ID --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
72-
```
72+
az role assignment create --assignee $PRINCIPAL_ID --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
73+
```
7374
7475
## Add a scale rule with Azure Monitor metrics
75-
To scale with Azure Monitor metrics, you can refer to [Azure Monitor KEDA scaler](https://keda.sh/docs/2.16/scalers/azure-monitor/) to define your Container Apps scale rule.
76+
77+
To scale with Azure Monitor metrics, you can refer to the [Azure Monitor Kubernetes Event-driven Autoscaling (KEDA) scaler](https://keda.sh/docs/2.16/scalers/azure-monitor/) to define your Container Apps scale rule.
7678
7779
Here's a list of core metadata to set up the scale rule.
7880

@@ -85,11 +87,9 @@ Here's a list of core metadata to set up the scale rule.
8587
| metricName | Name of the metric to query. |
8688
| metricAggregationType | Aggregation method of the Azure Monitor metric. Options include Average, Total, Maximum. |
8789
| metricFilter | Name of the filter to be more specific by using dimensions listed in the official documentation. (Optional) |
88-
| metricAggregationInterval | Collection time of the metric in format "hh:mm:ss" (Default: "0:5:0", Optional) |
90+
| metricAggregationInterval | Collection time of the metric in the format `hh:mm:ss` (Default: `0:5:0`, Optional) |
8991
| targetValue | Target value to trigger scaling actions. (This value can be a float) |
9092

91-
92-
9393
Add a scale rule with [Azure Monitor metrics for Azure Container Apps](./metrics.md) for your application.
9494

9595
### [Azure CLI](#tab/azurecli)
@@ -161,19 +161,19 @@ This command adds a scale rule to your container app with the name `scale-with-a
161161
> The metric `JvmGcCount` is only used as an example. You can use any metric from Azure Monitor. Before setting up the scale rule, view the metrics in the Azure portal to determine the appropriate metric, aggregation interval, and target value based on your application's requirements. Additionally, consider using the built-in [HTTP/TCP scale rules](./scale-app.md#http), which can meet most common scaling scenarios, before opting for a custom metric.
162162
163163
## View scaling in Azure portal (optional)
164+
164165
Once your new revision is ready, [send requests](./tutorial-scaling.md#send-requests) to your container app to trigger auto scale with your Java metrics.
165166
1. Go to the `Metrics` blade in the Azure portal for your Azure Container Apps.
166167
1. Add a chart, use the metric `jvm.gc.count`, with filter `Revision=<your-revision>`, aggregation using `Sum`, and split by `Replica`. You can see the `JvmGcCount` metric value for each replica in this chat.
167168
1. Add a chart, use the metric `jvm.gc.count`, with filter `Revision=<your-revision>` and aggregation using `Sum`. You can see the total aggregated `JvmGcCount` metric value for the revision in this chat.
168169
1. Add a chart, use the metric `Replica Count`, with filter `Revision=<your-revision>` and aggregation using `Max`. You can see the replica count for the revision in this chat.
169170
170-
171171
Here's a sample metric snapshot for the example scale rule.
172172

173173
:::image type="content" source="media/java-metrics-keda/keda-auto-scale-java-gc-portal.png" alt-text="Screenshot of KEDA scale with JVM metrics." lightbox="media/java-metrics-keda/keda-auto-scale-java-gc-portal.png":::
174174

175175
1. Initially, there's one replica (the `minReplicas`) for the app.
176-
1. A spike in requests causes the Java app to experience frequent JVM garbage collection (GC).
176+
1. A spike in requests causes the Java app to experience frequent Java Virtual Machine (JVM) garbage collection (GC).
177177
1. KEDA observes the aggregated metric value for `jvm.gc.count` is increased to `256`, and calculates the `desiredReplicas` value as `ceil(256/30)=9`.
178178
1. KEDA scales out the container app's replica count to 9.
179179
1. The http traffic is distributed across more replicas, reducing the average GC count.

0 commit comments

Comments
 (0)