This tutorial includes the following steps
- Build and Deploy sample Golang Application
- Create Autoscaler Service Instance
- Bind App with Autoscaler Service
- Start Golang App
- Send Custom Metrics to Autoscaler Service
- Monitor Scale-Out and Scale-In
- You should have access to Cloud Foundry Runtime
make test
cf push --no-start -f deploy/app-manifest.yml -p deploy/build
sample-output
$ cf push --no-start -f deploy/app-manifest.yml -p deploy/build
Pushing app golang-autoscaler-custom-metrics to org ak_autoscalerxxx / space ak-test-space as [email protected]...
Applying manifest file deploy/app-manifest.yml...
Updating with these attributes...
---
applications:
- name: golang-autoscaler-custom-metrics
disk-quota: 128M
instances: 1
path: /Users/development/golang-autoscaler-custom-metrics/deploy/build
memory: 128M
+ default-route: true
stack: cflinuxfs4
buildpacks:
binary_buildpack
command: ./golang-autoscaler-custom-metrics
Manifest applied
All files found in remote cache; nothing to upload.
Waiting for API to complete processing files...
name: golang-autoscaler-custom-metrics
requested state: stopped
routes: golang-autoscaler-custom-metrics.cfapps.sap.hana.ondemand.com
last uploaded:
stack:
buildpacks:
type: web
sidecars:
instances: 0/1
memory usage: 128M
start command: ./golang-autoscaler-custom-metrics
state since cpu memory disk details
#0 down 2022-12-30T14:22:58Z 0.0% 0 of 0 0 of 0
$ cf create-service autoscaler standard ak-test-autoscaler
Creating service instance ak-test-autoscaler in org ak_autoscalerxxx / space ak-test-space as as [email protected]...
Service instance ak-test-autoscaler created.
OK
$ cf bind-service golang-autoscaler-custom-metrics ak-test-autoscaler -c deploy/custom-metrics-policy.json
$ cf bind-service golang-autoscaler-custom-metrics ak-test-autoscaler -c deploy/custom-metrics-policy.json
Binding service instance ak-test-autoscaler to app golang-autoscaler-custom-metrics in org ak_autoscalerxxx / space ak-test-space as [email protected]...
OK
TIP: Use 'cf restage golang-autoscaler-custom-metrics' to ensure your env variable changes take effect
$ cf env golang-autoscaler-custom-metrics
Getting env variables for app golang-autoscaler-custom-metrics in org ak_autoscalerxxx / space ak-test-space as [email protected]...
System-Provided:
VCAP_SERVICES: {
"autoscaler": [
{
"binding_guid": "c02fba90-83b2-4753-a31f-1d0827978632",
"binding_name": null,
"credentials": {
"custom_metrics": {
"mtls_url": "https://autoscaler-metrics-mtls.cf.xxx.com",
"password": "xxxxxxxxx",
"url": "https://autoscaler-metrics.cf.xxx.com",
"username": "xxxxxxxxx"
}
},
"instance_guid": "3eeac1a2-ced1-4748-a3b4-a87188a7d3c6",
"instance_name": "ak-test-autoscaler",
"label": "autoscaler",
"name": "ak-test-autoscaler",
"plan": "standard",
"provider": null,
"syslog_drain_url": null,
"tags": [
"autoscaler",
"app-autoscaler",
"cf-autoscaler"
],
"volume_mounts": []
}
]
}
VCAP_APPLICATION: {
...
....
...
cf start golang-autoscaler-custom-metrics
cf start golang-autoscaler-custom-metrics
Starting app golang-autoscaler-custom-metrics in org ak_autoscalerxxx / space ak-test-space as [email protected]...
Staging app and tracing logs...
Downloading binary_buildpack...
Downloaded binary_buildpack
Cell 038ca894-a748-49d5-85eb-be08569dfe48 creating container for instance 95b8140e-065c-4116-8c42-085f3f33db27
Cell 038ca894-a748-49d5-85eb-be08569dfe48 successfully created container for instance 95b8140e-065c-4116-8c42-085f3f33db27
Downloading app package...
Downloading build artifacts cache...
Downloaded build artifacts cache (215B)
Downloaded app package (6M)
-----> Binary Buildpack version 1.0.47
Exit status 0
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (216B)
Starting app golang-autoscaler-custom-metrics in org ak_autoscalerxxx / space ak-test-space as [email protected]...
Waiting for app to start...
Instances starting...
Instances starting...
Instances starting...
name: golang-autoscaler-custom-metrics
requested state: started
routes: golang-autoscaler-custom-metrics.cfapps.sap.hana.ondemand.com
last uploaded: Fri 30 Dec 16:04:06 CET 2022
stack: cflinuxfs4
buildpacks:
name version detect output buildpack name
binary_buildpack 1.0.47 binary binary
type: web
sidecars:
instances: 1/1
memory usage: 128M
state since cpu memory disk details
#0 running 2022-12-30T15:04:16Z 0.0% 0 of 128M 0 of 128M
Scale out > $ curl https://golang-autoscaler-custom-metrics.cfapps.abc.com/busy/301
Every 2.0s: cf app golang-autoscaler-custom-metrics XNQNV6VGJC: Fri Dec 30 16:19:22 2022
Showing health and status for app golang-autoscaler-custom-metrics in org ak_autoscalerxxx / space ak-test-space as [email protected]...
name: golang-autoscaler-custom-metrics
requested state: started
routes: golang-autoscaler-custom-metrics.cfapps.sap.hana.ondemand.com
last uploaded: Fri 30 Dec 16:16:35 CET 2022
stack: cflinuxfs4
buildpacks:
name version detect output buildpack name
binary_buildpack 1.0.47 binary binary
type: web
sidecars:
instances: 2/2
memory usage: 128M
state since cpu memory disk details
#0 running 2022-12-30T15:16:44Z 0.9% 23.6M of 128M 10.9M of 128M
#1 running 2022-12-30T15:18:13Z 0.9% 22.9M of 128M 10.9M of 128M
Scale In > $ curl https://golang-autoscaler-custom-metrics.cfapps.abc.com/not-busy/190
Checkout the blog for more details on how to use Custom Metrics in Application Autoscaler.