def __ensure_provisioning_reads(table_name): """ Ensure that provisioning is correct :type table_name: str :param table_name: Name of the DynamoDB table :returns: (bool, int) -- update_needed, updated_read_units """ update_needed = False updated_read_units = statistics.get_provisioned_read_units(table_name) consumed_read_units_percent = \ statistics.get_consumed_read_units_percent(table_name) if (consumed_read_units_percent == 0 and not get_table_option(table_name, 'allow_scaling_down_reads_on_0_percent')): logger.info( '{0} - Scaling down reads is not done when usage is at 0%'.format( table_name)) elif (consumed_read_units_percent >= get_table_option(table_name, 'reads_upper_threshold')): if get_table_option(table_name, 'increase_reads_unit') == 'percent': updated_provisioning = calculators.increase_reads_in_percent( table_name, updated_read_units, get_table_option(table_name, 'increase_reads_with')) else: updated_provisioning = calculators.increase_reads_in_units( table_name, updated_read_units, get_table_option(table_name, 'increase_reads_with')) update_needed = True updated_read_units = updated_provisioning elif (consumed_read_units_percent <= get_table_option(table_name, 'reads_lower_threshold')): if get_table_option(table_name, 'decrease_reads_unit') == 'percent': updated_provisioning = calculators.decrease_reads_in_percent( table_name, updated_read_units, get_table_option(table_name, 'decrease_reads_with')) else: updated_provisioning = calculators.decrease_reads_in_units( table_name, updated_read_units, get_table_option(table_name, 'decrease_reads_with')) update_needed = True updated_read_units = updated_provisioning return update_needed, int(updated_read_units)
def test_increase_reads_in_units_hit_max_units(self): """ Check that max values are honoured """ result = calculators.increase_reads_in_units(20, 50, 25, 'test') self.assertEqual(result, 25)
def test_increase_reads_in_units(self): """ Ensure that a regular increase works """ result = calculators.increase_reads_in_units(200, 90, 300, 'test') self.assertEqual(result, 290)
def test_increase_reads_in_units_hit_max_units(self): """ Check that max values are honoured """ result = calculators.increase_reads_in_units(20, 50, 25, 2, 'test') self.assertEqual(result, 25)
def test_increase_reads_in_units(self): """ Ensure that a regular increase works """ result = calculators.increase_reads_in_units(200, 90, 300, 2, 'test') self.assertEqual(result, 290)
def __ensure_provisioning_reads(table_name, key_name): """ Ensure that provisioning is correct :type table_name: str :param table_name: Name of the DynamoDB table :type key_name: str :param key_name: Configuration option key name :returns: (bool, int) -- update_needed, updated_read_units """ update_needed = False updated_read_units = statistics.get_provisioned_read_units(table_name) consumed_read_units_percent = \ statistics.get_consumed_read_units_percent(table_name) if (consumed_read_units_percent == 0 and not get_table_option(key_name, 'allow_scaling_down_reads_on_0_percent')): logger.info( '{0} - Scaling down reads is not done when usage is at 0%'.format( table_name)) elif (consumed_read_units_percent >= get_table_option(key_name, 'reads_upper_threshold')): if get_table_option(key_name, 'increase_reads_unit') == 'percent': updated_provisioning = calculators.increase_reads_in_percent( table_name, updated_read_units, get_table_option(key_name, 'increase_reads_with'), key_name) else: updated_provisioning = calculators.increase_reads_in_units( table_name, updated_read_units, get_table_option(key_name, 'increase_reads_with'), key_name) update_needed = True updated_read_units = updated_provisioning elif (consumed_read_units_percent <= get_table_option(key_name, 'reads_lower_threshold')): if get_table_option(key_name, 'decrease_reads_unit') == 'percent': updated_provisioning = calculators.decrease_reads_in_percent( table_name, updated_read_units, get_table_option(key_name, 'decrease_reads_with'), key_name) else: updated_provisioning = calculators.decrease_reads_in_units( table_name, updated_read_units, get_table_option(key_name, 'decrease_reads_with'), key_name) update_needed = True updated_read_units = updated_provisioning return update_needed, int(updated_read_units)