You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/container-apps/java-metrics-scale-with-keda.md
+36-41Lines changed: 36 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
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.
4
4
services: container-apps
5
5
author: craigshoemaker
6
6
ms.service: azure-container-apps
@@ -11,15 +11,15 @@ ms.author: cshoe
11
11
#customer intent: As a developer, I want to set up auto scale using Java metrics exposed from Azure Container Apps
12
12
---
13
13
14
-
# Tutorial: Scale a Java container app with Java metrics
14
+
# Tutorial: Scale a container app with Java metrics
15
15
16
16
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).
17
17
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.
19
19
20
20
## Prerequisites
21
21
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/).
23
23
*[Azure CLI](/cli/azure/install-azure-cli).
24
24
*[A Java application deployed in Azure Container Apps](java-get-started.md).
25
25
@@ -28,13 +28,15 @@ In this tutorial, you add a custom scale rule to scale your container app with J
28
28
Use the following steps to define environment variables and set up the environment.
29
29
30
30
1. Create variables to support your scale configuration.
@@ -45,7 +47,6 @@ Use the following steps to define environment variables and set up the environme
45
47
| `APP_NAME` | The app name for your Azure Container Apps. |
46
48
| `IDENTITY_NAME` | The name for your managed identity, which is assigned to your Azure Container Apps.|
47
49
48
-
49
50
1. Log in to Azure with the Azure CLI.
50
51
51
52
```azurecli
@@ -61,32 +62,30 @@ Use the following steps to define environment variables and set up the environme
61
62
## Set up a managed identity for your Azure Container Apps
62
63
To scale with Azure Container Apps platform metrics, you need a managed identity to access metrics from Azure Monitor.
63
64
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
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.
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).
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
+
```
79
79
80
80
## 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.
84
82
83
+
Here is a list of core metadata to set up the scale rule.
| 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. |
90
89
| resourceGroupName | Name of the resource group for the Azure resource. |
91
90
| resourceURI | Shortened URI to the Azure resource with format `<resourceProviderNamespace>/<resourceType>/<resourceName>`. |
92
91
| 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.
99
98
100
99
Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your application.
101
100
102
-
# [Azure CLI](#tab/Azure CLI)
101
+
# [Azure CLI](#tab/azurecli)
103
102
104
103
```azurecli
105
104
az containerapp update \
@@ -120,11 +119,9 @@ Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your
120
119
--scale-rule-identity $USER_ASSIGNED_IDENTITY_ID
121
120
```
122
121
123
-
124
-
125
-
# [ARM Template](#tab/ARM Template)
122
+
# [ARM Template](#tab/arm)
126
123
127
-
```json
124
+
```arm
128
125
{
129
126
"resources": {
130
127
"properties": {
@@ -158,17 +155,16 @@ Add a scale rule with [metrics from Azure Container Apps](./metrics.md) for your
158
155
}
159
156
```
160
157
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)`.
162
159
163
160
> [!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.
166
162
167
163
## View scaling in Azure portal (optional)
168
164
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.
170
166
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>`.
172
168
173
169
Here is a sample metric snapshot for the example scale rule.
174
170
@@ -184,18 +180,17 @@ Here is a sample metric snapshot for the example scale rule.
184
180
185
181
## Scale Log
186
182
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`.
:::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":::
197
193
198
-
199
194
## Clean up resources
200
195
201
196
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