2022-10-07 10:31:32 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
##############################################################################
|
|
|
|
# Usage: ./scaling.sh
|
|
|
|
# Switch auto scaling modes
|
|
|
|
# Make sure you have the correct environment variables set.
|
|
|
|
# For that, first run: source ./azure.sh env
|
|
|
|
##############################################################################
|
2022-10-07 11:59:41 +03:00
|
|
|
# Dependencies: Azure CLI
|
2022-10-07 10:31:32 +03:00
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
set -e
|
|
|
|
cd $(dirname ${BASH_SOURCE[0]})
|
|
|
|
cd ../..
|
|
|
|
|
|
|
|
command=${1}
|
|
|
|
|
|
|
|
showUsage() {
|
|
|
|
script_name="$(basename "$0")"
|
|
|
|
echo "Usage: ./$script_name setup|restore|ping"
|
|
|
|
echo "Setup auto-scaling mode for apps."
|
|
|
|
echo
|
|
|
|
echo "Commands:"
|
|
|
|
echo " setup Setup auto-scaling as in the docs"
|
|
|
|
echo " restore Restore default auto-scaling"
|
|
|
|
echo " ping Send a curl to the 3 apps"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$command" ]; then
|
|
|
|
showUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$command" == "setup" ]; then
|
|
|
|
|
|
|
|
echo "Setting up auto-scaling..."
|
|
|
|
|
|
|
|
# tag::adocAutoScalingCpu[]
|
|
|
|
az containerapp update \
|
|
|
|
--name "$QUARKUS_APP" \
|
|
|
|
--resource-group "$RESOURCE_GROUP" \
|
|
|
|
--scale-rule-name "cpu-scaling" \
|
|
|
|
--scale-rule-type "cpu" \
|
|
|
|
--scale-rule-metadata type=Utilization value=10 \
|
|
|
|
--min-replicas 1 \
|
|
|
|
--max-replicas 10
|
2022-10-07 11:01:25 +03:00
|
|
|
# end::adocAutoScalingCpu[]
|
2022-10-07 10:31:32 +03:00
|
|
|
|
|
|
|
# tag::adocAutoScalingMemory[]
|
|
|
|
az containerapp update \
|
|
|
|
--name "$MICRONAUT_APP" \
|
|
|
|
--resource-group "$RESOURCE_GROUP" \
|
|
|
|
--scale-rule-name "memory-scaling" \
|
|
|
|
--scale-rule-type "memory" \
|
|
|
|
--scale-rule-metadata type=Utilization value=15 \
|
|
|
|
--min-replicas 1 \
|
|
|
|
--max-replicas 10
|
2022-10-07 11:01:25 +03:00
|
|
|
# end::adocAutoScalingMemory[]
|
2022-10-07 10:31:32 +03:00
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
elif [ "$command" == "restore" ]; then
|
|
|
|
|
|
|
|
echo "Restoring default auto-scaling..."
|
|
|
|
|
|
|
|
az containerapp update \
|
|
|
|
--name "$QUARKUS_APP" \
|
|
|
|
--resource-group "$RESOURCE_GROUP" \
|
|
|
|
--scale-rule-name "http-scaling" \
|
|
|
|
--scale-rule-metadata concurrentRequests=10 \
|
|
|
|
--min-replicas 0 \
|
|
|
|
--max-replicas 10
|
|
|
|
|
|
|
|
az containerapp update \
|
|
|
|
--name "$MICRONAUT_APP" \
|
|
|
|
--resource-group "$RESOURCE_GROUP" \
|
|
|
|
--scale-rule-name "http-scaling" \
|
|
|
|
--scale-rule-metadata concurrentRequests=10 \
|
|
|
|
--min-replicas 0 \
|
|
|
|
--max-replicas 10
|
|
|
|
|
|
|
|
az containerapp update \
|
|
|
|
--name "$SPRING_APP" \
|
|
|
|
--resource-group "$RESOURCE_GROUP" \
|
|
|
|
--scale-rule-name "http-scaling" \
|
|
|
|
--scale-rule-metadata concurrentRequests=10 \
|
|
|
|
--min-replicas 0 \
|
|
|
|
--max-replicas 10
|
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
|
|
|
|
elif [ "$command" == "ping" ]; then
|
|
|
|
|
|
|
|
echo "Pinging apps..."
|
2022-10-07 11:53:15 +03:00
|
|
|
# tag::adocPingApps[]
|
2022-10-07 10:31:32 +03:00
|
|
|
curl https://${QUARKUS_HOST}/quarkus
|
|
|
|
echo
|
|
|
|
curl https://${MICRONAUT_HOST}/micronaut
|
|
|
|
echo
|
|
|
|
curl https://${SPRING_HOST}/springboot
|
|
|
|
echo
|
2022-10-07 11:53:15 +03:00
|
|
|
# end::adocPingApps[]
|
2022-10-07 10:31:32 +03:00
|
|
|
|
|
|
|
else
|
|
|
|
showUsage
|
|
|
|
exit
|
|
|
|
fi
|