Skip to content

Commit 8a3c72d

Browse files
author
Wael Kdouh
committed
Addressed issues raised in module 9 review
1 parent c7432b3 commit 8a3c72d

4 files changed

Lines changed: 49 additions & 48 deletions

File tree

docs/aca/06-aca-dapr-bindingsapi/TasksNotifierController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private async Task<bool> SendEmail(TaskModel taskModel)
5959
{
6060
//Introduce artificial delay to slow down message processing
6161
_logger.LogInformation("Simulate slow processing for email sending for Email with Email subject '{0}' Email to: '{1}'", subject, taskModel.TaskAssignedTo);
62-
Thread.Sleep(5000);
62+
Thread.Sleep(1000);
6363
}
6464

6565
if (sendEmailResponse)

docs/aca/06-aca-dapr-bindingsapi/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Now we need to invoke the SendGrid output binding by using the Dapr .NET SDK. Re
272272
```
273273

274274
!!! note
275-
Even though we restored the code to send emails it won't actually trigger sending emails as we set the `IntegrationEnabled` flag to false. Also notice that we introduced a Thread.Sleep(5000) statement. This will come in handy in module 9 where it will be used to simulate artificial delay within the `ACA-Processor Backend` service to demonstrate autoscaling with KEDA.
275+
Even though we restored the code to send emails it won't actually trigger sending emails as we set the `IntegrationEnabled` flag to false. Also notice that we introduced a Thread.Sleep(1000) statement. This will come in handy in module 9 where it will be used to simulate artificial delay within the `ACA-Processor Backend` service to demonstrate autoscaling with KEDA.
276276

277277

278278
??? tip "Curious to learn more about the code above?"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
triggers:
2+
- type: azure-servicebus
3+
metadata:
4+
# Required: queueName OR topicName and subscriptionName
5+
queueName: queueName
6+
# or
7+
topicName: topicName
8+
subscriptionName: subscriptionName
9+
# Optional, required when pod identity is used
10+
namespace: service-bus-namespace
11+
# Optional, can use TriggerAuthentication as well
12+
connectionFromEnv: SERVICEBUS_CONNECTIONSTRING_ENV_NAME # This must be a connection string for a queue itself, and not a namespace level (e.g. RootAccessPolicy) connection string
13+
# Optional
14+
messageCount: "5" # Optional. Count of messages to trigger scaling on. Default: 5 messages
15+
cloud: Private # Optional. Default: AzurePublicCloud
16+
endpointSuffix: servicebus.airgap.example # Required when cloud=Private

docs/aca/09-aca-autoscale-keda/index.md

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,23 @@ So our requirements for scaling the backend processor are as follows:
3434

3535
To achieve this, we will start looking into KEDA Azure Service Bus scaler. This specification describes the `azure-servicebus` trigger for Azure Service Bus Queue or Topic. Let's take a look at the yaml file below which contains a generic template for the KEDA specification:
3636
```yaml
37-
triggers:
38-
- type: azure-servicebus
39-
metadata:
40-
# Required: queueName OR topicName and subscriptionName
41-
queueName: queueName
42-
# or
43-
topicName: topicName
44-
subscriptionName: subscriptionName
45-
# Optional, required when pod identity is used
46-
namespace: service-bus-namespace
47-
# Optional, can use TriggerAuthentication as well
48-
connectionFromEnv: SERVICEBUS_CONNECTIONSTRING_ENV_NAME # This must be a connection string for a queue itself, and not a namespace level (e.g. RootAccessPolicy) connection string
49-
# Optional
50-
messageCount: "5" # Optional. Count of messages to trigger scaling on. Default: 5 messages
51-
cloud: Private # Optional. Default: AzurePublicCloud
52-
endpointSuffix: servicebus.airgap.example # Required when cloud=Private
37+
--8<-- "docs/aca/09-aca-autoscale-keda/KEDA_Azure_Service_Bus scaler.yaml"
5338
```
39+
??? info "Curious to learn more about the contents of the yaml file?"
40+
- The property `type` is set to `azure-servicebus`. Each KEDA scaler specification file has a unique type.
41+
- One of the properties `queueName` or `topicName` should be provided. In our case, it will be `topicName` and we will use the value `tasksavedtopic`.
42+
- The property `subscriptionName` will be set to use `tasksmanager-backend-processor`. This represents the subscription associated with the topic. Not needed if we are using queues.
43+
- The property `connectionFromEnv` will be set to reference a secret stored in our Container App. We will not use the Azure Service Bus shared access policy (connection string) directly. The shared access policy will be stored in the Container App secrets, and the secret will be referenced here. Please note that the Service Bus Shared Access Policy needs to be of type `Manage`. It is required for KEDA to be able to get metrics from Service Bus and read the length of messages in the queue or topic.
44+
- The property `messageCount` is used to decide when scaling out should be triggered. In our case, it will be set to `10`.
45+
- The property `cloud` represents the name of the cloud environment that the service bus belongs to.
5446

55-
Let's review the parameters:
56-
57-
* The property `type` is set to `azure-servicebus`. Each KEDA scaler specification file has a unique type.
58-
* One of the properties `queueName` or `topicName` should be provided. In our case, it will be `topicName` and we will use the value `tasksavedtopic`.
59-
* The property `subscriptionName` will be set to use `tasksmanager-backend-processor`. This represents the subscription associated with the topic. Not needed if we are using queues.
60-
* The property `connectionFromEnv` will be set to reference a secret stored in our Container App. We will not use the Azure Service Bus shared access policy (connection string) directly. The shared access policy will be stored in the Container App secrets, and the secret will be referenced here. Please note that the Service Bus Shared Access Policy needs to be of type `Manage`. It is required for KEDA to be able to get metrics from Service Bus and read the length of messages in the queue or topic.
61-
* The property `messageCount` is used to decide when scaling out should be triggered. In our case, it will be set to `10`.
62-
* The property `cloud` represents the name of the cloud environment that the service bus belongs to.
6347

6448
!!! note
6549
Note about authentication: KEDA scaler for Azure Service Bus supports different authentication mechanisms such as [Pod Managed Identity](https://learn.microsoft.com/en-us/azure/aks/use-azure-ad-pod-identity), [Azure AD Workload Identity](https://azure.github.io/azure-workload-identity/docs/), and shared access policy (connection string). At the time of writing this workshop, when using KEDA with Azure Container Apps the only supported authentication mechanism is Connection Strings. There is a work item in the ACA product backlog that involves enabling [KEDA Scale with Managed Identity.](https://github.com/microsoft/azure-container-apps/issues/592)
6650

6751
Azure Container Apps has its own proprietary schema to map KEDA Scaler template to its own when defining a custom scale rule. You can define this scaling rule via Container Apps [ARM templates](https://learn.microsoft.com/en-us/azure/container-apps/azure-resource-manager-api-spec?tabs=arm-template#container-app-examples), [yaml manifest](https://learn.microsoft.com/en-us/azure/container-apps/azure-resource-manager-api-spec?tabs=arm-template#container-app-examples), Azure CLI, or from the Azure Portal. In this module, we will cover how to do it from the Azure CLI.
6852

69-
##### 1. Create a New Secret In The Container App
53+
#### 1. Create a New Secret In The Container App
7054

7155
Let's now create a secret named `svcbus-connstring` in our `tasksmanager-backend-processor` Container App. This secret will contain the value of Azure Service Bus shared access policy (connection string) with `Manage` policy. To accomplish this, run the following commands in the Azure CLI to get the connection string, and then add this secret using the second command:
7256

@@ -86,11 +70,11 @@ az containerapp secret set `
8670
--secrets "svcbus-connstring=$ServiceBusConnectionString"
8771
```
8872

89-
##### 2. Create a Custom Scaling Rule from Azure CLI
73+
#### 2. Create a Custom Scaling Rule from Azure CLI
9074
Now we are ready to add a new custom scaling rule to match the business requirements. To accomplish this, we need to run the Azure CLI command below:
9175

9276
!!! note
93-
We need to update `az containerapp` extension in order to create a scaling rule from CLI. To update the extension you can run the following command `az extension update --name containerapp` inside your powershell terminal.
77+
You might need to upgrade the extension if you are on an older version of `az containerapp` which didn't allow you to create a scaling rule from CLI. To update the extension you can run the following command `az extension update --name containerapp` inside your powershell terminal.
9478

9579
```powershell
9680
az containerapp update `
@@ -110,22 +94,23 @@ az containerapp update `
11094
"connectionFromEnv=svcbus-connstring"
11195
```
11296

113-
What we have done is the following:
114-
115-
* Setting the minimum number of replicas to `1`. This means that this Container App could be scaled-in to a single replica if there are no new messages on the topic.
116-
* Setting the maximum number of replicas to `5`. This means that this Container App will not exceed more than 5 replicas regardless of the number of messages on the topic.
117-
* Setting a friendly name for the scale rule `topic-msgs-length` which will be visible in the Azure Portal.
118-
* Setting the scale rule type to `azure-servicebus`. This is important to tell KEDA which type of scalers our Container App is configuring.
119-
* Setting the authentication mechanism to type `connection` and indicating which secret reference will be used. In our case `svcbus-connstring`.
120-
* Setting the `metadata` dictionary of the scale rule. Those match the metadata properties in KEDA template we discussed earlier.
121-
* Disabled the integration with SendGrid as we are going to send several messages to test the scale out rule.
97+
??? info "Curious to learn more about the different parameters passed to the `az containerapp update` command?"
98+
- Setting the minimum number of replicas to `1`. This means that this Container App could be scaled-in to a single replica if there are no new messages on the topic.
99+
- Setting the maximum number of replicas to `5`. This means that this Container App will not exceed more than 5 replicas regardless of the number of messages on the topic.
100+
- Setting a friendly name for the scale rule `topic-msgs-length` which will be visible in the Azure Portal.
101+
- Setting the scale rule type to `azure-servicebus`. This is important to tell KEDA which type of scalers our Container App is configuring.
102+
- Setting the authentication mechanism to type `connection` and indicating which secret reference will be used. In our case `svcbus-connstring`.
103+
- Setting the `metadata` dictionary of the scale rule. Those match the metadata properties in KEDA template we discussed earlier.
104+
- Disabled the integration with SendGrid as we are going to send several messages to test the scale out rule.
122105

123-
**Note About Setting Minimum Replicas To 0:**
124-
* We can set the minimum number of replicas to `zero` to avoid any charges when the backend processor is not processing any message from Azure Service Bus Topic, but this will impact running the other features within this backend processor such as the periodic cron job as well as the external input bidding and output bindings. We are configuring the minimum number of replicas to one, ensuring that a backend processor instance is always running and capable of handling tasks, even if there are no messages being received by the Azure Service Bus Topic.
106+
!!! note
107+
**Note About Setting Minimum Replicas To 0:**
108+
109+
* We can set the minimum number of replicas to `zero` to avoid any charges when the backend processor is not processing any message from Azure Service Bus Topic, but this will impact running the other features within this backend processor such as the periodic cron job as well as the external input bidding and output bindings. We are configuring the minimum number of replicas to one, ensuring that a backend processor instance is always running and capable of handling tasks, even if there are no messages being received by the Azure Service Bus Topic.
125110

126-
* When the single replica of the backend processor is not doing anything, it will be running in an `idle mode`. When the replica is in idle mode usage is charged at a reduced idle rate. A replica enters an active mode and is charged at the active rate when it is starting up, and when it is processing requests. For more details about the ACA pricing visit [the link.](https://azure.microsoft.com/en-us/pricing/details/container-apps/)
111+
* When the single replica of the backend processor is not doing anything, it will be running in an `idle mode`. When the replica is in idle mode usage is charged at a reduced idle rate. A replica enters an active mode and is charged at the active rate when it is starting up, and when it is processing requests. For more details about the ACA pricing visit [the link.](https://azure.microsoft.com/en-us/pricing/details/container-apps/)
127112

128-
##### 3. Run an End-to-End Test and Generate a Several Messages
113+
#### 3. Run an End-to-End Test and Generate a Several Messages
129114
Now we are ready to test out our Azure Service Bus Scaling Rule. To produce a high volume of messages, you can utilize Service Bus Explorer located within your Azure Service Bus namespace. Navigate to Azure Service Bus, choose your topic/subscription, and then select the Service Bus Explorer option.
130115

131116
To get the number of current replicas of service `tasksmanager-backend-processor ` we could run the command below, this should run single replica as we didn't load the service bus topic yet.
@@ -154,13 +139,13 @@ The message structure our backend processor expects is similar to the JSON shown
154139
```
155140
![svcbus-send](../../assets/images/09-aca-autoscale-keda/svs-bus-send.jpg)
156141

157-
##### 4. Verify that Multiple Replicas Are Created
158-
159-
If all is setup correctly, 5 replicas will be created based on the number of messages we generated into the topic. There are various ways to verify this:
142+
#### 4. Verify that Multiple Replicas Are Created
143+
!!! success
144+
If all is setup correctly, 5 replicas will be created based on the number of messages we generated into the topic. There are various ways to verify this:
160145

161-
* You can run the Azure CLI command used in [previous step](#3-run-an-end-to-end-test-and-generate-a-load-of-messages) to list the names of replicas.
162-
* You can verify this from Container Apps `Console` tab where you will see those replicas in the drop-down list
163-
![replica-console](../../assets/images/09-aca-autoscale-keda/replica-console.png)
146+
* You can run the Azure CLI command used in [previous step](#3-run-an-end-to-end-test-and-generate-a-load-of-messages) to list the names of replicas.
147+
* You can verify this from Container Apps `Console` tab where you will see those replicas in the drop-down list
148+
![replica-console](../../assets/images/09-aca-autoscale-keda/replica-console.png)
164149

165150
!!! note
166151
**Note About KEDA Scale In:**

0 commit comments

Comments
 (0)