(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None)
Do a single check to scale the fleet up or down if necessary.

        :param dry_run: boolean; if True, don't modify the pool size, just print what would happen
        :param timestamp: an arrow object indicating the current time
Do a single check to scale the fleet up or down if necessary.
Do a single check to scale the fleet up or down if necessary .
def run(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None) -> None:
        """ Do a single check to scale the fleet up or down if necessary.

        :param dry_run: boolean; if True, don't modify the pool size, just print what would happen
        :param timestamp: an arrow object indicating the current time
        """

        timestamp = timestamp or arrow.utcnow()
        logger.info(f"Autoscaling run starting at {timestamp}")
        if autoscaling_is_paused(self.cluster, self.pool, self.scheduler, timestamp):
            logger.info("Autoscaling is currently paused; doing nothing")
            return

        self.pool_manager.reload_state()
        try:
            signal_name = self.signal.name
            resource_request = self.signal.evaluate(timestamp)
            exception = None
        except Exception as e:
            logger.error(f"Client signal {self.signal.name} failed; using default signal")
            signal_name = self.default_signal.name
            resource_request = self.default_signal.evaluate(timestamp)
            exception, tb = e, traceback.format_exc()

        logger.info(f"Signal {signal_name} requested {resource_request}")

        no_scale_down = False
        if self.autoscaling_config.prevent_scale_down_after_capacity_loss:
            num_removed_nodes_before_last_reload = self.pool_manager.get_num_removed_nodes_before_last_reload()
            # TODO (CLUSTERMAN-576): support instance weights here, instead of just instance count
            if num_removed_nodes_before_last_reload > self.autoscaling_config.instance_loss_threshold:
                logger.warning(
                    "Nodes lost since last autoscaler run is {}"
                    " which is greater than the threshold ({}),".format(
                        str(num_removed_nodes_before_last_reload), str(self.autoscaling_config.instance_loss_threshold),
                    )
                )
                logger.warning("Autoscaler will not kill any nodes on this run.")
                no_scale_down = True

        if isinstance(resource_request, list):
            pass
        else:
            new_target_capacity = self._compute_target_capacity(resource_request)
            self.target_capacity_gauge.set(new_target_capacity, {"dry_run": dry_run})
            self._emit_requested_resource_metrics(resource_request, dry_run=dry_run)

        self.pool_manager.modify_target_capacity(new_target_capacity, dry_run=dry_run, no_scale_down=no_scale_down)

        if exception:
            logger.error(f"The client signal failed with:\n{tb}")
            raise exception
def run ( self , dry_run : bool = False , timestamp : Optional [ arrow . Arrow ] = None ) -> None : timestamp = timestamp or arrow . utcnow ( ) logger . info ( f"Autoscaling run starting at {timestamp}" ) if autoscaling_is_paused ( self . cluster , self . pool , self . scheduler , timestamp ) : logger . info ( "Autoscaling is currently paused; doing nothing" ) return self . pool_manager . reload_state ( ) try : signal_name = self . signal . name resource_request = self . signal . evaluate ( timestamp ) exception = None except Exception as e : logger . error ( f"Client signal {self.signal.name} failed; using default signal" ) signal_name = self . default_signal . name resource_request = self . default_signal . evaluate ( timestamp ) exception , tb = e , traceback . format_exc ( ) logger . info ( f"Signal {signal_name} requested {resource_request}" ) no_scale_down = False if self . autoscaling_config . prevent_scale_down_after_capacity_loss : num_removed_nodes_before_last_reload = self . pool_manager . get_num_removed_nodes_before_last_reload ( ) # TODO (CLUSTERMAN-576): support instance weights here, instead of just instance count if num_removed_nodes_before_last_reload > self . autoscaling_config . instance_loss_threshold : logger . warning ( "Nodes lost since last autoscaler run is {}" " which is greater than the threshold ({})," . format ( str ( num_removed_nodes_before_last_reload ) , str ( self . autoscaling_config . instance_loss_threshold ) , ) ) logger . warning ( "Autoscaler will not kill any nodes on this run." ) no_scale_down = True if isinstance ( resource_request , list ) : pass else : new_target_capacity = self . _compute_target_capacity ( resource_request ) self . target_capacity_gauge . set ( new_target_capacity , { "dry_run" : dry_run } ) self . _emit_requested_resource_metrics ( resource_request , dry_run = dry_run ) self . pool_manager . modify_target_capacity ( new_target_capacity , dry_run = dry_run , no_scale_down = no_scale_down ) if exception : logger . error ( f"The client signal failed with:\n{tb}" ) raise exception