RegionalAutoscaler

A regional autoscaler for a regional managed instance group.

Like all Resources, this class configures itself across multiple Environments.

For more information see the official documentation.

Example Usage

Basic Usage

This will scale based on CPU utilization of .6.

1
import launchflow as lf
2
3
instance_group = lf.gcp.RegionalManagedInstanceGroup("instance-group")
4
autoscaler = lf.gcp.RegionalAutoscaler("autoscaler", group_mananger=instance_group)

Autoscaling based on a specific CPU Utilization

1
import launchflow as lf
2
3
instance_group = lf.gcp.RegionalManagedInstanceGroup("instance-group")
4
autoscaler = lf.gcp.RegionalAutoscaler(
5
"autoscaler",
6
group_mananger=instance_group,
7
autoscaling_policies=[
8
lf.gcp.regional_autoscaler.AutoscalingPolicy(
9
min_replicas=1,
10
max_replicas=10,
11
cpu_utilization=lf.gcp.regional_autoscaler.CPUUtilization(target=0.8)
12
)
13
]
14
)

Autoscaling based on a custom metric

1
import launchflow as lf
2
3
instance_group = lf.gcp.RegionalManagedInstanceGroup("instance-group")
4
autoscaler = lf.gcp.RegionalAutoscaler(
5
"autoscaler",
6
group_mananger=instance_group,
7
autoscaling_policies=[
8
lf.gcp.regional_autoscaler.AutoscalingPolicy(
9
min_replicas=1,
10
max_replicas=10,
11
custom_metric=lf.gcp.regional_autoscaler.CustomMetric(name="my-custom-metric", target=100)
12
)
13
]
14
)

initialization

Create a new regional autoscaler.

Args:

CPUUtilization

Configuration for autoscaling based on CPU utilization. Args:

  • target (float): The target CPU utilization that the autoscaler should aim for. Must be between 0 and 1. Defaults to 0.6.
  • predictive_method (Literal["NONE", "OPTIMIZE_AVAILABILITY"]): The predictive method to use for the autoscaler. Defaults to "NONE".

CustomMetric

Configuration for autoscaling based on a custom metric.

Args:

  • name (str): The name of the custom metric.
  • target (Optional[float]): The target value for the custom metric that the autoscaler should aim for.
  • type (Optional[Literal["GAUGE", "DELTA_PER_SECOND", "DELTA_PER_MINUTE"]]): How the target utilization value should be interpreted for a Google Cloud Monitoring metric.

LoadBalancingUtilization

Configuration for autoscaling based on load balancer.

Args:

  • target (float): The percent of backend utilization the autoscaler should aim for. Must be between 0 and 1. Defaults to 0.8.

AutoscalingPolicy

The autoscaling policy for a regional autoscaler.

Args:

  • min_replicas (int): The minimum number of instances that the group manager will maintain.
  • max_replicas (int): The maximum number of instances that the group manager will maintain.
  • cooldown_period (int): The number of seconds that the autoscaler should wait before it starts collecting information from a new instance.
  • cpu_utilization (Optional[CPUUtilization]): If set the autoscaler will scale based on CPU utilization. This is the default if none of the other options are set.
  • custom_metric (Optional[CustomMetric]): If set the autoscaler will scale based on a custom metric you provide (i.e. a pub/sub backlog).
  • load_balancing_utilization (Optional[LoadBalancingUtilization]): If set the autoscaler will scale based on the load balancing utilization.