### cURL Example: Create Credential Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst This cURL command demonstrates how to create a credential for the App Autoscaler metric server. Ensure you replace placeholders with your actual server URL, port, and application GUID. ```bash curl "https://[the-api-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/credential" \ -X PUT \ -H "Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidWFhLWlkLTQwOCIsImVtYWlsIjoiZW1haWwtMzAzQHNvbWVkb21haW4uY29tIiwic2NvcGUiOlsiY2xvdWRfY29udHJvbGxlci5hZG1pbiJdLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciJdLCJleHAiOjE0NDU1NTc5NzF9.RMJZvSzCSxpj4jjZBmzbO7eoSfTAcIWVSHqFu5_Iu_o" ``` -------------------------------- ### Install Pre-commit using pip Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Installs pre-commit and its git hooks using pip. Ensure pip is available on your system. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Install Pre-commit using curl Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Installs pre-commit using a curl command to download and execute the installation script. This method is useful if pip is not directly available or preferred. ```bash curl https://pre-commit.com/install-local.py | python - pre-commit install ``` -------------------------------- ### Install MultiApps CF CLI Plugin Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Installs the MultiApps CF CLI plugin on your local machine. Use this to manage MTAR deployments. ```bash # Check if already installed cf plugins | grep multiapps # Install the plugin cf install-plugin multiapps ``` -------------------------------- ### Install Pre-commit using Homebrew Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Installs pre-commit using the Homebrew package manager. This is a convenient option for macOS users. ```bash brew install pre-commit pre-commit install ``` -------------------------------- ### Example Schedule for App AutoScaler Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Defines a schedule to override default instance limits for a specific time period, setting initial minimum, minimum, and maximum instance counts. ```json { "start_date_time": "2099-01-01T10:00", "end_date_time": "2099-01-01T20:00", "instance_min_count": 10, "instance_max_count": 100, "initial_min_instance_count": 50 } ``` -------------------------------- ### Backup PostgreSQL Database Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Perform a database backup using pg_dump before starting the migration. ```bash pg_dump -h -U -d autoscaler > autoscaler_backup_$(date +%F).sql ``` -------------------------------- ### Response Body for Create Credential Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst This is an example of the JSON response received after successfully creating a credential. It includes the application ID, generated username and password, and the metric server URL. ```json { "app_id": "", "username": "MY_USERNAME", "password": "MY_PASSWORD", "url": "" } ``` -------------------------------- ### Install Pre-commit using Conda Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Installs pre-commit using the Conda package manager, specifically from the conda-forge channel. This is suitable for users managing environments with Conda. ```bash conda install -c conda-forge pre-commit pre-commit install ``` -------------------------------- ### cURL Example for Submitting Custom Metrics Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst This cURL command demonstrates how to send a custom metric payload to the Autoscaler metric server. Replace placeholders with your specific values and ensure proper authorization. ```bash curl "https://[the-autoscaler-metric-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/metrics" \ -X PUT \ -d @metric.json \ -H "Content-Type: application/json" \ -H "Authorization: basic xxxx" ``` -------------------------------- ### GET /v1/apps/{guid}/aggregated_metric_histories Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Retrieves a history of aggregated metrics for a specific application. Supports pagination and sorting. ```APIDOC ## GET /v1/apps/{guid}/aggregated_metric_histories ### Description Retrieves a history of aggregated metrics for a specific application. Supports pagination and sorting. ### Method GET ### Endpoint /v1/apps/{guid}/aggregated_metric_histories ### Parameters #### Query Parameters - **start-time** (long) - Required - The start timestamp for the metric history. - **end-time** (long) - Required - The end timestamp for the metric history. - **order-direction** (string) - Optional - The direction to order the results. Accepted values: "asc", "desc". Defaults to "asc". - **page** (int) - Optional - The page number to query. Defaults to 1. - **results-per-page** (int) - Optional - The number of results per page. Defaults to 50. ### Request Example ```bash curl "https://[the-api-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/aggregated_metric_histories?start-time=1494989539138350432&end-time=1494989539138399999&order-direction=asc&page=1&results-per-page=10" \ -X GET \ -H "Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidWFhLWlkLTQwOCIsImVtYWlsIjoiZW1haWwtMzAzQHNvbWVkb21haW4uY29tIiwic2NvcGUiOlsiY2xvdWRfY29udHJvbGxlci5hZG1pbiJdLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciJdLCJleHAiOjE0NDU1NTc5NzF9.RMJZvSzCSxpj4jjZBmzbO7eoSfTAcIWVSHqFu5_Iu_o" ``` ### Response #### Success Response (200) - **total_results** (int) - The total number of results available. - **total_pages** (int) - The total number of pages. - **page** (int) - The current page number. - **prev_url** (string) - URL for the previous page, or null if on the first page. - **next_url** (string) - URL for the next page, or null if on the last page. - **resources** (array) - An array of metric history objects. - **app_guid** (string) - The GUID of the application. - **timestamp** (long) - The timestamp of the metric. - **metric_type** (string) - The type of the metric (e.g., "memoryused"). - **value** (string) - The value of the metric. - **unit** (string) - The unit of the metric (e.g., "megabytes"). #### Response Example ```json { "total_results": 2, "total_pages": 1, "page": 1, "prev_url": null, "next_url": "/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/aggregated_metric_histories?start-time=1494989539138350432&end-time=1494989539138399999&order-direction=asc&page=2&results-per-page=10", "resources": [ { "app_guid": "8d0cee08-23ad-4813-a779-ad8118ea0b91", "timestamp": 1494989539138350433, "metric_type": "memoryused", "value": "400", "unit": "megabytes" }, { "app_guid": "8d0cee08-23ad-4813-a779-ad8118ea0b91", "timestamp": 1494989539138350433, "metric_type": "memoryused", "value": "400", "unit": "megabytes" } ] } ``` ``` -------------------------------- ### Create Autoscaling Credential using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Creates a custom metric credential for an application, which is then displayed in JSON format. Refer to the CLI user guide for more details. ```bash cf create-autoscaling-credential ``` -------------------------------- ### GET /v1/apps/:guid/policy Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Retrieves the current autoscaling policy configuration for the specified application. ```APIDOC ## GET /v1/apps/:guid/policy ### Description Retrieves the autoscaling policy details for a given application. ### Method GET ### Endpoint /v1/apps/:guid/policy ### Parameters #### Path Parameters - **guid** (string) - Required - The GUID of the application ### Response #### Success Response (200) - **instance_min_count** (integer) - Minimum number of instances - **instance_max_count** (integer) - Maximum number of instances - **scaling_rules** (array) - List of scaling rules - **schedules** (object) - Schedule configuration #### Response Example { "instance_min_count": 1, "instance_max_count": 4, "scaling_rules": [ { "metric_type": "memoryused", "breach_duration_secs": 600, "threshold": 30, "operator": "<", "cool_down_secs": 300, "adjustment": "-1" } ], "schedules": { "timezone": "Asia/Shanghai" } } ``` -------------------------------- ### cURL Example: Delete Credential Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst This cURL command shows how to delete the credential associated with an application's custom metric submission. Replace placeholders with your specific API server URL, port, and application GUID. ```bash curl "https://[the-api-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/credential" \ -X DELETE \ ``` -------------------------------- ### Retrieve application scaling history via cURL Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Use this cURL command to fetch the scaling history for a specific application GUID. Ensure the Authorization header contains a valid bearer token. ```bash curl "https://[the-api-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/scaling_histories?start-time=1494989539138350432&end-time=1494989539138399999&order-direction=desc&page=1&results-per-page=10" \ -X GET \ -H "Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidWFhLWlkLTQwOCIsImVtYWlsIjoiZW1haWwtMzAzQHNvbWVkb21haW4uY29tIiwic2NvcGUiOlsiY2xvdWRfY29udHJvbGxlci5hZG1pbiJdLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciJdLCJleHAiOjE0NDU1NTc5NzF9.RMJZvSzCSxpj4jjZBmzbO7eoSfTAcIWVSHqFu5_Iu_o" ``` -------------------------------- ### Query Scaling Events using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Retrieves the scaling event history for a specified application. Advanced options for time range and number of events are available in the CLI user guide. ```bash cf ash ``` -------------------------------- ### Query Metrics using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Queries the most recent aggregated metrics for a specified application and metric type. Advanced options for time range and number of values are available in the CLI user guide. ```bash cf asm ``` -------------------------------- ### Define Throughput Scaling Rule Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Example of a dynamic scaling rule to scale out an application by adding 2 instances when throughput exceeds 800 requests per second. This rule uses 'throughput' as the metric type. ```json { "metric_type": "throughput", "operator": ">=", "threshold": 800, "adjustment": "+2" } ``` -------------------------------- ### Get Aggregated Metric Histories Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Use this cURL command to retrieve historical metric data for a specific application. Ensure you replace placeholders with your actual API server URL, port, and bearer token. ```bash curl "https://[the-api-server-url]:[port]/v1/apps/8d0cee08-23ad-4813-a779-ad8118ea0b91/aggregated_metric_histories?start-time=1494989539138350432&end-time=1494989539138399999&order-direction=asc&page=1&results-per-page=10" \ -X GET \ -H "Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidWFhLWlkLTQwOCIsImVtYWlsIjoiZW1haWwtMzAzQHNvbWVkb21haW4uY29tIiwic2NvcGUiOlsiY2xvdWRfY29udHJvbGxlci5hZG1pbiJdLCJhdWQiOlsiY2xvdWRfY29udHJvbGxlciJdLCJleHAiOjE0NDU1NTc5NzF9.RMJZvSzCSxpj4jjZBmzbO7eoSfTAcIWVSHqFu5_Iu_o" ``` -------------------------------- ### Configure User-Provided Service for Credentials Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Commands to create a user-provided service with the credential file and bind it to the application. ```bash >>> cf create-user-provided-service -p ... >>> cf bind-service ... TIP: Use 'cf restage ' to ensure your env variable changes take effect ``` -------------------------------- ### Build the database application Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/src/db/README.md Compiles and packages the application using Maven. Ensure database credentials are configured in application.properties before running. ```shell mvn clean package ``` -------------------------------- ### Monitor Deployment Logs Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Check the logs of the apiserver and scalingengine to verify the deployment status. ```bash # Monitor logs during deployment, some autoscaler traffic should get to the app instances. cf logs apiserver --recent cf logs scalingengine --recent ``` -------------------------------- ### Deploy the Autoscaler Pipeline Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/ci/README.md Commands to set the target environment and deploy the autoscaler pipeline configuration. ```makefile make set-target make set-autoscaler-pipeline ``` -------------------------------- ### Deploy MTAR with MultiApps Plugin Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Authenticate with the Cloud Foundry environment and deploy the MTAR using the extension file. ```bash # Log in to your CF environment cf login -a https://api.your-cf-domain.com # Target the org and space for deployment cf target -o -s # Deploy with extension file cf deploy app-autoscaler.mtar -e production.mtaext ``` -------------------------------- ### GET /v1/apps/:guid/aggregated_metric_histories/:metric_type Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Retrieves the aggregated metric result of an application based on the specified metric type. ```APIDOC ## GET /v1/apps/:guid/aggregated_metric_histories/:metric_type ### Description AutoScaler collects the instances' metrics of an application and aggregates the raw data into an accumulated value for evaluation. This API is used to return the aggregated metric result of an application. ### Method GET ### Endpoint /v1/apps/:guid/aggregated_metric_histories/:metric_type ### Parameters #### Path Parameters - **guid** (string) - Required - The GUID of the application - **metric_type** (string) - Required - The metric type (e.g., "memoryused", "memoryutil", "responsetime", "throughput", "cpu") #### Query Parameters - **start-time** (int) - Optional - The start time in nanoseconds since January 1, 1970 UTC (default: 0) - **end-time** (int) - Optional - The end time in nanoseconds since January 1, 1970 UTC (default: now) - **order-direction** (string) - Optional - The order type, "asc" or "desc" (default: desc) ### Response #### Success Response (200) - **resources** (array) - List of aggregated metric records - **next_url** (string) - URL for the next page of results ``` -------------------------------- ### Create and View Autoscaler Credentials Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Commands to generate credentials for the App Autoscaler extension and display the resulting JSON configuration. ```bash >>>cf create-autoscaling-credential --output ... >>> cat { "app_id": "c99f4f6d-2d67-4eb6-897f-21be90e0dee5", "username": "9bb48dd3-9246-4d7e-7827-b478e9bbedcd", "password": "c1e47d80-e9a0-446a-782b-63fe9f974d4c", "url": "https://autoscalermetrics.bosh-lite.com" } ``` -------------------------------- ### Deploy the database application Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/src/db/README.md Pushes the application to Cloud Foundry using the specified Java buildpack version. ```shell cf push autoscaler-db -p /db/target/db-1.0-SNAPSHOT.war -b https://github.com/cloudfoundry/java-buildpack.git#v3.7 ``` -------------------------------- ### Deploy and Scale MultiApps Controller Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Deploys the MultiApps Controller using its manifest and scales it up to handle large MTAR files. Adjust memory (m) and disk (k) as needed. ```bash # Deploy the application cf push deploy-service -f multiapps-controller-web-${MULTIAPPS_VERSION}-manifest.yml -p multiapps-controller-web-${MULTIAPPS_VERSION}.war # Scale up to handle large MTARs (>1GB) cf scale deploy-service -m 4G -k 2G -f ``` -------------------------------- ### Download MultiApps Controller Release Files Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Downloads the MultiApps Controller WAR file and manifest. Remember to set MULTIAPPS_VERSION to the latest available version. ```bash # Set the version (check for latest at https://repo.maven.apache.org/maven2/org/cloudfoundry/multiapps/multiapps-controller-web/) export MULTIAPPS_VERSION="1.174.0" # Download the WAR file wget "https://repo.maven.apache.org/maven2/org/cloudfoundry/multiapps/multiapps-controller-web/${MULTIAPPS_VERSION}/multiapps-controller-web-${MULTIAPPS_VERSION}.war" # Download the manifest wget "https://repo.maven.apache.org/maven2/org/cloudfoundry/multiapps/multiapps-controller-web/${MULTIAPPS_VERSION}/multiapps-controller-web-${MULTIAPPS_VERSION}-manifest.yml" ``` -------------------------------- ### Scale Down Internal Database Deployment Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Use an ops file to scale all non-database instances to zero when the database is part of the BOSH deployment. ```bash # Create an ops file to scale instances to 0 cat > scale-to-zero.yml < -o scale-to-zero.yml # Verify only postgres is running bosh -d app-autoscaler instances ``` -------------------------------- ### Create User-Provided Service for Database Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Creates a user-provided service in Cloud Foundry to connect the MultiApps Controller to its PostgreSQL database. Update the DB connection details accordingly. ```bash # Set your database connection details DB_USERNAME="multiapps_user" DB_PASSWORD="your-secure-password" DB_HOST="your-postgres-host" DB_PORT="5432" DB_NAME="multiapps_controller" # Create the user-provided service cf cups deploy-service-database -p "{ \"uri\": \"postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable\", \"username\": \"${DB_USERNAME}\", \"password\": \"${DB_PASSWORD}\" }" -t postgres ``` -------------------------------- ### Create PostgreSQL Database for MultiApps Controller Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Creates a new PostgreSQL database and user for the MultiApps Controller. Ensure you replace 'your-secure-password' with a strong password. ```sql -- Connect to your PostgreSQL instance CREATE DATABASE multiapps_controller WITH ENCODING='UTF8'; CREATE USER multiapps_user WITH PASSWORD 'your-secure-password'; GRANT ALL PRIVILEGES ON DATABASE multiapps_controller TO multiapps_user; ``` -------------------------------- ### Attach Autoscaling Policy using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Creates or updates an autoscaling policy for a specified application by providing the application name and the policy file name. ```bash cf aasp ``` -------------------------------- ### Download App Autoscaler MTAR Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Use these commands to set the desired version and download the corresponding MTAR file. ```bash # Check available releases at: https://github.com/cloudfoundry/app-autoscaler/releases # Set the version you want to use export AUTOSCALER_VERSION="v15.12.2" # Download the MTAR file wget "https://github.com/cloudfoundry/app-autoscaler/releases/download/${AUTOSCALER_VERSION}/app-autoscaler.mtar" ``` -------------------------------- ### Execute Terragrunt Infrastructure Commands Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/ci/terragrunt/app-autoscaler/concourse/README.md Run these commands to preview or apply infrastructure changes defined in the project. ```sh terragrunt plan terragrunt apply ``` -------------------------------- ### Format Java Code with Google Java Format Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Execute the provided `java` command to format Java code using `google-java-format`. This command includes necessary exports and specifies the target file for formatting. ```bash java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -jar /.cache/google-java-format-1.11.0-all-deps.jar \ -replace --skip-javadoc-formatting scheduler/src/main/java/org/cloudfoundry/autoscaler/scheduler/util/DataValidationHelper.java ``` -------------------------------- ### Create MTA Extension Descriptor Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Define custom configurations for the MTAR deployment using an .mtaext file. ```yaml _schema-version: "3.3.0" ID: production extends: com.github.cloudfoundry.app-autoscaler-release version: 1.0.0 modules: - name: apiserver parameters: instances: 2 routes: - route: autoscaler.${default-domain} - route: autoscalerservicebroker.${default-domain} - name: eventgenerator parameters: instances: 2 - name: scalingengine parameters: instances: 2 - name: metricsforwarder parameters: instances: 2 routes: - route: autoscalermetrics.${default-domain} - name: operator parameters: instances: 2 - name: scheduler parameters: instances: 2 resources: - name: database parameters: # PostgreSQL connection URI uri: "postgres://username:password@postgres-host:5432/autoscaler?sslmode=verify-full" # Optional: TLS certificates for secure database connection client_cert: | -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- client_key: | -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY----- server_ca: | -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- - name: broker-catalog parameters: services: - name: autoscaler id: autoscaler-guid plans: - name: autoscaler-free-plan id: autoscaler-free-plan-guid - name: autoscaler-standard id: autoscaler-standard-guid ``` -------------------------------- ### View Autoscaling Policy using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Retrieves and displays the current autoscaling policy configured for a given application. ```bash cf asp ``` -------------------------------- ### POST /v1/apps/:guid/metrics Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Submit custom metrics for a specific application instance to the Autoscaler metric server. ```APIDOC ## POST /v1/apps/:guid/metrics ### Description Submit custom metrics to the Autoscaler metric server for a specific application instance. ### Method POST ### Endpoint /v1/apps/:guid/metrics ### Parameters #### Path Parameters - **guid** (string) - Required - The unique identifier of the application. #### Request Body - **instance_index** (number) - Required - The index of the current application instance (fetch from CF_INSTANCE_INDEX). - **metrics** (array) - Required - List of metrics to submit. - **name** (string) - Required - The name of the metric (must match policy definition). - **value** (number) - Required - The numeric value of the metric. - **unit** (string) - Optional - The unit of the metric. ### Request Example { "instance_index": 0, "metrics": [{ "name": "custom_metric", "value": 100, "unit": "count" }] } ### Response #### Success Response (200) - **Status** (200 OK) - Metric successfully submitted. #### Error Response - **error** (string) - A descriptive error message. ``` -------------------------------- ### Update App Autoscaler Release Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Download a new release version and perform a blue-green deployment using the Cloud Foundry CLI. ```bash # Download new release (check https://github.com/cloudfoundry/app-autoscaler/releases for available versions) export AUTOSCALER_VERSION="vNEW_VERSION" export MTAR_FILE="app-autoscaler-release-${AUTOSCALER_VERSION}.mtar" wget "https://github.com/cloudfoundry/app-autoscaler/releases/download/${AUTOSCALER_VERSION}/${MTAR_FILE}" # Deploy update (blue-green deployment recommended) cf deploy --strategy blue-green $MTAR_FILE -e autoscaler-custom.mtaext ``` -------------------------------- ### Verify MultiApps Controller Deployment Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Checks if the MultiApps Controller application is running and tests its accessibility. This confirms the controller is ready for MTAR deployments. ```bash # Check the application is running cf apps | grep deploy-service # Test the MultiApps Controller endpoint cf mtas ``` -------------------------------- ### Configure Acceptance Tests Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Set the API endpoint and domain for the autoscaler acceptance tests via environment variables. ```bash cf set-env autoscaler-acceptance-tests API_ENDPOINT https://autoscaler.your-domain.com cf set-env autoscaler-acceptance-tests CF_DOMAIN your-domain.com cf restage autoscaler-acceptance-tests ``` -------------------------------- ### Bind Service with Policy File using CF CLI Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Readme.md Binds an App AutoScaler service instance to an application, optionally attaching a scaling policy file during the binding process. ```bash cf bind-service -c ``` -------------------------------- ### Run MTAR Acceptance Tests Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Execute acceptance tests packaged as Cloud Foundry tasks. ```bash # List available tasks cf apps | grep autoscaler-test # Run acceptance tests cf run-task autoscaler-acceptance-tests "api" --name acceptance-test-api cf run-task autoscaler-acceptance-tests "broker" --name acceptance-test-broker cf run-task autoscaler-acceptance-tests "app" --name acceptance-test-app # View test results cf logs autoscaler-acceptance-tests --recent ``` -------------------------------- ### Configure Security Group for PostgreSQL Access Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Creates and binds a security group to allow the MultiApps Controller to connect to a PostgreSQL instance on a private network. Replace placeholders with your specific IP and organization/space details. ```bash # Create security group JSON file cat > multiapps-postgres-sg.json < --space ``` -------------------------------- ### PUT /v1/apps/:guid/policy Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Creates or updates the scaling policy for a given application. Requires a JSON body defining the policy. ```APIDOC ## PUT /v1/apps/:guid/policy ### Description Creates or updates the scaling policy for a given application. Requires a JSON body defining the policy. ### Method PUT ### Endpoint /v1/apps/:guid/policy ### Parameters #### Path Parameters - **guid** (string) - Required - The GUID of the application. #### Request Body - **instance_min_count** (integer) - Required - The minimum number of instances for the application. - **instance_max_count** (integer) - Required - The maximum number of instances for the application. - **scaling_rules** (array) - Required - A list of rules that define when to scale the application. - **metric_type** (string) - Required - The type of metric to monitor (e.g., "memoryused", "diskused", "cpu"). - **breach_duration_secs** (integer) - Required - The duration in seconds the metric must breach the threshold to trigger scaling. - **threshold** (number) - Required - The threshold value for the metric. - **operator** (string) - Required - The comparison operator for the threshold (e.g., "<", ">="). - **cool_down_secs** (integer) - Required - The cooldown period in seconds after a scaling event. - **adjustment** (string) - Required - The amount to adjust the instance count by (e.g., "-1", "+1"). - **schedules** (object) - Optional - Defines scheduled scaling events. - **timezone** (string) - Required - The timezone for the schedules (e.g., "Asia/Shanghai"). - **recurring_schedule** (array) - Optional - A list of recurring schedules. - **start_time** (string) - Required - The start time for the recurring schedule (HH:MM format). - **end_time** (string) - Required - The end time for the recurring schedule (HH:MM format). - **days_of_week** (array) - Optional - An array of integers representing days of the week (1-7, Sunday=1). - **days_of_month** (array) - Optional - An array of integers representing days of the month. - **instance_min_count** (integer) - Optional - The minimum instance count for this schedule. - **instance_max_count** (integer) - Optional - The maximum instance count for this schedule. - **initial_min_instance_count** (integer) - Optional - The initial minimum instance count when the schedule becomes active. - **specific_date_schedule** (array) - Optional - A list of specific date schedules. - **start_date** (string) - Required - The start date for the specific schedule (YYYY-MM-DD format). - **end_date** (string) - Required - The end date for the specific schedule (YYYY-MM-DD format). - **start_time** (string) - Required - The start time for the specific schedule (HH:MM format). - **end_time** (string) - Required - The end time for the specific schedule (HH:MM format). - **instance_min_count** (integer) - Optional - The minimum instance count for this schedule. - **instance_max_count** (integer) - Optional - The maximum instance count for this schedule. - **initial_min_instance_count** (integer) - Optional - The initial minimum instance count when the schedule becomes active. ### Request Example ```json { "instance_min_count": 1, "instance_max_count": 4, "scaling_rules": [ { "metric_type": "memoryused", "breach_duration_secs": 600, "threshold": 30, "operator": "<", "cool_down_secs": 300, "adjustment": "-1" }, { "metric_type": "memoryused", "breach_duration_secs": 600, "threshold": 90, "operator": ">=", "cool_down_secs": 300, "adjustment": "+1" } ], "schedules": { "timezone": "Asia/Shanghai", "recurring_schedule": [ { "start_time": "10:00", "end_time": "18:00", "days_of_week": [ 1, 2, 3 ], "instance_min_count": 1, "instance_max_count": 10, "initial_min_instance_count": 5 } ], "specific_date_schedule": [ { "start_date": "2016-06-27", "end_date": "2016-07-23", "start_time": "11:00", "end_time": "19:30", "instance_min_count": 1, "instance_max_count": 10, "initial_min_instance_count": 5 } ] } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Progressive BOSH VM Shutdown Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Commands to stop specific BOSH VM components in the recommended order to ensure service continuity. ```bash bosh -d app-autoscaler stop operator # Verify autoscaler is still working as expected ``` ```bash bosh -d app-autoscaler stop eventgenerator # Verify metrics collection is working on mtar MTAR deployment app ``` ```bash bosh -d app-autoscaler stop scalingengine # Verify scaling events are executed by MTAR deployment app ``` ```bash bosh -d app-autoscaler stop metricsforwarder # Verify custom metrics are still being collected by MTAR deployment app ``` ```bash bosh -d app-autoscaler stop scheduler # Verify scheduled scaling is working ``` ```bash bosh -d app-autoscaler stop apiserver # Verify API is still accessible curl https://autoscaler./health ``` -------------------------------- ### Fix Go Code Formatting Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Use `gofmt` with the `-s` and `-w` flags to automatically format Go code and apply the changes. This is necessary when `golangci-lint` reports formatting issues. ```bash gofmt -s -w api/brokerserver/broker_handler.go ``` -------------------------------- ### Verify BOSH Deployment Status Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Check the status of BOSH instances to ensure all are stopped before decommissioning. ```bash # Check all VMs are stopped bosh -d app-autoscaler instances # Should show all instances in 'stopped' state ``` -------------------------------- ### Basic Git Commit Usage Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Standard Git commands for staging files and committing changes with a message. This is a fundamental workflow for version control. ```bash git add git commit -m ``` -------------------------------- ### Commit Changes with Pre-Commit Hooks Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/style-guide/README.md Standard Git commit command to stage and commit changes. Pre-commit hooks will run automatically to check code quality. ```bash $ git commit -m "aas82 fix GHA linter: Golang and Java - local" ``` -------------------------------- ### Verify MTAR Route Configuration Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/cf-migration.md Check that the MTAR routes are correctly mapped to the autoscaler service. ```bash # Verify MTAR routes are mapped cf routes | grep autoscaler # BOSH and MTAR should use the same route hostnames # The MTAR extension file should specify the same routes used by BOSH: # - autoscaler. (API) # - autoscalerservicebroker. (Service Broker) # - autoscalermetrics. (Metrics) ``` -------------------------------- ### Create Credential Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Creates a new credential for an application to authorize access to the App Autoscaler metric server. A credential with random username/password will be generated by default. It is also supported to define a credential with a specific pair of username and password. ```APIDOC ## PUT /v1/apps/:guid/credential ### Description Optional. A credential with random username/password will be generated by this API by default. Also it is supported to define credential with a specific pair of username and password with below JSON payload. ### Method PUT ### Endpoint /v1/apps/:guid/credential ### Request Body - **username** (string) - Optional - The desired username for the credential. - **password** (string) - Optional - The desired password for the credential. ### Request Example ```json { "username": "username", "password": "password" } ``` ### Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200 OK) - **app_id** (string) - The ID of the application. - **username** (string) - The generated or specified username. - **password** (string) - The generated or specified password. - **url** (string) - The URL of the App Autoscaler metric server. #### Response Example ```json { "app_id": "", "username": "MY_USERNAME", "password": "MY_PASSWORD", "url": "" } ``` ``` -------------------------------- ### Scaling Rules Schema Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/policy.md Defines the structure for dynamic scaling rules within the App AutoScaler policy. ```APIDOC ### Scaling Rules | Name | Type | Required | Description | |---|---|---|---| | metric_type | String | true | one of system-default metric types `memoryused`, `memoryutil`, `responsetime`, `throughput`, `cpu` or user-defined custom metric type | | threshold | int | true | the boundary when metric value exceeds is considered as a breach | | operator | String | true | >, <, >=, <= | | adjustment | String | true | the adjustment approach for instance count with each scaling. Support regex format `^[-+][1-9]+[0-9]*[%]?$`, i.e. +5 means adding 5 instances, -50% means shrinking to the half of current size. | | breach_duration_secs | int, seconds | false | time duration to fire scaling event if it keeps breaching | | cool_down_secs | int,seconds | false | the time duration to wait before the next scaling kicks in | ``` -------------------------------- ### Run Rspec Test for Scaling Engine Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/spec/jobs/README.md Execute Rspec tests for the scalingengine job component. This command is used to identify and debug issues within the test cases. ```bash bundle exec rspec spec/jobs/scalingengine/scalingengine_spec.rb ``` -------------------------------- ### App AutoScaler Policy Schema Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/policy.md The main structure of the App AutoScaler policy JSON. ```APIDOC ## Policy | Name | Type | Required | Description | |---|---|---|---| | instance_min_count | int | true | minimal number of instance count | | instance_max_count | int | true | maximal number of instance count | | scaling_rules | JSON Array | `AnyOf` | dynamic scaling rules, see `Scaling Rules ` below | | schedules | JSON Array | `AnyOf` | scheduled, see `Schedules` below | ``` -------------------------------- ### Create or Update Scaling Policy Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst This JSON object defines the scaling policy for an application. It includes minimum and maximum instance counts, scaling rules based on metric thresholds, and optional scheduled scaling periods. ```json { "instance_min_count": 1, "instance_max_count": 4, "scaling_rules": [ { "metric_type": "memoryused", "breach_duration_secs": 600, "threshold": 30, "operator": "<", "cool_down_secs": 300, "adjustment": "-1" }, { "metric_type": "memoryused", "breach_duration_secs": 600, "threshold": 90, "operator": ">=", "cool_down_secs": 300, "adjustment": "+1" } ], "schedules": { "timezone": "Asia/Shanghai", "recurring_schedule": [ { "start_time": "10:00", "end_time": "18:00", "days_of_week": [ 1, 2, 3 ], "instance_min_count": 1, "instance_max_count": 10, "initial_min_instance_count": 5 }, { "start_date": "2016-06-27", "end_date": "2016-07-23", "start_time": "11:00", "end_time": "19:30", "days_of_month": [ ``` -------------------------------- ### Create Credential for Custom Metrics Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/Public_API.rst Use this API to generate a username and password for your application to authenticate with the App Autoscaler metric server. You can optionally provide your own username and password. ```json { "username": "username", "password": "password" } ``` -------------------------------- ### Schedules Schema Source: https://github.com/cloudfoundry/app-autoscaler-release/blob/main/docs/policy.md Defines the structure for scheduled scaling events within the App AutoScaler policy. ```APIDOC ### Schedules | Name | Type | Required | Description | |---|---|---|---| | timezone | String | true | Using [timezone definition of Java][a] | | recurring_schedule | JSON Array | `AnyOf` | the schedules which will take effect repeatly, see `Recurring Schedule` below | | specific_date | JSON Array | `AnyOf` | the schedules which take effect only once, see `Specific Date` below | ```