Updated on 2024-05-25 GMT+08:00

Configuring a Metric AS Policy

This section describes how to configure a metric AS policy. Currently, instances can be automatically added or deleted based on CPU, memory thresholds, and custom metrics. This frees you from repeatedly adjusting resources to keep up with service changes and peak pressures, helping you reduce resources and labor costs.

CAE instance scaling is calculated by current and expected metrics.

Expected instances = ceil [Current instances * (Current metrics/Expected metrics)] (ceil is rounded up.)

There is an error tolerance of 10% to prevent frequent fluctuation of instance quantity, so there is no scaling when Current metrics/Expected metric ranges from 0.9 to 1.1.

Application Scenario

This policy is useful for burst traffic and typical periodic traffic, mainly in industries such as the Internet, games, and social platforms.

Procedure

  1. Log in to CAE.
  2. Choose Component Configurations.
  3. Select the target component from the drop-down list in the upper part of the page.

    Figure 1 Selecting a component

  4. Click Edit in the AS Policies module.
  5. Select Metric and configure the policy by referring to Table 1.

    Table 1 Configuring a metric policy

    Parameter

    Description

    Max. Instances

    Max. number of instances that can be reached during scale-out.

    Value range: 1 to 99.

    NOTE:

    Max. Instances must be greater than Min Instances.

    Min Instances

    Min number of instances that can be reached during scale-in.

    Value range: 1 to 99.

    Metric

    • CPU usage, a preset metric in the system
    • Memory usage, a preset metric in the system
    • Custom metrics. Click Add Expected Value and select a custom metric from the drop-down list to add a custom metric. For details about how to create a custom metric, see Configuring Custom Metrics.
      You can add multiple custom metrics.
      NOTE:
      • You must enter a PromQL statement. PromQL is a built-in data query language from Prometheus, and is used to select, aggregate, and perform logical calculation on time series data. For details, see Prometheus.
      • The query result of the PromQL statement must be a single value of the vector or scalar type.
      • Upgrade the component created/upgraded before November 3, 2023 for the custom scaling policy to take effect.

    You can scale instances based on the CPU and memory thresholds.

    For example, set the maximum expected CPU usage to 80 and memory usage to 70. When the CPU usage of a component is greater than 80% or the memory usage is greater than 70%, the system automatically increases the number of component instances. When the CPU usage of a component is less than 80% and the memory usage is less than 70%, the system automatically reduces the number of component instances.

    Figure 2 Configuring a metric policy

    You can scale instances based on the custom metrics.

    For example, select click_ operated_total from the drop-down list, enter the PromeQL statement max(avg_over_time(click_operated_total{environment_name="env-test",application_name="test",component_name="demo-backend-1676360408"}[1m])), and set the expected value to 10.

    • The PromeQL statement indicates the maximum average value of click_ operated_total per minute of all the demo-backend-1676360408 component instances.
    • If the value of the PromeQL statement is greater than the expected value, the system automatically increases the number of component instances.
    • If the value of the PromeQL statement is less than the expected value, the system automatically reduces the number of component instances.
      Figure 3 Configuring a custom metric policy

  6. (Optional) Expand Advanced Settings and configure advanced settings by referring to Table 2.

    Table 2 Configuring advanced settings

    Parameter

    Description

    Scale-out Step

    Number of pods to be added per minute.

    Value range: 1 to 99. Default value: 4.

    Stable Scale-out Window (s)

    Value range: 1 to 3600, in seconds. Default value: 0.

    Scale-in Step

    Number of pods to be reduced per minute.

    Value range: 1 to 99. Default value: 99.

    Stable Scale-in Window (s)

    Value range: 1 to 3600, in seconds. Default value: 300.

    Disable Scale-in

    Click to disable scale-in.

    Figure 4 Advanced settings

  7. Click OK.
  8. Click Activate Settings in the upper part of the page. In the dialog box displayed on the right, confirm the configurations and click OK for the configurations to take effect.