Skip to content

Commit

Permalink
Fix: visits-service scale down to one, not zero (#103)
Browse files Browse the repository at this point in the history
## Purpose

If `visits-service` scales down to zero, we will meet the error `503
Service Unavailable` when calling it via api-gateway.
This is because that the spring cloud gateway internally use Eureka
Service Discovery to discover the instance. When scaled to zero, it will
be considered as no such instance.

## Does this introduce a breaking change?
<!-- Mark one with an "x". -->
```
[ ] Yes
[ ] No
```

## Pull Request Type
What kind of change does this Pull Request introduce?

<!-- Please check the one that applies to this PR using "x". -->
```
[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:
```

## How to Test
*  Get the code

```
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
```

* Test the code
<!-- Add steps to run the tests suite and/or manually test -->
```
```

## What to Check
Verify that the following are valid
* ...

## Other Information
<!-- Add any other helpful information that may be needed here. -->

Co-authored-by: Hao Zhang <[email protected]>
  • Loading branch information
haoozhang and Hao Zhang authored Oct 22, 2024
1 parent 80cb32d commit 4c3b04f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/11_lab_scale/1102.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parent: 'Lab 11: Set up autoscaling for microservices on ACA'

# Set up a custom scaling rule

In addition to the HTTP scaling rule, you can also configure a custom scaling rule based on any [ScaledJob](https://keda.sh/docs/2.15/concepts/scaling-jobs/)-based [KEDA scalers](https://keda.sh/docs/2.15/scalers/). The example below demonstrates how to set up an [Azure Service Bus scaler](https://keda.sh/docs/2.15/scalers/azure-service-bus/) for the `visits-service` container app. Once configured, you can send batch messages to the message queue and observe the auto-scaling behavior of the `visits-service` replicas. After a period of inactivity (no incoming message), you can see the replicas scaling down to zero.
In addition to the HTTP scaling rule, you can also configure a custom scaling rule based on any [ScaledJob](https://keda.sh/docs/2.15/concepts/scaling-jobs/)-based [KEDA scalers](https://keda.sh/docs/2.15/scalers/). The example below demonstrates how to set up an [Azure Service Bus scaler](https://keda.sh/docs/2.15/scalers/azure-service-bus/) for the `visits-service` container app. Once configured, you can send batch messages to the message queue and observe the auto-scaling behavior of the `visits-service` replicas. After a period of inactivity (no incoming message), you can see the replicas scaling down to minimum number.

## Step by step guidance

Expand All @@ -22,7 +22,7 @@ In addition to the HTTP scaling rule, you can also configure a custom scaling ru
az containerapp update \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--min-replicas 0 \
--min-replicas 1 \
--max-replicas 10 \
--scale-rule-name servicebus-queue-scale-rule \
--scale-rule-type azure-servicebus \
Expand Down Expand Up @@ -79,5 +79,5 @@ In addition to the HTTP scaling rule, you can also configure a custom scaling ru
1. Navigate to the portal of the container app `visits-service`, expand **Application** and select **Revisions and replicas**, then select **Replicas** tab. You can see the container app now has more than one replica running.
![service bus rule scale out](../../images/lab11_service_bus_rule_scale_out.png)

1. After low incoming requests for 300 seconds (scale down stabilization window), the replicas will gradually scale down to low count. If there are no further incoming requests for 300 seconds (cool down period), the replicas will eventually scale down to zero. You can also observe the revision status as **Scaled to zero** in the Azure portal.
1. After low incoming requests for 300 seconds (scale down stabilization window), the replicas will gradually scale down to low count. If there are no further incoming requests for 300 seconds (cool down period), the replicas will eventually scale down to minimum number. You can also observe the replica details in the Azure portal.
![service bus rule scale in](../../images/lab11_service_bus_rule_scale_in.png)
Binary file modified images/lab11_service_bus_rule_scale_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/lab11_service_bus_scale_rule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4c3b04f

Please sign in to comment.