Skip to content

Commit 968c98d

Browse files
committed
fix
1 parent 731802c commit 968c98d

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

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

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Tutorial: Scale a Java container app with Java metrics"
3-
description: Scale a Java container app with Java metrics.
2+
title: "Tutorial: Scale a container app with Java metrics"
3+
description: Scale a container app with Java metrics.
44
services: container-apps
55
author: craigshoemaker
66
ms.service: azure-container-apps
@@ -11,15 +11,15 @@ 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
---
1313

14-
# Tutorial: Scale a Java container app with Java metrics
14+
# Tutorial: Scale a container app with Java metrics
1515

1616
Azure Container Apps manages automatic horizontal scaling through a set of declarative scaling rules. You can create your own scale rules with [customized event sources](./scale-app.md#custom).
1717

18-
In this tutorial, you add a custom scale rule to scale your container app with Java metrics, and observe how your application scales.
18+
In this tutorial, you add a custom scale rule to scale your container app with Java metrics and observe how your application scales.
1919

2020
## Prerequisites
2121

22-
* An Azure account with an active subscription. If you don't already have one, you can [can create one for free](https://azure.microsoft.com/free/).
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/free/).
2323
* [Azure CLI](/cli/azure/install-azure-cli).
2424
* [A Java application deployed in Azure Container Apps](java-get-started.md).
2525

@@ -28,13 +28,15 @@ In this tutorial, you add a custom scale rule to scale your container app with J
2828
Use the following steps to define environment variables and set up the environment.
2929

3030
1. Create variables to support your scale configuration.
31-
```bash
32-
export LOCATION=eastus
33-
export TENANT_ID={tenant-id}
34-
export SUBSCRIPTION_ID={subscriprion-id}
35-
export RESOURCE_GROUP=my-resource-group
36-
export APP_NAME=my-aca-app
37-
```
31+
32+
```bash
33+
export LOCATION=eastus
34+
export TENANT_ID={tenant-id}
35+
export SUBSCRIPTION_ID={subscription-id}
36+
export RESOURCE_GROUP=my-resource-group
37+
export APP_NAME=my-aca-app
38+
export IDENTITY_NAME=my-identity
39+
```
3840

3941
| Variable | Description |
4042
|-------------------------|------------------------------------------------------------------------------------|
@@ -45,7 +47,6 @@ Use the following steps to define environment variables and set up the environme
4547
| `APP_NAME` | The app name for your Azure Container Apps. |
4648
| `IDENTITY_NAME` | The name for your managed identity, which is assigned to your Azure Container Apps.|
4749
48-
4950
1. Log in to Azure with the Azure CLI.
5051
5152
```azurecli
@@ -61,32 +62,30 @@ Use the following steps to define environment variables and set up the environme
6162
## Set up a managed identity for your Azure Container Apps
6263
To scale with Azure Container Apps platform metrics, you need a managed identity to access metrics from Azure Monitor.
6364
64-
1. Create an user-assigned identity and assign to your Azure Container Apps, you can follow doc [Add a user-assigned identity](./managed-identity.md#add-a-user-assigned-identity).
65-
After you create the identity, run bellow CLI command to set the
66-
```azurecli
67-
USER_ASSIGNED_IDENTITY_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "id" --output tsv)
68-
```
65+
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 below CLI command to set the identity ID.
6966
67+
```azurecli
68+
USER_ASSIGNED_IDENTITY_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "id" --output tsv)
69+
```
7070
71-
2. Grant `Monitoring Reader` role for your managed identity to read data from Azure Monitor. You can find more details aboute the RBAC for Azure Monitor in [Buil-in Role Monitoring Reader](../role-based-access-control/built-in-roles/monitor.md#monitoring-reader)
71+
2. Grant the `Monitoring Reader` role to your managed identity to read data from Azure Monitor. You can find more details about the RBAC for Azure Monitor in [Built-in Role Monitoring Reader](../role-based-access-control/built-in-roles/monitor.md#monitoring-reader).
7272
73-
```azurecli
74-
# Get the principal id for your managed identity
75-
PRINCIPAL_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "principalId" --output tsv)
73+
```azurecli
74+
# Get the principal id for your managed identity
75+
PRINCIPAL_ID=$(az identity show --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME --query "principalId" --output tsv)
7676
77-
az role assignment create --assignee $PRINCIPAL_ID --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
78-
```
77+
az role assignment create --assignee $PRINCIPAL_ID --role "Monitoring Reader" --scope /subscriptions/$SUBSCRIPTION_ID
78+
```
7979
8080
## Add a scale rule with Azure Monitor metrics
81-
To scale with Azure Monitor metrics, you can refer [Azure Monitor keda scaler](https://keda.sh/docs/2.16/scalers/azure-monitor/) to define your Container Apps scale rule.
82-
83-
Here is a list of core meta data to set up the scale rule.
81+
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.
8482
83+
Here is a list of core metadata to set up the scale rule.
8584
8685
| Metadata key | Description |
8786
|------------------------------------|-------------------------------------------------------------------------------------------------------|
8887
| tenantId | Id of the tenant that contains the Azure resource. This is used for authentication. |
89-
| subscriptionId | Id of Azure subscription that contains the Azure resource. This is used for determining the full resource URI. |
88+
| subscriptionId | Id of the Azure subscription that contains the Azure resource. This is used for determining the full resource URI. |
9089
| resourceGroupName | Name of the resource group for the Azure resource. |
9190
| resourceURI | Shortened URI to the Azure resource with format `<resourceProviderNamespace>/<resourceType>/<resourceName>`. |
9291
| metricName | Name of the metric to query. |
@@ -99,7 +98,7 @@ Here is a list of core meta data to set up the scale rule.
9998
10099
Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your application.
101100
102-
# [Azure CLI](#tab/Azure CLI)
101+
# [Azure CLI](#tab/azurecli)
103102
104103
```azurecli
105104
az containerapp update \
@@ -120,11 +119,9 @@ Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your
120119
--scale-rule-identity $USER_ASSIGNED_IDENTITY_ID
121120
```
122121
123-
124-
125-
# [ARM Template](#tab/ARM Template)
122+
# [ARM Template](#tab/arm)
126123
127-
```json
124+
```arm
128125
{
129126
"resources": {
130127
"properties": {
@@ -158,17 +155,16 @@ Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your
158155
}
159156
```
160157
161-
This command adds a scale rule to your container app with name `scale-with-azure-monitor-metrics`, and scale type is set to `azure-monitor`. It uses the managed identity with resource id `USER_ASSIGNED_IDENTITY_ID` to autheticate with Azure Monitor and query metrics for your conatner app. In the example, keda queries metric `JvmGcCount`, and aggregate the metric values within 1 minute with aggregation type `Total`. The target value is set to `30`, which means keda calculates the `desiredReplicas` using `ceil(AggregatedMetricValue(JvmGcCount)/30)`.
158+
This command adds a scale rule to your container app with the name `scale-with-azure-monitor-metrics`, and the scale type is set to `azure-monitor`. It uses the managed identity with resource id `USER_ASSIGNED_IDENTITY_ID` to authenticate with Azure Monitor and query metrics for your container app. In the example, KEDA queries the metric `JvmGcCount`, and aggregates the metric values within 1 minute with aggregation type `Total`. The target value is set to `30`, which means KEDA calculates the `desiredReplicas` using `ceil(AggregatedMetricValue(JvmGcCount)/30)`.
162159
163160
> [!NOTE]
164-
> 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 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.
165-
161+
> 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.
166162

167163
## View scaling in Azure portal (optional)
168164
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.
169-
1. Go to `Metric` blade in Azure Portal for your Azure Container Apps.
165+
1. Go to the `Metrics` blade in the Azure Portal for your Azure Container Apps.
170166
1. Add your metric `jvm.gc.count`, with filter `Revision=<your-revision>` and Split by `Replica`.
171-
1. Add metric `Replica Count`, with filter `Revision=<your-revision>`.
167+
1. Add the metric `Replica Count`, with filter `Revision=<your-revision>`.
172168

173169
Here is a sample metric snapshot for the example scale rule.
174170

@@ -184,18 +180,17 @@ Here is a sample metric snapshot for the example scale rule.
184180
185181
## Scale Log
186182
187-
To view the KEDA scale logs, you can run bellow query in `Logs`.
183+
To view the KEDA scale logs, you can run the below query in `Logs`.
188184
189185
```
190186
ContainerAppSystemLogs
191187
| where RevisionName == "<your-revision>"
192-
| where EventSource == "KEDA"
188+
| where EventSource == "KEDA"
193189
| project TimeGenerated, Type, Reason, ContainerAppName, Log
194190
```
195191
196192
:::image type="content" source="media/java-metrics-keda/keda-auto-scale-java-log.png" alt-text="Screenshot of KEDA scale log query" lightbox="media/java-metrics-keda/keda-auto-scale-java-log.png":::
197193
198-
199194
## Clean up resources
200195
201196
The resources created in this tutorial have an effect on your Azure bill. If you aren't going to use these services long-term, run the following command to remove everything created in this tutorial.

0 commit comments

Comments
 (0)